Skip to content

Commit

Permalink
Bugfix/swap mints (#457)
Browse files Browse the repository at this point in the history
* Fix swaps

* allow only the right mints to be selected

* remove dc from output options
  • Loading branch information
bryzettler authored Sep 12, 2023
1 parent 207b517 commit 2894b2f
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/features/swaps/SwapScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,22 +260,25 @@ const SwapScreen = () => {
[refresh, selectorMode, youReceiveMint],
)

const validYouReceiveMints = useMemo(() => {
if (youPayMint.equals(HNT_MINT)) return [DC_MINT]
return [HNT_MINT]
}, [youPayMint])

const tokenData = useMemo(() => {
const tokens = {
[SelectorMode.youPay]: [MOBILE_MINT, HNT_MINT, IOT_MINT].map((mint) => ({
mint,
selected: youPayMint.equals(mint),
})),
[SelectorMode.youReceive]: [MOBILE_MINT, HNT_MINT, IOT_MINT].map(
(mint) => ({
mint,
selected: youReceiveMint.equals(mint),
}),
),
[SelectorMode.youReceive]: validYouReceiveMints.map((mint) => ({
mint,
selected: youReceiveMint.equals(mint),
})),
}

return tokens[selectorMode]
}, [selectorMode, youPayMint, youReceiveMint])
}, [selectorMode, youPayMint, youReceiveMint, validYouReceiveMints])

const onCurrencySelect = useCallback(
(youPay: boolean) => () => {
Expand Down Expand Up @@ -351,14 +354,16 @@ const SwapScreen = () => {
? new PublicKey(recipient)
: new PublicKey(currentAccount.solanaAddress)

if (youPayMint.equals(HNT_MINT) && youReceiveTokenAmount) {
if (
youPayMint.equals(HNT_MINT) &&
youReceiveMint.equals(DC_MINT) &&
youReceiveTokenAmount
) {
await submitMintDataCredits({
dcAmount: new BN(youReceiveTokenAmount),
recipient: recipientAddr,
})
}

if (!youPayMint.equals(HNT_MINT)) {
} else {
await submitTreasurySwap(youPayMint, youPayTokenAmount, recipientAddr)
}

Expand Down

0 comments on commit 2894b2f

Please sign in to comment.