Skip to content

Commit 6bae3a5

Browse files
authored
Merge pull request #421 from EdgeApp/matthew/san-currency-code
Use tokenIds in place of currencyCodes
2 parents 197150c + b0e295c commit 6bae3a5

File tree

20 files changed

+423
-262
lines changed

20 files changed

+423
-262
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- changed: Replace wallet denomination methods with synchronous utils
6+
- changed: Use tokenIds in invalid currency objects
7+
58
## 2.40.0 (2025-12-04)
69

710
- added: (Maya) Zcash support

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"chai": "^4.2.0",
6969
"cleaner-config": "^0.1.10",
7070
"crypto-browserify": "^3.12.0",
71-
"edge-core-js": "^2.34.0",
71+
"edge-core-js": "^2.37.0",
7272
"edge-currency-accountbased": "^2.9.0",
7373
"edge-currency-plugins": "^2.4.1",
7474
"esbuild-loader": "^2.20.0",

src/swap/central/changehero.ts

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,22 @@ import {
2323

2424
import {
2525
ChainCodeTickerMap,
26-
checkInvalidCodes,
26+
checkInvalidTokenIds,
2727
checkWhitelistedMainnetCodes,
2828
CurrencyPluginIdSwapChainCodeMap,
2929
getChainAndTokenCodes,
3030
getMaxSwappable,
31-
InvalidCurrencyCodes,
31+
InvalidTokenIds,
3232
makeSwapPluginQuote,
3333
SwapOrder
3434
} from '../../util/swapHelpers'
35-
import { convertRequest, getAddress, memoType } from '../../util/utils'
35+
import {
36+
convertRequest,
37+
denominationToNative,
38+
getAddress,
39+
memoType,
40+
nativeToDenomination
41+
} from '../../util/utils'
3642
import { EdgeSwapRequestPlugin } from '../types'
3743

3844
const pluginId = 'changehero'
@@ -117,10 +123,10 @@ export const MAINNET_CODE_TRANSCRIPTION: CurrencyPluginIdSwapChainCodeMap = {
117123

118124
// See https://changehero.io/currencies for list of supported currencies
119125
// Or `curl -X POST 'https://api.changehero.io/v2' -H 'api-key: <your-api-key>' -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"one","method":"getCurrenciesFull","params":{}}'`
120-
const INVALID_CURRENCY_CODES: InvalidCurrencyCodes = {
126+
const INVALID_TOKEN_IDS: InvalidTokenIds = {
121127
from: {},
122128
to: {
123-
zcash: ['ZEC'] // ChangeHero doesn't support sending to shielded addresses
129+
zcash: [null] // ChangeHero doesn't support sending to shielded addresses
124130
}
125131
}
126132

@@ -255,13 +261,15 @@ export function makeChangeHeroPlugin(
255261

256262
const quoteAmount =
257263
request.quoteFor === 'from'
258-
? await request.fromWallet.nativeToDenomination(
264+
? nativeToDenomination(
265+
request.fromWallet,
259266
request.nativeAmount,
260-
request.fromCurrencyCode
267+
request.fromTokenId
261268
)
262-
: await request.toWallet.nativeToDenomination(
269+
: nativeToDenomination(
270+
request.toWallet,
263271
request.nativeAmount,
264-
request.toCurrencyCode
272+
request.toTokenId
265273
)
266274

267275
const fixRate = {
@@ -282,21 +290,25 @@ export function makeChangeHeroPlugin(
282290
const [
283291
{ id: responseId, maxFrom, maxTo, minFrom, minTo }
284292
] = asGetFixRateReply(fixedRateQuote).result
285-
const maxFromNative = await request.fromWallet.denominationToNative(
293+
const maxFromNative = denominationToNative(
294+
request.fromWallet,
286295
maxFrom,
287-
request.fromCurrencyCode
296+
request.fromTokenId
288297
)
289-
const maxToNative = await request.toWallet.denominationToNative(
298+
const maxToNative = denominationToNative(
299+
request.toWallet,
290300
maxTo,
291-
request.toCurrencyCode
301+
request.toTokenId
292302
)
293-
const minFromNative = await request.fromWallet.denominationToNative(
303+
const minFromNative = denominationToNative(
304+
request.fromWallet,
294305
minFrom,
295-
request.fromCurrencyCode
306+
request.fromTokenId
296307
)
297-
const minToNative = await request.toWallet.denominationToNative(
308+
const minToNative = denominationToNative(
309+
request.toWallet,
298310
minTo,
299-
request.toCurrencyCode
311+
request.toTokenId
300312
)
301313

302314
if (request.quoteFor === 'from') {
@@ -356,13 +368,15 @@ export function makeChangeHeroPlugin(
356368
checkReply(sendReply, request)
357369

358370
const quoteInfo = asCreateFixTransactionReply(sendReply).result
359-
const amountExpectedFromNative = await request.fromWallet.denominationToNative(
371+
const amountExpectedFromNative = denominationToNative(
372+
request.fromWallet,
360373
`${quoteInfo.amountExpectedFrom.toString()}`,
361-
request.fromCurrencyCode
374+
request.fromTokenId
362375
)
363-
const amountExpectedToNative = await request.toWallet.denominationToNative(
376+
const amountExpectedToNative = denominationToNative(
377+
request.toWallet,
364378
`${quoteInfo.amountExpectedTo.toString()}`,
365-
request.toCurrencyCode
379+
request.toTokenId
366380
)
367381

368382
const memos: EdgeMemo[] =
@@ -427,7 +441,7 @@ export function makeChangeHeroPlugin(
427441
// Fetch and persist chaincode/tokencode maps from provider
428442
await fetchSupportedAssets()
429443

430-
checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)
444+
checkInvalidTokenIds(INVALID_TOKEN_IDS, request, swapInfo)
431445
checkWhitelistedMainnetCodes(
432446
MAINNET_CODE_TRANSCRIPTION,
433447
request,

src/swap/central/changenow.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,24 @@ import {
2626

2727
import {
2828
ChainCodeTickerMap,
29-
checkInvalidCodes,
29+
checkInvalidTokenIds,
3030
checkWhitelistedMainnetCodes,
3131
CurrencyPluginIdSwapChainCodeMap,
3232
EdgeIdSwapIdMap,
3333
ensureInFuture,
3434
getChainAndTokenCodes,
3535
getMaxSwappable,
36-
InvalidCurrencyCodes,
36+
InvalidTokenIds,
3737
makeSwapPluginQuote,
3838
SwapOrder
3939
} from '../../util/swapHelpers'
40-
import { convertRequest, getAddress, memoType } from '../../util/utils'
40+
import {
41+
convertRequest,
42+
denominationToNative,
43+
getAddress,
44+
memoType,
45+
nativeToDenomination
46+
} from '../../util/utils'
4147
import { EdgeSwapRequestPlugin, StringMap } from '../types'
4248

4349
const pluginId = 'changenow'
@@ -56,7 +62,7 @@ const asInitOptions = asObject({
5662
const orderUri = 'https://changenow.io/exchange/txs/'
5763
const uri = 'https://api.changenow.io/v2/'
5864

59-
const INVALID_CURRENCY_CODES: InvalidCurrencyCodes = {
65+
const INVALID_TOKEN_IDS: InvalidTokenIds = {
6066
from: {},
6167
to: {}
6268
}
@@ -282,9 +288,10 @@ export function makeChangeNowPlugin(
282288
async function swapSell(
283289
flow: 'fixed-rate' | 'standard'
284290
): Promise<SwapOrder> {
285-
const largeDenomAmount = await request.fromWallet.nativeToDenomination(
291+
const largeDenomAmount = nativeToDenomination(
292+
request.fromWallet,
286293
nativeAmount,
287-
request.fromCurrencyCode
294+
request.fromTokenId
288295
)
289296

290297
// Get min and max
@@ -300,17 +307,19 @@ export function makeChangeNowPlugin(
300307
const { minAmount, maxAmount } = asMarketRange(marketRangeResponseJson)
301308

302309
if (lt(largeDenomAmount, minAmount.toString())) {
303-
const minNativeAmount = await request.fromWallet.denominationToNative(
310+
const minNativeAmount = denominationToNative(
311+
request.fromWallet,
304312
minAmount.toString(),
305-
request.fromCurrencyCode
313+
request.fromTokenId
306314
)
307315
throw new SwapBelowLimitError(swapInfo, minNativeAmount)
308316
}
309317

310318
if (maxAmount != null && gt(largeDenomAmount, maxAmount.toString())) {
311-
const maxNativeAmount = await request.fromWallet.denominationToNative(
319+
const maxNativeAmount = denominationToNative(
320+
request.fromWallet,
312321
maxAmount.toString(),
313-
request.fromCurrencyCode
322+
request.fromTokenId
314323
)
315324
throw new SwapAboveLimitError(swapInfo, maxNativeAmount)
316325
}
@@ -323,9 +332,10 @@ export function makeChangeNowPlugin(
323332
validUntil
324333
} = await createOrder(flow, true, largeDenomAmount)
325334

326-
const toNativeAmount = await request.toWallet.denominationToNative(
335+
const toNativeAmount = denominationToNative(
336+
request.toWallet,
327337
toAmount.toString(),
328-
request.toCurrencyCode
338+
request.toTokenId
329339
)
330340

331341
const memos: EdgeMemo[] =
@@ -387,9 +397,10 @@ export function makeChangeNowPlugin(
387397

388398
async function swapBuy(flow: 'fixed-rate'): Promise<SwapOrder> {
389399
// Skip min/max check when requesting a purchase amount
390-
const largeDenomAmount = await request.toWallet.nativeToDenomination(
400+
const largeDenomAmount = nativeToDenomination(
401+
request.toWallet,
391402
nativeAmount,
392-
request.toCurrencyCode
403+
request.toTokenId
393404
)
394405

395406
const {
@@ -400,9 +411,10 @@ export function makeChangeNowPlugin(
400411
validUntil
401412
} = await createOrder(flow, false, largeDenomAmount)
402413

403-
const fromNativeAmount = await request.fromWallet.denominationToNative(
414+
const fromNativeAmount = denominationToNative(
415+
request.fromWallet,
404416
fromAmount.toString(),
405-
request.fromCurrencyCode
417+
request.fromTokenId
406418
)
407419

408420
const memos: EdgeMemo[] =
@@ -494,7 +506,7 @@ export function makeChangeNowPlugin(
494506
// Fetch and persist chaincode/tokencode maps from provider
495507
await fetchSupportedAssets()
496508

497-
checkInvalidCodes(INVALID_CURRENCY_CODES, request, swapInfo)
509+
checkInvalidTokenIds(INVALID_TOKEN_IDS, request, swapInfo)
498510
checkWhitelistedMainnetCodes(
499511
MAINNET_CODE_TRANSCRIPTION,
500512
request,

0 commit comments

Comments
 (0)