-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicp-index.ts
35 lines (29 loc) · 1.08 KB
/
icp-index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {IDL} from '@dfinity/candid';
import {Principal} from '@dfinity/principal';
import {assertNonNullish} from '@dfinity/utils';
import {init} from '../declarations/icp_index.idl';
import {Module} from '../services/modules.services';
import type {ModuleDescription, ModuleInstallParams} from '../types/module';
const ICP_INDEX: ModuleDescription = {
key: 'icp_index',
name: 'ICP Index',
canisterId: 'qhbym-qaaaa-aaaaa-aaafq-cai'
};
class IcpIndexModule extends Module {
override async install({state, ...rest}: ModuleInstallParams): Promise<void> {
const canisterId = state.getModule('icp_ledger')?.canisterId;
assertNonNullish(
canisterId,
'Cannot configure ICP index because the ICP ledger id is unknown.'
);
// Type definitions generated by Candid are not clean enough.
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
const arg = IDL.encode(init({IDL}), [{ledger_id: Principal.fromText(canisterId)}]);
await super.install({
state,
arg,
...rest
});
}
}
export const icpIndex = new IcpIndexModule(ICP_INDEX);