@@ -17,38 +17,46 @@ const CANISTER_ID = 'b7hhy-tyaaa-aaaah-abbja-cai';
17
17
18
18
const DEFAULT_AGENT = new HttpAgent ( { fetch, host : IC_HOST } ) ;
19
19
20
- export const TOKEN_STANDARDS = Object . values ( TOKEN )
20
+ export const TOKEN_STANDARDS = Object . values ( TOKEN ) ;
21
21
22
22
interface GetTokenActorParams {
23
- canisterId : string ,
24
- standard : string ,
25
- agent : HttpAgent
23
+ canisterId : string ;
24
+ standard : string ;
25
+ agent : HttpAgent ;
26
26
}
27
27
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 ) ) {
34
34
console . error ( `Standard ${ standard } is not implemented` ) ;
35
35
throw new Error ( `standard is not supported: ${ standard } ` ) ;
36
36
}
37
- return createTokenActor < T > ( canisterId , agent , standard )
37
+ return createTokenActor < T > ( canisterId , agent , standard ) ;
38
38
} ;
39
39
40
40
export class TokenRegistry extends Registry {
41
41
constructor ( agent ?: HttpAgent ) {
42
42
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
+ } ) ;
44
48
}
45
49
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 ( ) ;
47
53
return tokenCanistersMetadata . map ( formatMetadata ) ;
48
- }
54
+ } ;
49
55
}
50
56
51
- export const getTokens = async ( agent = DEFAULT_AGENT ) : Promise < Token [ ] > => {
57
+ export const getTokens = async ( { agent = DEFAULT_AGENT } = { } ) : Promise <
58
+ Token [ ]
59
+ > => {
52
60
const tokenRegistry = new TokenRegistry ( agent ) ;
53
61
const tokenCanisters = await tokenRegistry . getAll ( ) ;
54
62
return tokenCanisters . map ( ( token ) => ( {
@@ -59,15 +67,17 @@ export const getTokens = async (agent = DEFAULT_AGENT): Promise<Token[]> => {
59
67
website : token . frontend . length ? token . frontend [ 0 ] : '' ,
60
68
principal_id : token . principal_id ,
61
69
standard : token . details . standard as string ,
62
- total_supply : [ token . details . total_supply as bigint ] ,
70
+ total_supply : [ token . details . total_supply as bigint ] ,
63
71
symbol : token . details . symbol as string ,
64
72
} ) ) ;
65
73
} ;
66
74
67
75
export default {
68
76
getTokenActor,
69
77
getTokens,
70
- addToken : async ( { agent, tokenInfo } ) => new TokenRegistry ( agent ) . add ( tokenInfo ) ,
78
+ addToken : async ( { agent, tokenInfo } ) =>
79
+ new TokenRegistry ( agent ) . add ( tokenInfo ) ,
71
80
// 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 ) ,
73
83
} ;
0 commit comments