Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ST-346: add token to the assetlist after swap tx #398

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/txs/swap/TFMSwapForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import { SwapAssets, validateAssets } from "./useSwapUtils"
import { validateParams } from "./useSwapUtils"
import { calcMinimumReceive, SlippageParams } from "./SingleSwapContext"
import { useTFMSwap, validateTFMSlippageParams } from "./TFMSwapContext"
import { useCustomTokensCW20 } from "data/settings/CustomTokens"
import { useNativeDenoms } from "data/token"

interface TFMSwapParams extends SwapAssets {
amount: string
Expand All @@ -49,6 +51,10 @@ const TFMSwapForm = ({ chainID }: { chainID: string }) => {
const address = useAddress()
const { state } = useLocation()

// token whitelists
const cw20 = useCustomTokensCW20()
const readNativeDenom = useNativeDenoms()

/* swap context */
const { options, findTokenItem, findDecimals } = useTFMSwap()

Expand Down Expand Up @@ -202,14 +208,19 @@ const TFMSwapForm = ({ chainID }: { chainID: string }) => {
createTx,
queryKeys: [
queryKey.bank.balances,
...[offerAsset, askAsset]
.filter((asset) => asset && AccAddress.validate(asset))
.map((token) => [
queryKey.wasm.contractQuery,
token,
{ balance: address },
]),
queryKey.bank.balance,
queryKey.wasm.contractQuery,
],
onSuccess: () => {
if (askAsset && AccAddress.validate(askAsset)) {
const data = readNativeDenom(askAsset)
cw20.add({
...data,
token: askAsset,
name: data.name ?? data.symbol,
})
}
},
chain: chainID,
}

Expand Down