Skip to content

Commit

Permalink
Merge pull request #343 from EdgeApp/jon/fix/matic-pol
Browse files Browse the repository at this point in the history
Jon/fix/matic-pol
  • Loading branch information
Jon-edge authored Sep 30, 2024
2 parents 708926e + 6ddaad0 commit 4219fc2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
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

- fixed: POL currency code transcriptions for `letsexchange` and `changenow`

## 2.9.0 (2024-09-27)

- added: Add Maya Protocol
Expand Down
41 changes: 26 additions & 15 deletions src/swap/central/changenow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import {
import {
checkInvalidCodes,
checkWhitelistedMainnetCodes,
CurrencyCodeTranscriptionMap,
ensureInFuture,
getCodes,
getCodesWithTranscription,
getMaxSwappable,
InvalidCurrencyCodes,
Expand Down Expand Up @@ -128,6 +130,10 @@ const SPECIAL_MAINNET_CASES: {
avalanche: new Map([[null, 'cchain']])
}

const CURRENCY_CODE_TRANSCRIPTION: CurrencyCodeTranscriptionMap = {
polygon: { POL: 'matic' }
}

export function makeChangeNowPlugin(
opts: EdgeCorePluginOptions
): EdgeSwapPlugin {
Expand All @@ -153,21 +159,26 @@ export function makeChangeNowPlugin(
getAddress(request.toWallet)
])

const {
fromCurrencyCode,
toCurrencyCode,
fromMainnetCode: defaultFromMainnetCode,
toMainnetCode: defaultToMainnetCode
} = getCodesWithTranscription(request, MAINNET_CODE_TRANSCRIPTION)
const fromMainnetCode =
// Get our currency codes
const { fromCurrencyCode, toCurrencyCode } = getCodes(request)

// Get Changenow's codes for the request
const changenowCodes = getCodesWithTranscription(
request,
MAINNET_CODE_TRANSCRIPTION,
CURRENCY_CODE_TRANSCRIPTION
)
// Modify special mainnet code cases
changenowCodes.fromMainnetCode =
SPECIAL_MAINNET_CASES[request.fromWallet.currencyInfo.pluginId]?.get(
request.fromTokenId
) ?? defaultFromMainnetCode
const toMainnetCode =
) ?? changenowCodes.fromMainnetCode
changenowCodes.toMainnetCode =
SPECIAL_MAINNET_CASES[request.toWallet.currencyInfo.pluginId]?.get(
request.toTokenId
) ?? defaultToMainnetCode
const currencyString = `fromCurrency=${fromCurrencyCode}&toCurrency=${toCurrencyCode}&fromNetwork=${fromMainnetCode}&toNetwork=${toMainnetCode}`
) ?? changenowCodes.toMainnetCode

const currencyString = `fromCurrency=${changenowCodes.fromCurrencyCode}&toCurrency=${changenowCodes.toCurrencyCode}&fromNetwork=${changenowCodes.fromMainnetCode}&toNetwork=${changenowCodes.toMainnetCode}`

async function createOrder(
flow: 'fixed-rate' | 'standard',
Expand All @@ -192,10 +203,10 @@ export function makeChangeNowPlugin(

// Create order
const orderBody = {
fromCurrency: fromCurrencyCode,
toCurrency: toCurrencyCode,
fromNetwork: fromMainnetCode,
toNetwork: toMainnetCode,
fromCurrency: changenowCodes.fromCurrencyCode,
toCurrency: changenowCodes.toCurrencyCode,
fromNetwork: changenowCodes.fromMainnetCode,
toNetwork: changenowCodes.toMainnetCode,
fromAmount: isSelling ? largeDenomAmount : '',
toAmount: isSelling ? '' : largeDenomAmount,
type,
Expand Down
2 changes: 1 addition & 1 deletion src/swap/central/letsexchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const MAINNET_CODE_TRANSCRIPTION = {
osmosis: 'OSMO',
piratechain: 'ARRR',
polkadot: 'DOT',
polygon: 'MATIC',
polygon: 'POL',
pulsechain: 'PLS',
qtum: 'QTUM',
ravencoin: 'RVN',
Expand Down

0 comments on commit 4219fc2

Please sign in to comment.