Ability to buy tokens with Moonpay (#15924)
* Ability to buy tokens with Moonpay * fix for test cases failing * updated description for MoonPayChainSettings type * removed test resultsfeature/default_network_editable
parent
d520fc57cb
commit
3f801e377d
@ -0,0 +1,19 @@ |
|||||||
|
import { |
||||||
|
BUYABLE_CHAINS_MAP, |
||||||
|
CHAIN_IDS, |
||||||
|
} from '../../../shared/constants/network'; |
||||||
|
|
||||||
|
export const formatMoonpaySymbol = (symbol, chainId = CHAIN_IDS.MAINNET) => { |
||||||
|
if (!symbol) { |
||||||
|
return symbol; |
||||||
|
} |
||||||
|
let _symbol = symbol; |
||||||
|
if (chainId === CHAIN_IDS.POLYGON || chainId === CHAIN_IDS.BSC) { |
||||||
|
_symbol = `${_symbol}_${BUYABLE_CHAINS_MAP?.[ |
||||||
|
chainId |
||||||
|
]?.network.toUpperCase()}`;
|
||||||
|
} else if (chainId === CHAIN_IDS.AVALANCHE) { |
||||||
|
_symbol = `${_symbol}_CCHAIN`; |
||||||
|
} |
||||||
|
return _symbol; |
||||||
|
}; |
@ -0,0 +1,33 @@ |
|||||||
|
import { CHAIN_IDS } from '../../../shared/constants/network'; |
||||||
|
import { formatMoonpaySymbol } from './moonpay'; |
||||||
|
|
||||||
|
describe('Moonpay Utils', () => { |
||||||
|
describe('formatMoonpaySymbol', () => { |
||||||
|
it('should return the same input if falsy input is provided', () => { |
||||||
|
expect(formatMoonpaySymbol()).toBe(undefined); |
||||||
|
expect(formatMoonpaySymbol(null)).toBe(null); |
||||||
|
expect(formatMoonpaySymbol('')).toBe(''); |
||||||
|
}); |
||||||
|
|
||||||
|
it('should return the symbol in uppercase if no chainId is provided', () => { |
||||||
|
const result = formatMoonpaySymbol('ETH'); |
||||||
|
expect(result).toStrictEqual('ETH'); |
||||||
|
}); |
||||||
|
|
||||||
|
it('should return the symbol in uppercase if chainId is different than Avalanche/BSC/Polygon', () => { |
||||||
|
const result = formatMoonpaySymbol('ETH', CHAIN_IDS.MAINNET); |
||||||
|
expect(result).toStrictEqual('ETH'); |
||||||
|
const result2 = formatMoonpaySymbol('CELO', CHAIN_IDS.CELO); |
||||||
|
expect(result2).toStrictEqual('CELO'); |
||||||
|
}); |
||||||
|
|
||||||
|
it('should return the symbol in uppercase with the network name if chainId is Avalanche/BSC/Polygon', () => { |
||||||
|
const result = formatMoonpaySymbol('BNB', CHAIN_IDS.BSC); |
||||||
|
expect(result).toStrictEqual('BNB_BSC'); |
||||||
|
const result2 = formatMoonpaySymbol('MATIC', CHAIN_IDS.POLYGON); |
||||||
|
expect(result2).toStrictEqual('MATIC_POLYGON'); |
||||||
|
const result3 = formatMoonpaySymbol('AVAX', CHAIN_IDS.AVALANCHE); |
||||||
|
expect(result3).toStrictEqual('AVAX_CCHAIN'); |
||||||
|
}); |
||||||
|
}); |
||||||
|
}); |
Loading…
Reference in new issue