mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Ability to buy tokens with Wyre (#15992)
This commit is contained in:
parent
b0baa89aba
commit
18ca016cf0
@ -20,15 +20,20 @@ const fetchWithTimeout = getFetchWithTimeout();
|
|||||||
*
|
*
|
||||||
* @param {string} walletAddress - Ethereum destination address
|
* @param {string} walletAddress - Ethereum destination address
|
||||||
* @param {string} chainId - Current chain ID
|
* @param {string} chainId - Current chain ID
|
||||||
|
* @param {string|undefined} symbol - Token symbol to buy
|
||||||
* @returns String
|
* @returns String
|
||||||
*/
|
*/
|
||||||
const createWyrePurchaseUrl = async (walletAddress, chainId) => {
|
const createWyrePurchaseUrl = async (walletAddress, chainId, symbol) => {
|
||||||
const { wyre = {} } = BUYABLE_CHAINS_MAP[chainId];
|
const { wyre = {} } = BUYABLE_CHAINS_MAP[chainId];
|
||||||
const { srn, currencyCode } = wyre;
|
const { srn, currencyCode } = wyre;
|
||||||
|
|
||||||
const networkId = parseInt(chainId, 16);
|
const networkId = parseInt(chainId, 16);
|
||||||
const fiatOnRampUrlApi = `${SWAPS_API_V2_BASE_URL}/networks/${networkId}/fiatOnRampUrl?serviceName=wyre&destinationAddress=${walletAddress}`;
|
const fiatOnRampUrlApi = `${SWAPS_API_V2_BASE_URL}/networks/${networkId}/fiatOnRampUrl?serviceName=wyre&destinationAddress=${walletAddress}¤cy=${
|
||||||
const wyrePurchaseUrlFallback = `https://pay.sendwyre.com/purchase?dest=${srn}:${walletAddress}&destCurrency=${currencyCode}&accountId=AC-7AG3W4XH4N2&paymentMethod=debit-card`;
|
symbol || currencyCode
|
||||||
|
}`;
|
||||||
|
const wyrePurchaseUrlFallback = `https://pay.sendwyre.com/purchase?dest=${srn}:${walletAddress}&destCurrency=${
|
||||||
|
symbol || currencyCode
|
||||||
|
}&accountId=AC-7AG3W4XH4N2&paymentMethod=debit-card`;
|
||||||
try {
|
try {
|
||||||
const response = await fetchWithTimeout(fiatOnRampUrlApi, {
|
const response = await fetchWithTimeout(fiatOnRampUrlApi, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -158,7 +163,7 @@ export default async function getBuyUrl({ chainId, address, service, symbol }) {
|
|||||||
|
|
||||||
switch (service) {
|
switch (service) {
|
||||||
case 'wyre':
|
case 'wyre':
|
||||||
return await createWyrePurchaseUrl(address, chainId);
|
return await createWyrePurchaseUrl(address, chainId, symbol);
|
||||||
case 'transak':
|
case 'transak':
|
||||||
return createTransakUrl(address, chainId, symbol);
|
return createTransakUrl(address, chainId, symbol);
|
||||||
case 'moonpay':
|
case 'moonpay':
|
||||||
|
@ -39,7 +39,7 @@ describe('buy-url', () => {
|
|||||||
it('returns Wyre url with an ETH address for Ethereum mainnet', async () => {
|
it('returns Wyre url with an ETH address for Ethereum mainnet', async () => {
|
||||||
nock(SWAPS_API_V2_BASE_URL)
|
nock(SWAPS_API_V2_BASE_URL)
|
||||||
.get(
|
.get(
|
||||||
`/networks/1/fiatOnRampUrl?serviceName=wyre&destinationAddress=${ETH_ADDRESS}`,
|
`/networks/1/fiatOnRampUrl?serviceName=wyre&destinationAddress=${ETH_ADDRESS}¤cy=${CURRENCY_SYMBOLS.ETH}`,
|
||||||
)
|
)
|
||||||
.reply(200, {
|
.reply(200, {
|
||||||
url: `https://pay.sendwyre.com/purchase?accountId=${WYRE_ACCOUNT_ID}&utm_campaign=${WYRE_ACCOUNT_ID}&destCurrency=${CURRENCY_SYMBOLS.ETH}&utm_medium=widget&paymentMethod=debit-card&reservation=MLZVUF8FMXZUMARJC23B&dest=ethereum%3A${ETH_ADDRESS}&utm_source=checkout`,
|
url: `https://pay.sendwyre.com/purchase?accountId=${WYRE_ACCOUNT_ID}&utm_campaign=${WYRE_ACCOUNT_ID}&destCurrency=${CURRENCY_SYMBOLS.ETH}&utm_medium=widget&paymentMethod=debit-card&reservation=MLZVUF8FMXZUMARJC23B&dest=ethereum%3A${ETH_ADDRESS}&utm_source=checkout`,
|
||||||
|
@ -113,6 +113,10 @@ type WyreChainSettings = {
|
|||||||
* The native currency for the network
|
* The native currency for the network
|
||||||
*/
|
*/
|
||||||
currencyCode: CurrencySymbol;
|
currencyCode: CurrencySymbol;
|
||||||
|
/**
|
||||||
|
* The list of supported currencies for the Wyre onramp provider
|
||||||
|
*/
|
||||||
|
currencies: SupportedCurrencySymbol[];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -309,6 +313,8 @@ const SUPPORTED_CURRENCY_SYMBOLS = {
|
|||||||
AUCTION: 'AUCTION',
|
AUCTION: 'AUCTION',
|
||||||
AXS: 'AXS',
|
AXS: 'AXS',
|
||||||
AVAX: 'AVAX',
|
AVAX: 'AVAX',
|
||||||
|
AVAXC: 'AVAXC',
|
||||||
|
AVAXCUSDC: 'AVAXCUSDC',
|
||||||
BADGER: 'BADGER',
|
BADGER: 'BADGER',
|
||||||
BAL: 'BAL',
|
BAL: 'BAL',
|
||||||
BAND: 'BAND',
|
BAND: 'BAND',
|
||||||
@ -340,6 +346,8 @@ const SUPPORTED_CURRENCY_SYMBOLS = {
|
|||||||
GRT: 'GRT',
|
GRT: 'GRT',
|
||||||
GTC: 'GTC',
|
GTC: 'GTC',
|
||||||
GTH: 'GTH',
|
GTH: 'GTH',
|
||||||
|
GUSD: 'GUSD',
|
||||||
|
GYEN: 'GYEN',
|
||||||
HEX: 'HEX',
|
HEX: 'HEX',
|
||||||
IOTX: 'IOTX',
|
IOTX: 'IOTX',
|
||||||
IMX: 'IMX',
|
IMX: 'IMX',
|
||||||
@ -358,6 +366,7 @@ const SUPPORTED_CURRENCY_SYMBOLS = {
|
|||||||
MKR: 'MKR',
|
MKR: 'MKR',
|
||||||
MLN: 'MLN',
|
MLN: 'MLN',
|
||||||
MTL: 'MTL',
|
MTL: 'MTL',
|
||||||
|
MUSDC: 'mUSDC',
|
||||||
NKN: 'NKN',
|
NKN: 'NKN',
|
||||||
NMR: 'NMR',
|
NMR: 'NMR',
|
||||||
NU: 'NU',
|
NU: 'NU',
|
||||||
@ -397,13 +406,16 @@ const SUPPORTED_CURRENCY_SYMBOLS = {
|
|||||||
TXL: 'TXL',
|
TXL: 'TXL',
|
||||||
UMA: 'UMA',
|
UMA: 'UMA',
|
||||||
UNI: 'UNI',
|
UNI: 'UNI',
|
||||||
|
USDS: 'USDS',
|
||||||
VRA: 'VRA',
|
VRA: 'VRA',
|
||||||
WBTC: 'WBTC',
|
WBTC: 'WBTC',
|
||||||
WCFG: 'WCFG',
|
WCFG: 'WCFG',
|
||||||
XYO: 'XYO',
|
XYO: 'XYO',
|
||||||
YFII: 'YFII',
|
YFII: 'YFII',
|
||||||
|
YFI: 'YFI',
|
||||||
YLD: 'YLD',
|
YLD: 'YLD',
|
||||||
ZRX: 'ZRX',
|
ZRX: 'ZRX',
|
||||||
|
ZUSD: 'ZUSD',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const ETH_TOKEN_IMAGE_URL = './images/eth_logo.svg';
|
export const ETH_TOKEN_IMAGE_URL = './images/eth_logo.svg';
|
||||||
@ -693,6 +705,31 @@ export const BUYABLE_CHAINS_MAP: {
|
|||||||
wyre: {
|
wyre: {
|
||||||
srn: 'ethereum',
|
srn: 'ethereum',
|
||||||
currencyCode: CURRENCY_SYMBOLS.ETH,
|
currencyCode: CURRENCY_SYMBOLS.ETH,
|
||||||
|
currencies: [
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.ETH,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.AAVE,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.BAT,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.BUSD,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.COMP,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.CRV,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.DAI,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.GUSD,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.GYEN,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.LINK,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.MKR,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.PAX,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.RAI,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.SNX,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.UMA,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.UNI,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.USDC,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.USDS,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.USDT,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.WBTC,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.WETH,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.YFI,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.ZUSD,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
coinbasePayCurrencies: [
|
coinbasePayCurrencies: [
|
||||||
SUPPORTED_CURRENCY_SYMBOLS.ETH,
|
SUPPORTED_CURRENCY_SYMBOLS.ETH,
|
||||||
@ -849,6 +886,10 @@ export const BUYABLE_CHAINS_MAP: {
|
|||||||
wyre: {
|
wyre: {
|
||||||
srn: 'matic',
|
srn: 'matic',
|
||||||
currencyCode: CURRENCY_SYMBOLS.MATIC,
|
currencyCode: CURRENCY_SYMBOLS.MATIC,
|
||||||
|
currencies: [
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.MATIC,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.MUSDC,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[CHAIN_IDS.AVALANCHE]: {
|
[CHAIN_IDS.AVALANCHE]: {
|
||||||
@ -862,6 +903,11 @@ export const BUYABLE_CHAINS_MAP: {
|
|||||||
wyre: {
|
wyre: {
|
||||||
srn: 'avalanche',
|
srn: 'avalanche',
|
||||||
currencyCode: CURRENCY_SYMBOLS.AVALANCHE,
|
currencyCode: CURRENCY_SYMBOLS.AVALANCHE,
|
||||||
|
currencies: [
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.AVALANCHE,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.AVAXC,
|
||||||
|
SUPPORTED_CURRENCY_SYMBOLS.AVAXCUSDC,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
coinbasePayCurrencies: [SUPPORTED_CURRENCY_SYMBOLS.AVALANCHE],
|
coinbasePayCurrencies: [SUPPORTED_CURRENCY_SYMBOLS.AVALANCHE],
|
||||||
},
|
},
|
||||||
|
@ -29,6 +29,7 @@ import {
|
|||||||
getIsBuyableCoinbasePayToken,
|
getIsBuyableCoinbasePayToken,
|
||||||
getIsBuyableTransakToken,
|
getIsBuyableTransakToken,
|
||||||
getIsBuyableMoonpayToken,
|
getIsBuyableMoonpayToken,
|
||||||
|
getIsBuyableWyreToken,
|
||||||
} from '../../../selectors/selectors';
|
} from '../../../selectors/selectors';
|
||||||
|
|
||||||
import OnRampItem from './on-ramp-item';
|
import OnRampItem from './on-ramp-item';
|
||||||
@ -57,6 +58,9 @@ const DepositPopover = ({ onClose, token }) => {
|
|||||||
const isTokenBuyableMoonpay = useSelector((state) =>
|
const isTokenBuyableMoonpay = useSelector((state) =>
|
||||||
getIsBuyableMoonpayToken(state, token?.symbol),
|
getIsBuyableMoonpayToken(state, token?.symbol),
|
||||||
);
|
);
|
||||||
|
const isTokenBuyableWyre = useSelector((state) =>
|
||||||
|
getIsBuyableWyreToken(state, token?.symbol),
|
||||||
|
);
|
||||||
|
|
||||||
const networkName = NETWORK_TO_NAME_MAP[chainId];
|
const networkName = NETWORK_TO_NAME_MAP[chainId];
|
||||||
const symbol = token
|
const symbol = token
|
||||||
@ -86,7 +90,7 @@ const DepositPopover = ({ onClose, token }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
const toWyre = () => {
|
const toWyre = () => {
|
||||||
dispatch(buy({ service: 'wyre', address, chainId }));
|
dispatch(buy({ service: 'wyre', address, chainId, symbol: token?.symbol }));
|
||||||
};
|
};
|
||||||
const toFaucet = () => dispatch(buy({ chainId }));
|
const toFaucet = () => dispatch(buy({ chainId }));
|
||||||
|
|
||||||
@ -165,7 +169,6 @@ const DepositPopover = ({ onClose, token }) => {
|
|||||||
: !isBuyableMoonPayChain
|
: !isBuyableMoonPayChain
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<OnRampItem
|
<OnRampItem
|
||||||
logo={<LogoWyre />}
|
logo={<LogoWyre />}
|
||||||
title={t('buyWithWyre', [symbol])}
|
title={t('buyWithWyre', [symbol])}
|
||||||
@ -181,7 +184,11 @@ const DepositPopover = ({ onClose, token }) => {
|
|||||||
});
|
});
|
||||||
toWyre();
|
toWyre();
|
||||||
}}
|
}}
|
||||||
hide={isTokenDeposit || !isBuyableWyreChain}
|
hide={
|
||||||
|
isTokenDeposit
|
||||||
|
? !isBuyableWyreChain || !isTokenBuyableWyre
|
||||||
|
: !isBuyableWyreChain
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<OnRampItem
|
<OnRampItem
|
||||||
|
@ -22,6 +22,7 @@ import {
|
|||||||
getIsBuyableCoinbasePayToken,
|
getIsBuyableCoinbasePayToken,
|
||||||
getIsBuyableTransakToken,
|
getIsBuyableTransakToken,
|
||||||
getIsBuyableMoonpayToken,
|
getIsBuyableMoonpayToken,
|
||||||
|
getIsBuyableWyreToken,
|
||||||
} from '../../../selectors/selectors';
|
} from '../../../selectors/selectors';
|
||||||
|
|
||||||
import BuyIcon from '../../ui/icon/overview-buy-icon.component';
|
import BuyIcon from '../../ui/icon/overview-buy-icon.component';
|
||||||
@ -63,8 +64,15 @@ const TokenOverview = ({ className, token }) => {
|
|||||||
const isTokenBuyableMoonpay = useSelector((state) =>
|
const isTokenBuyableMoonpay = useSelector((state) =>
|
||||||
getIsBuyableMoonpayToken(state, token.symbol),
|
getIsBuyableMoonpayToken(state, token.symbol),
|
||||||
);
|
);
|
||||||
|
const isTokenBuyableWyre = useSelector((state) =>
|
||||||
|
getIsBuyableWyreToken(state, token.symbol),
|
||||||
|
);
|
||||||
|
|
||||||
const isBuyable =
|
const isBuyable =
|
||||||
isTokenBuyableCoinbasePay || isTokenBuyableTransak || isTokenBuyableMoonpay;
|
isTokenBuyableCoinbasePay ||
|
||||||
|
isTokenBuyableTransak ||
|
||||||
|
isTokenBuyableMoonpay ||
|
||||||
|
isTokenBuyableWyre;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (token.isERC721 && process.env.COLLECTIBLES_V1) {
|
if (token.isERC721 && process.env.COLLECTIBLES_V1) {
|
||||||
|
@ -727,6 +727,13 @@ export function getIsBuyableMoonpayToken(state, symbol) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getIsBuyableWyreToken(state, symbol) {
|
||||||
|
const chainId = getCurrentChainId(state);
|
||||||
|
return Boolean(
|
||||||
|
BUYABLE_CHAINS_MAP?.[chainId]?.wyre?.currencies.includes(symbol),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function getIsBuyableMoonPayChain(state) {
|
export function getIsBuyableMoonPayChain(state) {
|
||||||
const chainId = getCurrentChainId(state);
|
const chainId = getCurrentChainId(state);
|
||||||
return Boolean(BUYABLE_CHAINS_MAP?.[chainId]?.moonPay);
|
return Boolean(BUYABLE_CHAINS_MAP?.[chainId]?.moonPay);
|
||||||
|
Loading…
Reference in New Issue
Block a user