Skip to content

Add getTokenDetails to currency tools #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- added: Add `getTokenDetails` to currency tools

## 2.28.0 (2025-05-22)

- added: Added `forDuressAccount` option to `checkPin`.
Expand Down
10 changes: 10 additions & 0 deletions src/core/account/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Bridgeable, bridgifyObject } from 'yaob'
import {
EdgeCurrencyConfig,
EdgeCurrencyInfo,
EdgeGetTokenDetailsFilter,
EdgeOtherMethods,
EdgeSwapConfig,
EdgeSwapInfo,
Expand Down Expand Up @@ -68,6 +69,15 @@ export class CurrencyConfig
return state.accounts[accountId].customTokens[pluginId] ?? emptyTokens
}

async getTokenDetails(
filter: EdgeGetTokenDetailsFilter
): Promise<EdgeToken[]> {
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<string> {
const { _ai: ai, _pluginId: pluginId } = this
return await getTokenId(ai, pluginId, token)
Expand Down
17 changes: 17 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -1126,6 +1137,9 @@ export interface EdgeCurrencyTools {
key: string,
opts?: JsonObject
) => Promise<JsonObject>
readonly getTokenDetails?: (
filter: EdgeGetTokenDetailsFilter
) => Promise<EdgeToken[]>

// Derives a tokenId string from a token's network information:
readonly getTokenId?: (token: EdgeToken) => Promise<string>
Expand Down Expand Up @@ -1577,6 +1591,9 @@ export interface EdgeCurrencyConfig {
readonly allTokens: EdgeTokenMap
readonly builtinTokens: EdgeTokenMap
readonly customTokens: EdgeTokenMap
readonly getTokenDetails: (
filter: EdgeGetTokenDetailsFilter
) => Promise<EdgeToken[]>
readonly getTokenId: (token: EdgeToken) => Promise<string>
readonly addCustomToken: (token: EdgeToken) => Promise<string>
readonly changeCustomToken: (
Expand Down
Loading