WUSDC flow (#197)
This commit is contained in:
parent
401789f349
commit
cc9d882ffe
|
@ -43,12 +43,10 @@ const WUSDC_MINT = new PublicKey(
|
|||
const USDC_MINT = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
||||
|
||||
const WUSDT_MINT = new PublicKey(
|
||||
'BQcdHdAQW1hczDbBi9hiegXAR7A98Q9jx3X3iBBBDiq4'
|
||||
'BQcdHdAQW1hczDbBi9hiegXAR7A98Q9jx3X3iBBBDiq4',
|
||||
);
|
||||
|
||||
const USDT_MINT = new PublicKey(
|
||||
'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB'
|
||||
);
|
||||
const USDT_MINT = new PublicKey('Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB');
|
||||
|
||||
export default function SendDialog({ open, onClose, publicKey, balanceInfo }) {
|
||||
const isProdNetwork = useIsProdNetwork();
|
||||
|
@ -68,40 +66,34 @@ export default function SendDialog({ open, onClose, publicKey, balanceInfo }) {
|
|||
if (mint?.equals(WUSDC_MINT)) {
|
||||
return [
|
||||
<Tab label="SPL WUSDC" key="spl" value="spl" />,
|
||||
<Tab
|
||||
label="SPL USDC"
|
||||
key="wusdcToSplUsdc"
|
||||
value="wusdcToSplUsdc"
|
||||
/>,
|
||||
<Tab label="SPL USDC" key="wusdcToSplUsdc" value="wusdcToSplUsdc" />,
|
||||
<Tab label="ERC20 USDC" key="swap" value="swap" />,
|
||||
]
|
||||
];
|
||||
} else if (mint?.equals(WUSDT_MINT)) {
|
||||
return [
|
||||
<Tab label="SPL WUSDT" key="spl" value="spl" />,
|
||||
<Tab
|
||||
label="SPL USDT"
|
||||
key="wusdtToSplUsdt"
|
||||
value="wusdtToSplUsdt"
|
||||
/>,
|
||||
<Tab label="SPL USDT" key="wusdtToSplUsdt" value="wusdtToSplUsdt" />,
|
||||
<Tab label="ERC20 USDT" key="swap" value="swap" />,
|
||||
]
|
||||
];
|
||||
} else if (localStorage.getItem('sollet-private') && mint?.equals(USDC_MINT)) {
|
||||
return [
|
||||
<Tab label="SPL USDC" key="spl" value="spl" />,
|
||||
<Tab label="SPL WUSDC" key="usdcToSplWUsdc" value="usdcToSplWUsdc" />,
|
||||
<Tab label="ERC20 USDC" key="swap" value="swap" />,
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
<Tab label={`SPL ${swapCoinInfo.ticker}`} key="spl" value="spl" />,
|
||||
<Tab
|
||||
label={`SPL ${swapCoinInfo.ticker}`}
|
||||
key="spl"
|
||||
value="spl"
|
||||
/>,
|
||||
<Tab
|
||||
label={`${
|
||||
swapCoinInfo.erc20Contract ? 'ERC20' : 'Native'
|
||||
} ${swapCoinInfo.ticker}`}
|
||||
label={`${swapCoinInfo.erc20Contract ? 'ERC20' : 'Native'} ${
|
||||
swapCoinInfo.ticker
|
||||
}`}
|
||||
key="swap"
|
||||
value="swap"
|
||||
/>,
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -160,6 +152,16 @@ export default function SendDialog({ open, onClose, publicKey, balanceInfo }) {
|
|||
onSubmitRef={onSubmitRef}
|
||||
wusdtToSplUsdt
|
||||
/>
|
||||
) : tab === 'usdcToSplWUsdc' ? (
|
||||
<SendSwapDialog
|
||||
key={tab}
|
||||
onClose={onClose}
|
||||
publicKey={publicKey}
|
||||
balanceInfo={balanceInfo}
|
||||
swapCoinInfo={swapCoinInfo}
|
||||
onSubmitRef={onSubmitRef}
|
||||
usdcToSplWUsdc
|
||||
/>
|
||||
) : (
|
||||
<SendSwapDialog
|
||||
key={tab}
|
||||
|
@ -310,6 +312,7 @@ function SendSwapDialog({
|
|||
ethAccount,
|
||||
wusdcToSplUsdc = false,
|
||||
wusdtToSplUsdt = false,
|
||||
usdcToSplWUsdc = false,
|
||||
onSubmitRef,
|
||||
}) {
|
||||
const wallet = useWallet();
|
||||
|
@ -324,11 +327,12 @@ function SendSwapDialog({
|
|||
} = useForm(balanceInfo);
|
||||
|
||||
const { tokenName, decimals, mint } = balanceInfo;
|
||||
const blockchain = wusdcToSplUsdc || wusdtToSplUsdt
|
||||
? 'sol'
|
||||
: swapCoinInfo.blockchain === 'sol'
|
||||
? 'eth'
|
||||
: swapCoinInfo.blockchain;
|
||||
const blockchain =
|
||||
wusdcToSplUsdc || wusdtToSplUsdt || usdcToSplWUsdc
|
||||
? 'sol'
|
||||
: swapCoinInfo.blockchain === 'sol'
|
||||
? 'eth'
|
||||
: swapCoinInfo.blockchain;
|
||||
const needMetamask = blockchain === 'eth';
|
||||
|
||||
const [ethBalance] = useAsyncData(
|
||||
|
@ -362,13 +366,26 @@ function SendSwapDialog({
|
|||
let splUsdtWalletAddress = useWalletAddressForMint(
|
||||
wusdtToSplUsdt ? USDT_MINT : null,
|
||||
);
|
||||
let splWUsdcWalletAddress = useWalletAddressForMint(
|
||||
usdcToSplWUsdc ? WUSDC_MINT : null,
|
||||
);
|
||||
useEffect(() => {
|
||||
if (wusdcToSplUsdc && splUsdcWalletAddress) {
|
||||
setDestinationAddress(splUsdcWalletAddress);
|
||||
} else if (wusdtToSplUsdt && splUsdtWalletAddress) {
|
||||
setDestinationAddress(splUsdtWalletAddress);
|
||||
} else if (usdcToSplWUsdc && splWUsdcWalletAddress) {
|
||||
setDestinationAddress(splWUsdcWalletAddress);
|
||||
}
|
||||
}, [setDestinationAddress, wusdcToSplUsdc, splUsdcWalletAddress, wusdtToSplUsdt, splUsdtWalletAddress]);
|
||||
}, [
|
||||
setDestinationAddress,
|
||||
wusdcToSplUsdc,
|
||||
splUsdcWalletAddress,
|
||||
wusdtToSplUsdt,
|
||||
splUsdtWalletAddress,
|
||||
usdcToSplWUsdc,
|
||||
splWUsdcWalletAddress,
|
||||
]);
|
||||
|
||||
async function makeTransaction() {
|
||||
let amount = Math.round(parseFloat(transferAmountString) * 10 ** decimals);
|
||||
|
@ -387,6 +404,11 @@ function SendSwapDialog({
|
|||
}
|
||||
if (mint?.equals(WUSDC_MINT)) {
|
||||
params.wusdcToUsdc = true;
|
||||
} else if (mint?.equals(USDC_MINT)) {
|
||||
if (usdcToSplWUsdc) {
|
||||
params.usdcToWUsdc = true;
|
||||
params.coin = WUSDC_MINT.toString();
|
||||
}
|
||||
} else if (mint?.equals(WUSDT_MINT)) {
|
||||
params.wusdtToUsdt = true;
|
||||
}
|
||||
|
@ -399,6 +421,7 @@ function SendSwapDialog({
|
|||
new PublicKey(swapInfo.address),
|
||||
amount,
|
||||
balanceInfo.mint,
|
||||
decimals,
|
||||
swapInfo.memo,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ export async function swapApiRequest(
|
|||
headers['Content-Type'] = 'application/json';
|
||||
params.body = JSON.stringify(body);
|
||||
}
|
||||
|
||||
let resp = await fetch(`https://swap.sollet.io/api/${path}`, params);
|
||||
return await handleSwapApiResponse(resp, ignoreUserErrors);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue