diff --git a/frontend/src/lib/api/canisters.api.ts b/frontend/src/lib/api/canisters.api.ts index 4019c28e20e..461130ec62a 100644 --- a/frontend/src/lib/api/canisters.api.ts +++ b/frontend/src/lib/api/canisters.api.ts @@ -11,6 +11,8 @@ import { } from "$lib/canisters/nns-dapp/nns-dapp.errors"; import type { CanisterDetails as CanisterInfo, + ImportedToken, + ImportedTokens, SubAccountArray, } from "$lib/canisters/nns-dapp/nns-dapp.types"; import { @@ -376,3 +378,33 @@ const canisters = async ( return { cmc, icMgt, nnsDapp }; }; + +export const getImportedTokens = async ({ + identity, +}: { + identity: Identity; +}): Promise => { + logWithTimestamp("Getting imported tokens call..."); + const { nnsDapp } = await canisters(identity); + + const importedTokens = await nnsDapp.getImportedTokens(); + + logWithTimestamp("Getting imported tokens call complete."); + + return importedTokens; +}; + +export const setImportedTokens = async ({ + identity, + importedTokens, +}: { + identity: Identity; + importedTokens: Array; +}): Promise => { + logWithTimestamp("Setting imported tokens call..."); + const { nnsDapp } = await canisters(identity); + + await nnsDapp.setImportedTokens(importedTokens); + + logWithTimestamp("Setting imported tokens call complete."); +}; diff --git a/frontend/src/lib/canisters/nns-dapp/nns-dapp.canister.ts b/frontend/src/lib/canisters/nns-dapp/nns-dapp.canister.ts index 1efe86dd3c3..019539d800f 100644 --- a/frontend/src/lib/canisters/nns-dapp/nns-dapp.canister.ts +++ b/frontend/src/lib/canisters/nns-dapp/nns-dapp.canister.ts @@ -25,7 +25,7 @@ import type { AccountDetails, CanisterDetails, CreateSubAccountResponse, - GetAccountResponse, + GetAccountResponse, ImportedToken, ImportedTokens, RegisterHardwareWalletRequest, RegisterHardwareWalletResponse, RenameSubAccountRequest, @@ -325,4 +325,30 @@ export class NNSDappCanister { errorText ?? (nonNullish(response) ? JSON.stringify(response) : undefined) ); } + + public getImportedTokens = async (): Promise => { + const response = await this.certifiedService.get_imported_tokens(); + if ("Ok" in response) { + return response.Ok; + } + if ("AccountNotFound" in response) { + throw new AccountNotFoundError("error__account.not_found"); + } + // Edge case + throw new Error(`Error getting imported tokens ${JSON.stringify(response)}`); + }; + + public setImportedTokens = async (importedTokens: Array): Promise => { + const response = await this.certifiedService.set_imported_tokens( + { 'imported_tokens' : importedTokens } + ); + if ("Ok" in response) { + return; + } + if ("AccountNotFound" in response) { + throw new AccountNotFoundError("error__account.not_found"); + } + // Edge case + throw new Error(`Error setting imported tokens ${JSON.stringify(response)}`); + }; }