Skip to content
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Unreleased

- added: `EdgeAccount.fetchSwapQuotes` accepts an `EdgeSwapSendRequest`, for swaps that pay out to an address.
- added: `EdgeTxActionSwapSend`, for sends that settle through a swap provider.
- added: `EdgeSwapRequest.privacy`, restricting quotes to sender-unlinkable routes.
- added: `EdgeSwapRequestOptions.forceEnabled`, for querying plugins the user switched off.
- added: `EdgeCurrencyConfig.parseUri`, for parsing a URI without a wallet.
- added: `EdgeParsedUri.addressTypes`, listing the address formats a parsed address matches.

## 2.50.0 (2026-09-29)

- added: `EdgeContextOptions.apiSigner`, for delegating API request signing to native code.
Expand Down
5 changes: 3 additions & 2 deletions src/core/account/account-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
EdgeSwapQuote,
EdgeSwapRequest,
EdgeSwapRequestOptions,
EdgeSwapSendRequest,
EdgeWalletInfo,
EdgeWalletInfoFull,
EdgeWalletStates
Expand Down Expand Up @@ -871,7 +872,7 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
// ----------------------------------------------------------------

async fetchSwapQuote(
request: EdgeSwapRequest,
request: EdgeSwapRequest | EdgeSwapSendRequest,
opts?: EdgeSwapRequestOptions
): Promise<EdgeSwapQuote> {
const [bestQuote, ...otherQuotes] = await fetchSwapQuotes(
Expand All @@ -892,7 +893,7 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
},

async fetchSwapQuotes(
request: EdgeSwapRequest,
request: EdgeSwapRequest | EdgeSwapSendRequest,
opts?: EdgeSwapRequestOptions
): Promise<EdgeSwapQuote[]> {
return await fetchSwapQuotes(ai, accountId, request, opts)
Expand Down
35 changes: 35 additions & 0 deletions src/core/account/custom-tokens.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { asMaybe, asObject, asString } from 'cleaners'

import { upgradeCurrencyCode } from '../../types/type-helpers'
import {
EdgeCurrencyEngine,
EdgeMetaToken,
EdgeParsedUri,
EdgePluginMap,
EdgeToken,
EdgeTokenInfo,
Expand Down Expand Up @@ -118,6 +120,39 @@ export function makeMetaTokens(tokens: EdgeTokenMap = {}): EdgeMetaToken[] {
return out
}

/**
* Parses a URI with a plugin's currency tools on behalf of an account.
* The parser receives the account's custom tokens, and a result that
* names its asset only by the deprecated `currencyCode` gains a `tokenId`.
*/
export async function parseCurrencyUri(
ai: ApiInput,
accountId: string,
pluginId: string,
uri: string,
currencyCode?: string
): Promise<EdgeParsedUri> {
const tools = await getCurrencyTools(ai, pluginId)
const { state } = ai.props
const { allTokens, customTokens } = state.accounts[accountId]

const parsedUri = await tools.parseUri(
uri,
currencyCode,
makeMetaTokens(customTokens[pluginId])
)

if (parsedUri.tokenId === undefined) {
const { tokenId = null } = upgradeCurrencyCode({
allTokens: allTokens[pluginId],
currencyInfo: state.plugins.currency[pluginId].currencyInfo,
currencyCode: parsedUri.currencyCode ?? currencyCode
})
parsedUri.tokenId = tokenId
}
return parsedUri
}

export function makeTokenInfo(token: EdgeToken): EdgeTokenInfo | undefined {
const { currencyCode, displayName, denominations, networkLocation } = token
const cleanLocation = asMaybeContractLocation(networkLocation)
Expand Down
8 changes: 7 additions & 1 deletion src/core/account/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EdgeCurrencyInfo,
EdgeGetTokenDetailsFilter,
EdgeOtherMethods,
EdgeParsedUri,
EdgeSwapConfig,
EdgeSwapInfo,
EdgeToken,
Expand All @@ -14,7 +15,7 @@ import { uniqueStrings } from '../currency/wallet/enabled-tokens'
import { getCurrencyTools } from '../plugins/plugins-selectors'
import { ApiInput } from '../root-pixie'
import { changePluginUserSettings, changeSwapSettings } from './account-files'
import { getTokenId } from './custom-tokens'
import { getTokenId, parseCurrencyUri } from './custom-tokens'

const emptyTokens: EdgeTokenMap = {}
const emptyTokenIds: string[] = []
Expand Down Expand Up @@ -223,6 +224,11 @@ export class CurrencyConfig
const keys = await tools.importPrivateKey(userInput, opts.keyOptions)
return { ...keys, imported: true }
}

async parseUri(uri: string, currencyCode?: string): Promise<EdgeParsedUri> {
const { _accountId: accountId, _ai: ai, _pluginId: pluginId } = this
return await parseCurrencyUri(ai, accountId, pluginId, uri, currencyCode)
}
}

export class SwapConfig extends Bridgeable<EdgeSwapConfig> {
Expand Down
21 changes: 2 additions & 19 deletions src/core/currency/wallet/currency-wallet-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
JsonObject
} from '../../../types/types'
import { compare } from '../../../util/compare'
import { makeMetaTokens } from '../../account/custom-tokens'
import { makeMetaTokens, parseCurrencyUri } from '../../account/custom-tokens'
import { splitWalletInfo } from '../../login/splitting'
import { getCurrencyTools } from '../../plugins/plugins-selectors'
import { RootProps, toApiInput } from '../../root-pixie'
Expand Down Expand Up @@ -1033,24 +1033,7 @@ export function makeCurrencyWalletApi(
)
},
async parseUri(uri: string, currencyCode?: string): Promise<EdgeParsedUri> {
const tools = await getTools()
const parsedUri = await tools.parseUri(
uri,
currencyCode,
makeMetaTokens(
input.props.state.accounts[accountId].customTokens[pluginId]
)
)

if (parsedUri.tokenId === undefined) {
const { tokenId = null } = upgradeCurrencyCode({
allTokens: input.props.state.accounts[accountId].allTokens[pluginId],
currencyInfo: plugin.currencyInfo,
currencyCode: parsedUri.currencyCode ?? currencyCode
})
parsedUri.tokenId = tokenId
}
return parsedUri
return await parseCurrencyUri(ai, accountId, pluginId, uri, currencyCode)
},

// Generic:
Expand Down
15 changes: 15 additions & 0 deletions src/core/currency/wallet/currency-wallet-cleaners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
EdgeTxActionGiftCard,
EdgeTxActionStake,
EdgeTxActionSwap,
EdgeTxActionSwapSend,
EdgeTxActionTokenApproval,
EdgeTxSwap
} from '../../../types/types'
Expand Down Expand Up @@ -195,6 +196,19 @@ export const asEdgeTxActionSwap = asObject<EdgeTxActionSwap>({
refundAddress: asOptional(asString)
})

export const asEdgeTxActionSwapSend = asObject<EdgeTxActionSwapSend>({
actionType: asValue('swapSend'),
swapInfo: asEdgeSwapInfo,
orderId: asOptional(asString),
orderUri: asOptional(asString),
isEstimate: asBoolean,
fromAsset: asEdgeAssetAmount,
toAsset: asEdgeAssetAmount,
payoutAddress: asString,
refundAddress: asOptional(asString),
privacy: asBoolean
})

export const asEdgeTxActionStake = asObject<EdgeTxActionStake>({
actionType: asValue('stake'),
pluginId: asString,
Expand Down Expand Up @@ -257,6 +271,7 @@ export const asEdgeTxActionGiftCard = asObject<EdgeTxActionGiftCard>({

export const asEdgeTxAction: Cleaner<EdgeTxAction> = asEither(
asEdgeTxActionSwap,
asEdgeTxActionSwapSend,
asEdgeTxActionStake,
asEdgeTxActionFiat,
asEdgeTxActionTokenApproval,
Expand Down
Loading
Loading