Skip to content

Commit c96bb8d

Browse files
committed
wip
1 parent 19c7b1b commit c96bb8d

18 files changed

Lines changed: 101 additions & 87 deletions

File tree

src/constants/dezswap.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ export const contractAddresses: {
8585
play3List: "",
8686
},
8787
};
88+
export const GAS_INFO = {
89+
multiplier: 1.4,
90+
gasPrice: {
91+
amount: new Decimal("850000000000"),
92+
denom: "axpla",
93+
},
94+
};
95+
8896
export const getGasInfo = (chainName: string) => {
8997
if (chainName === "fetchhub")
9098
return {

src/constants/network.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export type Network = {
55

66
export const XPLA_ADDRESS = "axpla";
77

8+
export const XPLA_SYMBOL = "XPLA";
9+
810
export const IBC_PREFIX = 4;
911

1012
const networks: Record<string, Network> = {

src/hooks/useAPI.ts

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -142,31 +142,28 @@ const useAPI = (version: ApiVersion = "v1") => {
142142
return res.block?.header.height ?? ("0" as unknown as string);
143143
}, [client]);
144144

145-
// unused func
146-
// const getDecimal = useCallback(
147-
// async (denom: string) => {
148-
// const contractAddress = contractAddresses[chainName]?.factory;
149-
// if (!contractAddress || !denom) {
150-
// return undefined;
151-
// }
152-
153-
// const queryData = toBase64(
154-
// toUtf8(
155-
// JSON.stringify({
156-
// native_token_decimals: { denom },
157-
// }),
158-
// ),
159-
// )
160-
161-
// const { data: res } = await client.cosmwasm.wasm.v1.smartContractState({
162-
// address: contractAddress,
163-
// queryData,
164-
// });
165-
// const tokenDecimals = parseJsonFromBinary(res) as unknown as Decimal;
166-
// return tokenDecimals.decimals;
167-
// },
168-
// [chainName, client],
169-
// );
145+
const getDecimal = useCallback(
146+
async (denom: string) => {
147+
const contractAddress = contractAddresses[chainName]?.factory;
148+
if (!contractAddress || !denom || !client) {
149+
return undefined;
150+
}
151+
152+
const queryData = toUtf8({
153+
native_token_decimals: { denom },
154+
});
155+
156+
const { data: res } = await client.cosmwasm.wasm.v1.smartContractState({
157+
address: contractAddress,
158+
queryData,
159+
});
160+
const tokenDecimals = parseJsonFromUtf8(res) as unknown as {
161+
decimals: number;
162+
};
163+
return tokenDecimals.decimals;
164+
},
165+
[chainName, client],
166+
);
170167

171168
const getLockdropEvents = useCallback(
172169
async (startAfter = 0) => {
@@ -334,7 +331,7 @@ const useAPI = (version: ApiVersion = "v1") => {
334331
getVerifiedTokenInfos,
335332
getVerifiedIbcTokenInfos,
336333
getLatestBlockHeight,
337-
// getDecimal,
334+
getDecimal,
338335
getLockdropEvents,
339336
getLockdropEventInfo,
340337
getLockdropUserInfo,
@@ -354,7 +351,7 @@ const useAPI = (version: ApiVersion = "v1") => {
354351
getVerifiedTokenInfos,
355352
getVerifiedIbcTokenInfos,
356353
getLatestBlockHeight,
357-
// getDecimal,
354+
getDecimal,
358355
getLockdropEvents,
359356
getLockdropEventInfo,
360357
getLockdropUserInfo,

src/hooks/useAuthSequence.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ import { useQuery } from "@tanstack/react-query";
22
import { useMemo } from "react";
33

44
import useAPI from "./useAPI";
5-
import useConnectedWallet from "./useConnectedWallet";
5+
import { useConnectedWallet } from "./useConnectedWallet";
66
import useNetwork from "./useNetwork";
7-
import useSigningClient from "./useSigningClient";
87

98
function useAuthSequence() {
109
const api = useAPI();
11-
const { signingClient: client } = useSigningClient();
12-
const { walletAddress } = useConnectedWallet();
10+
const connectedWallet = useConnectedWallet();
11+
const walletAddress = connectedWallet?.walletAddress;
1312
const { chainName } = useNetwork();
1413
const isXpla = useMemo(() => chainName.includes("xpla"), [chainName]);
1514

1615
const { data: sequence, isLoading } = useQuery({
17-
queryKey: ["authSequence", walletAddress, chainName, isXpla, !!client],
16+
queryKey: ["authSequence", walletAddress, chainName, isXpla],
1817
queryFn: async (): Promise<bigint> => {
1918
if (!walletAddress || !chainName) {
2019
throw new Error("Wallet address or chain name is not available");

src/hooks/useBalanceMinusFee.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const useBalanceMinusFee = (address?: string, feeAmount?: string) => {
1414
useEffect(() => {
1515
if (balance) {
1616
if (
17-
address === selectedChain.fees.feeTokens[0].denom &&
17+
address === selectedChain.fees?.feeTokens[0]?.denom &&
1818
feeAmount !== undefined
1919
) {
2020
const res = Numeric.parse(amountToValue(balance) || 0).minus(
@@ -28,7 +28,7 @@ const useBalanceMinusFee = (address?: string, feeAmount?: string) => {
2828
setBalanceMinusFee("0");
2929
}
3030
// eslint-disable-next-line react-hooks/exhaustive-deps
31-
}, [balance, feeAmount, selectedChain.fees.feeTokens[0].denom]);
31+
}, [balance, feeAmount, selectedChain.fees?.feeTokens[0]?.denom]);
3232

3333
return useMemo(() => {
3434
return balanceMinusFee;

src/hooks/useCustomAssets.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ import { AccAddress } from "@xpla/xpla.js";
22
import { useAtom } from "jotai";
33
import { useCallback, useEffect, useMemo, useRef } from "react";
44

5-
import { nativeTokens } from "~/constants/network";
6-
5+
import useNativeTokens from "~/hooks/useNativeTokens";
76
import useNetwork from "~/hooks/useNetwork";
87

98
import { customAssetsAtom } from "~/stores/assets";
109

1110
import { Token } from "~/types/api";
1211
import { TokenInfo } from "~/types/token";
1312

14-
import { getIbcTokenHash, isNativeTokenAddress } from "~/utils";
13+
import { getIbcTokenHash, isNativeToken } from "~/utils";
1514
import { parseJsonFromUtf8, toUtf8 } from "~/utils/encode";
1615

1716
import usePairs from "./usePairs";
@@ -28,8 +27,9 @@ const useCustomAssets = () => {
2827
const { client } = useRPCClient();
2928
const {
3029
chainName,
31-
selectedChain: { chainId },
30+
selectedChain: { chainId, bech32Prefix },
3231
} = useNetwork();
32+
const { nativeTokens } = useNativeTokens();
3333
const fetchQueue = useRef<{ [K in string]?: AccAddress[] }>({
3434
xpla: [],
3535
xplatestnet: [],
@@ -51,8 +51,8 @@ const useCustomAssets = () => {
5151
Date.now() - UPDATE_INTERVAL_SEC &&
5252
window.navigator.onLine
5353
) {
54-
if (isNativeTokenAddress(chainName, address)) {
55-
const asset = nativeTokens[chainName]?.find(
54+
if (isNativeToken(address, bech32Prefix ?? "")) {
55+
const asset = nativeTokens?.find(
5656
(item) => item.token === address,
5757
);
5858
if (asset) {
@@ -140,6 +140,8 @@ const useCustomAssets = () => {
140140
}, [
141141
chainName,
142142
chainId,
143+
bech32Prefix,
144+
nativeTokens,
143145
customAssetStore,
144146
verifiedIbcAssets,
145147
setCustomAssetStore,
@@ -150,7 +152,7 @@ const useCustomAssets = () => {
150152
const addFetchQueue = useCallback(
151153
(address: string, networkName: string) => {
152154
if (
153-
nativeTokens[networkName]?.some((item) => item.token === address) ||
155+
nativeTokens?.some((item) => item.token === address) ||
154156
AccAddress.validate(address) ||
155157
(verifiedIbcAssets && verifiedIbcAssets?.[getIbcTokenHash(address)])
156158
) {

src/hooks/useNativeTokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function useNativeTokens() {
1010
const { data: nativeTokens, isLoading: isNativeTokensLoading } = useQuery({
1111
queryKey: ["nativeTokens", chainName],
1212
queryFn: () => {
13-
return api.getNativeToken(selectedChain.bech32Prefix);
13+
return api.getNativeToken(selectedChain.bech32Prefix ?? "");
1414
},
1515
enabled: !!chainName && !api.isLoading,
1616
refetchOnReconnect: true,

src/pages/Earn/ImportAssetModal.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import {
2020
MOBILE_SCREEN_CLASS,
2121
MODAL_CLOSE_TIMEOUT_MS,
2222
} from "~/constants/layout";
23-
import { nativeTokens } from "~/constants/network";
2423

2524
import useAPI from "~/hooks/useAPI";
2625
import useBalance from "~/hooks/useBalance";
2726
import useCustomAssets from "~/hooks/useCustomAssets";
27+
import useNativeTokens from "~/hooks/useNativeTokens";
2828
import useNetwork from "~/hooks/useNetwork";
2929
import usePairs from "~/hooks/usePairs";
3030
import useRPCClient from "~/hooks/useRPCClient";
@@ -33,7 +33,7 @@ import useVerifiedAssets from "~/hooks/useVerifiedAssets";
3333
import { Token } from "~/types/api";
3434
import { TokenInfo } from "~/types/token";
3535

36-
import { getIbcTokenHash, isNativeTokenAddress } from "~/utils";
36+
import { isNativeToken as checkIsNativeToken, getIbcTokenHash } from "~/utils";
3737
import { parseJsonFromUtf8, toUtf8 } from "~/utils/encode";
3838

3939
interface ImportAssetModalProps extends ReactModal.Props {
@@ -49,8 +49,10 @@ function ImportAssetModal({ onFinish, ...modalProps }: ImportAssetModalProps) {
4949
const { availableAssetAddresses } = usePairs();
5050
const { verifiedAssets, verifiedIbcAssets } = useVerifiedAssets();
5151
const {
52-
selectedChain: { chainName, chainId },
52+
chainName,
53+
selectedChain: { chainId, bech32Prefix },
5354
} = useNetwork();
55+
const { nativeTokens } = useNativeTokens();
5456
const { client } = useRPCClient();
5557

5658
const api = useAPI();
@@ -59,8 +61,8 @@ function ImportAssetModal({ onFinish, ...modalProps }: ImportAssetModalProps) {
5961
const deferredAddress = useDeferredValue(address);
6062
const [tokenInfo, setTokenInfo] = useState<TokenInfo>();
6163
const isNativeToken = useMemo(
62-
() => isNativeTokenAddress(chainName, address),
63-
[chainName, address],
64+
() => checkIsNativeToken(address, bech32Prefix ?? ""),
65+
[bech32Prefix, address],
6466
);
6567
const isIbcToken = useMemo(
6668
() => verifiedIbcAssets?.[getIbcTokenHash(address)] !== undefined,
@@ -104,7 +106,7 @@ function ImportAssetModal({ onFinish, ...modalProps }: ImportAssetModalProps) {
104106
let isAborted = false;
105107
const fetchAsset = async () => {
106108
if (isNativeToken) {
107-
const asset = nativeTokens[chainName]?.find(
109+
const asset = nativeTokens?.find(
108110
(item) => item.token === deferredAddress,
109111
);
110112
if (!isAborted && asset) {
@@ -155,6 +157,7 @@ function ImportAssetModal({ onFinish, ...modalProps }: ImportAssetModalProps) {
155157
isNativeToken,
156158
isIbcToken,
157159
verifiedIbcAssets,
160+
nativeTokens,
158161
chainName,
159162
client,
160163
address,

src/pages/Earn/Lockdrop/Cancel/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function CancelPage() {
6464
selectedChain: { chainId, explorers },
6565
} = useNetwork();
6666
const { walletAddress } = useConnectedWallet() ?? {};
67-
const { getAsset } = useAssets();
67+
const { assetInfos } = useAssets();
6868
const { findPairByLpAddress } = usePairs();
6969
const { getLockdropEventInfo } = useLockdropEvents();
7070

@@ -114,8 +114,8 @@ function CancelPage() {
114114
);
115115

116116
const [asset1, asset2] = useMemo(
117-
() => pair?.asset_addresses.map((address) => getAsset(address)) || [],
118-
[getAsset, pair],
117+
() => pair?.asset_addresses.map((address) => assetInfos?.[address]) || [],
118+
[assetInfos, pair],
119119
);
120120

121121
const lockupInfo = useMemo(() => {
@@ -127,9 +127,9 @@ function CancelPage() {
127127
const rewardAsset = useMemo(
128128
() =>
129129
lockdropEventInfo
130-
? getAsset(lockdropEventInfo.reward_token_addr)
130+
? assetInfos?.[lockdropEventInfo.reward_token_addr]
131131
: undefined,
132-
[getAsset, lockdropEventInfo],
132+
[assetInfos, lockdropEventInfo],
133133
);
134134

135135
const cancelLockdropMsg = useMemo(() => {

src/pages/Earn/Lockdrop/Claim/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function ClaimPage() {
6666
const api = useAPI();
6767

6868
const { findPairByLpAddress } = usePairs();
69-
const { getAsset } = useAssets();
69+
const { assetInfos } = useAssets();
7070

7171
const { data: lockdropEventInfo, error: lockdropEventInfoError } = useQuery({
7272
queryKey: ["lockdropEventInfo", eventAddress, chainId],
@@ -110,13 +110,13 @@ function ClaimPage() {
110110
}, [duration, lockdropUserInfo]);
111111

112112
const [asset1, asset2] = useMemo(
113-
() => pair?.asset_addresses.map((address) => getAsset(address)) || [],
114-
[getAsset, pair],
113+
() => pair?.asset_addresses.map((address) => assetInfos?.[address]) || [],
114+
[assetInfos, pair],
115115
);
116116

117117
const rewardAsset = useMemo(
118-
() => getAsset(lockdropEventInfo?.reward_token_addr || ""),
119-
[getAsset, lockdropEventInfo],
118+
() => assetInfos?.[lockdropEventInfo?.reward_token_addr || ""],
119+
[assetInfos, lockdropEventInfo],
120120
);
121121

122122
const claimLockdropMsg = useMemo(() => {

0 commit comments

Comments
 (0)