Skip to content

Commit d4e5758

Browse files
authored
Merge pull request #61 from Psychedelic/fix/getTokens-params
fix: getTokens receive an objet
2 parents a38b3cc + e52370c commit d4e5758

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@psychedelic/dab-js",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "JS adapter for DAB",
55
"main": "dist/index.js",
66
"repository": {

src/registries/token_registry.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,46 @@ const CANISTER_ID = 'b7hhy-tyaaa-aaaah-abbja-cai';
1717

1818
const DEFAULT_AGENT = new HttpAgent({ fetch, host: IC_HOST });
1919

20-
export const TOKEN_STANDARDS = Object.values(TOKEN)
20+
export const TOKEN_STANDARDS = Object.values(TOKEN);
2121

2222
interface GetTokenActorParams {
23-
canisterId: string,
24-
standard: string,
25-
agent: HttpAgent
23+
canisterId: string;
24+
standard: string;
25+
agent: HttpAgent;
2626
}
2727

28-
export const getTokenActor = <T = {}>(
29-
{ canisterId,
30-
agent,
31-
standard }: GetTokenActorParams
32-
) => {
33-
if (!(TOKEN_STANDARDS.includes(standard))) {
28+
export const getTokenActor = <T = {}>({
29+
canisterId,
30+
agent,
31+
standard,
32+
}: GetTokenActorParams) => {
33+
if (!TOKEN_STANDARDS.includes(standard)) {
3434
console.error(`Standard ${standard} is not implemented`);
3535
throw new Error(`standard is not supported: ${standard}`);
3636
}
37-
return createTokenActor<T>(canisterId, agent, standard)
37+
return createTokenActor<T>(canisterId, agent, standard);
3838
};
3939

4040
export class TokenRegistry extends Registry {
4141
constructor(agent?: HttpAgent) {
4242
super(CANISTER_ID, agent);
43-
this.actor = generateActor({ agent: agent || DEFAULT_AGENT, canisterId: CANISTER_ID, IDL });
43+
this.actor = generateActor({
44+
agent: agent || DEFAULT_AGENT,
45+
canisterId: CANISTER_ID,
46+
IDL,
47+
});
4448
}
4549
public getAll = async (): Promise<FormattedMetadata[]> => {
46-
const tokenCanistersMetadata = await (this.actor as ActorSubclass<TokenRegistryInterface>).get_all();
50+
const tokenCanistersMetadata = await (
51+
this.actor as ActorSubclass<TokenRegistryInterface>
52+
).get_all();
4753
return tokenCanistersMetadata.map(formatMetadata);
48-
}
54+
};
4955
}
5056

51-
export const getTokens = async (agent = DEFAULT_AGENT): Promise<Token[]> => {
57+
export const getTokens = async ({ agent = DEFAULT_AGENT } = {}): Promise<
58+
Token[]
59+
> => {
5260
const tokenRegistry = new TokenRegistry(agent);
5361
const tokenCanisters = await tokenRegistry.getAll();
5462
return tokenCanisters.map((token) => ({
@@ -59,15 +67,17 @@ export const getTokens = async (agent = DEFAULT_AGENT): Promise<Token[]> => {
5967
website: token.frontend.length ? token.frontend[0] : '',
6068
principal_id: token.principal_id,
6169
standard: token.details.standard as string,
62-
total_supply : [token.details.total_supply as bigint],
70+
total_supply: [token.details.total_supply as bigint],
6371
symbol: token.details.symbol as string,
6472
}));
6573
};
6674

6775
export default {
6876
getTokenActor,
6977
getTokens,
70-
addToken: async ({ agent, tokenInfo }) => new TokenRegistry(agent).add(tokenInfo),
78+
addToken: async ({ agent, tokenInfo }) =>
79+
new TokenRegistry(agent).add(tokenInfo),
7180
// editToken: async ({ agent, tokenInfo }) => new TokenRegistry(agent).edit(tokenInfo),
72-
removeToken: async ({ agent, canisterId }) => new TokenRegistry(agent).remove(canisterId),
81+
removeToken: async ({ agent, canisterId }) =>
82+
new TokenRegistry(agent).remove(canisterId),
7383
};

0 commit comments

Comments
 (0)