From 952d612daf9f04313185d85ce07e3f9cddc3146b Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 26 Feb 2024 18:58:28 -0800 Subject: [PATCH] Add special mainnet case for ChangeNow --- CHANGELOG.md | 5 +++++ src/swap/central/changenow.ts | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1b4fd90..3e9d169f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +- added: (Swapuz) Above limit response handling +- added: (ChangeNow) AVAX special mainnet case +- fixed: (Exolix) Correctly handle below limit errors for 'from' quotes +- fixed: (Godex/Swapuz) Fix conversion to native units + ## 2.1.0 (2023-02-09) - added: Mainnet codes for Arbitrum, Axelar, Base, and Cosmos Hub diff --git a/src/swap/central/changenow.ts b/src/swap/central/changenow.ts index ca0150af..96431f92 100644 --- a/src/swap/central/changenow.ts +++ b/src/swap/central/changenow.ts @@ -15,6 +15,7 @@ import { EdgeSwapPlugin, EdgeSwapQuote, EdgeSwapRequest, + EdgeTokenId, SwapAboveLimitError, SwapBelowLimitError, SwapCurrencyError @@ -119,6 +120,12 @@ const MAINNET_CODE_TRANSCRIPTION = { zksync: 'zksync' } +const SPECIAL_MAINNET_CASES: { + [pId: string]: Map +} = { + avalanche: new Map([[null, 'cchain']]) +} + export function makeChangeNowPlugin( opts: EdgeCorePluginOptions ): EdgeSwapPlugin { @@ -147,9 +154,17 @@ export function makeChangeNowPlugin( const { fromCurrencyCode, toCurrencyCode, - fromMainnetCode, - toMainnetCode + fromMainnetCode: defaultFromMainnetCode, + toMainnetCode: defaultToMainnetCode } = getCodesWithTranscription(request, MAINNET_CODE_TRANSCRIPTION) + const fromMainnetCode = + SPECIAL_MAINNET_CASES[request.fromWallet.currencyInfo.pluginId]?.get( + request.fromTokenId + ) ?? defaultFromMainnetCode + const toMainnetCode = + SPECIAL_MAINNET_CASES[request.toWallet.currencyInfo.pluginId]?.get( + request.toTokenId + ) ?? defaultToMainnetCode const currencyString = `fromCurrency=${fromCurrencyCode}&toCurrency=${toCurrencyCode}&fromNetwork=${fromMainnetCode}&toNetwork=${toMainnetCode}` async function createOrder(