From ee2855d13e21197ab11b799024a9bdd58c7d62a6 Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 19 May 2025 14:57:33 -0700 Subject: [PATCH] Add `getTokenDetails` to currency tools --- CHANGELOG.md | 2 ++ src/core/account/plugin-api.ts | 10 ++++++++++ src/types/types.ts | 17 +++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index af62bfd0..ebd982ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- added: Add `getTokenDetails` to currency tools + ## 2.28.0 (2025-05-22) - added: Added `forDuressAccount` option to `checkPin`. diff --git a/src/core/account/plugin-api.ts b/src/core/account/plugin-api.ts index 8d00fb38..7bff1070 100644 --- a/src/core/account/plugin-api.ts +++ b/src/core/account/plugin-api.ts @@ -3,6 +3,7 @@ import { Bridgeable, bridgifyObject } from 'yaob' import { EdgeCurrencyConfig, EdgeCurrencyInfo, + EdgeGetTokenDetailsFilter, EdgeOtherMethods, EdgeSwapConfig, EdgeSwapInfo, @@ -68,6 +69,15 @@ export class CurrencyConfig return state.accounts[accountId].customTokens[pluginId] ?? emptyTokens } + async getTokenDetails( + filter: EdgeGetTokenDetailsFilter + ): Promise { + const { _ai: ai, _pluginId: pluginId } = this + const tools = await getCurrencyTools(ai, pluginId) + if (tools.getTokenDetails == null) return [] + return await tools.getTokenDetails(filter) + } + async getTokenId(token: EdgeToken): Promise { const { _ai: ai, _pluginId: pluginId } = this return await getTokenId(ai, pluginId, token) diff --git a/src/types/types.ts b/src/types/types.ts index c9366050..bd570817 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -426,6 +426,17 @@ export interface EdgeTokenInfo { multiplier: string } +/** + * The search parameter for {@link EdgeCurrencyConfig.getTokenDetails} and + * {@link EdgeCurrencyTools.getTokenDetails}. + */ +export interface EdgeGetTokenDetailsFilter { + /** Contract address or other unique onchain identifier. */ + contractAddress?: string + /** Ticker symbol for the currency. */ + currencyCode?: string +} + // currency info ------------------------------------------------------- export type EdgeObjectTemplate = Array< @@ -1126,6 +1137,9 @@ export interface EdgeCurrencyTools { key: string, opts?: JsonObject ) => Promise + readonly getTokenDetails?: ( + filter: EdgeGetTokenDetailsFilter + ) => Promise // Derives a tokenId string from a token's network information: readonly getTokenId?: (token: EdgeToken) => Promise @@ -1577,6 +1591,9 @@ export interface EdgeCurrencyConfig { readonly allTokens: EdgeTokenMap readonly builtinTokens: EdgeTokenMap readonly customTokens: EdgeTokenMap + readonly getTokenDetails: ( + filter: EdgeGetTokenDetailsFilter + ) => Promise readonly getTokenId: (token: EdgeToken) => Promise readonly addCustomToken: (token: EdgeToken) => Promise readonly changeCustomToken: (