Compare commits
2 Commits
main
...
fix-float-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
514a2d3ab3 | ||
|
|
c58d94e477 |
@ -48,7 +48,7 @@ export const useSubaccount = () => useContext(SubaccountContext);
|
|||||||
|
|
||||||
export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: LocalWallet }) => {
|
export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: LocalWallet }) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { usdcDenom } = useTokenConfigs();
|
const { usdcDenom, usdcDecimals } = useTokenConfigs();
|
||||||
const { compositeClient, faucetClient } = useDydxClient();
|
const { compositeClient, faucetClient } = useDydxClient();
|
||||||
|
|
||||||
const { getFaucetFunds } = useMemo(
|
const { getFaucetFunds } = useMemo(
|
||||||
@ -79,16 +79,34 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
|||||||
subaccountClient: SubaccountClient;
|
subaccountClient: SubaccountClient;
|
||||||
assetId?: number;
|
assetId?: number;
|
||||||
amount: number;
|
amount: number;
|
||||||
}) => await compositeClient?.depositToSubaccount(subaccountClient, amount.toString()),
|
}) => {
|
||||||
|
try {
|
||||||
|
return await compositeClient?.depositToSubaccount(
|
||||||
|
subaccountClient,
|
||||||
|
amount.toFixed(usdcDecimals)
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
log('useSubaccount/depositToSubaccount', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
withdrawFromSubaccount: async ({
|
withdrawFromSubaccount: async ({
|
||||||
subaccountClient,
|
subaccountClient,
|
||||||
amount,
|
amount,
|
||||||
}: {
|
}: {
|
||||||
subaccountClient: SubaccountClient;
|
subaccountClient: SubaccountClient;
|
||||||
amount: number;
|
amount: number;
|
||||||
}) => await compositeClient?.withdrawFromSubaccount(subaccountClient, amount.toString()),
|
}) => {
|
||||||
|
try {
|
||||||
|
return await compositeClient?.withdrawFromSubaccount(
|
||||||
|
subaccountClient,
|
||||||
|
amount.toFixed(usdcDecimals)
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
log('useSubaccount/withdrawFromSubaccount', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
transferFromSubaccountToAddress: async ({
|
transferFromSubaccountToAddress: async ({
|
||||||
subaccountClient,
|
subaccountClient,
|
||||||
assetId = 0,
|
assetId = 0,
|
||||||
@ -99,8 +117,9 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
|||||||
assetId?: number;
|
assetId?: number;
|
||||||
amount: number;
|
amount: number;
|
||||||
recipient: string;
|
recipient: string;
|
||||||
}) =>
|
}) => {
|
||||||
await compositeClient?.validatorClient.post.send(
|
try {
|
||||||
|
return await compositeClient?.validatorClient.post.send(
|
||||||
subaccountClient?.wallet,
|
subaccountClient?.wallet,
|
||||||
() =>
|
() =>
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
@ -119,7 +138,12 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
|||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
Method.BroadcastTxCommit
|
Method.BroadcastTxCommit
|
||||||
),
|
);
|
||||||
|
} catch (error) {
|
||||||
|
log('useSubaccount/transferFromSubaccountToAddress', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
transferNativeToken: async ({
|
transferNativeToken: async ({
|
||||||
subaccountClient,
|
subaccountClient,
|
||||||
@ -129,15 +153,16 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
|||||||
subaccountClient: SubaccountClient;
|
subaccountClient: SubaccountClient;
|
||||||
amount: number;
|
amount: number;
|
||||||
recipient: string;
|
recipient: string;
|
||||||
}) =>
|
}) => {
|
||||||
await compositeClient?.validatorClient.post.send(
|
try {
|
||||||
|
return await compositeClient?.validatorClient.post.send(
|
||||||
subaccountClient.wallet,
|
subaccountClient.wallet,
|
||||||
() =>
|
() =>
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
const msg = compositeClient?.sendTokenMessage(
|
const msg = compositeClient?.sendTokenMessage(
|
||||||
subaccountClient.wallet,
|
subaccountClient.wallet,
|
||||||
amount.toString(),
|
amount.toString(),
|
||||||
recipient,
|
recipient
|
||||||
);
|
);
|
||||||
|
|
||||||
resolve([msg]);
|
resolve([msg]);
|
||||||
@ -146,7 +171,12 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
|||||||
compositeClient?.validatorClient?.post.defaultDydxGasPrice,
|
compositeClient?.validatorClient?.post.defaultDydxGasPrice,
|
||||||
undefined,
|
undefined,
|
||||||
Method.BroadcastTxCommit
|
Method.BroadcastTxCommit
|
||||||
),
|
);
|
||||||
|
} catch (error) {
|
||||||
|
log('useSubaccount/transferNativeToken', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
sendSquidWithdrawFromSubaccount: async ({
|
sendSquidWithdrawFromSubaccount: async ({
|
||||||
subaccountClient,
|
subaccountClient,
|
||||||
@ -158,10 +188,13 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
|||||||
payload: string;
|
payload: string;
|
||||||
}) => {
|
}) => {
|
||||||
if (!compositeClient) throw new Error('client not initialized');
|
if (!compositeClient) throw new Error('client not initialized');
|
||||||
|
try {
|
||||||
const transaction = JSON.parse(payload);
|
const transaction = JSON.parse(payload);
|
||||||
|
|
||||||
const msg = compositeClient.withdrawFromSubaccountMessage(subaccountClient, amount.toString());
|
const msg = compositeClient.withdrawFromSubaccountMessage(
|
||||||
|
subaccountClient,
|
||||||
|
amount.toFixed(usdcDecimals)
|
||||||
|
);
|
||||||
const ibcMsg: EncodeObject = {
|
const ibcMsg: EncodeObject = {
|
||||||
typeUrl: transaction.msgTypeUrl,
|
typeUrl: transaction.msgTypeUrl,
|
||||||
value: transaction.msg,
|
value: transaction.msg,
|
||||||
@ -172,6 +205,10 @@ export const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: Lo
|
|||||||
() => Promise.resolve([msg, ibcMsg]),
|
() => Promise.resolve([msg, ibcMsg]),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
} catch (error) {
|
||||||
|
log('useSubaccount/sendSquidWithdrawFromSubaccount', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
[compositeClient]
|
[compositeClient]
|
||||||
|
|||||||
@ -19,8 +19,10 @@ export const useTokenConfigs = (): {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
usdcDenom: string;
|
usdcDenom: string;
|
||||||
|
usdcDecimals: number;
|
||||||
usdcLabel: string;
|
usdcLabel: string;
|
||||||
chainTokenDenom: string;
|
chainTokenDenom: string;
|
||||||
|
chainTokenDecimals: number;
|
||||||
chainTokenLabel: string;
|
chainTokenLabel: string;
|
||||||
} => {
|
} => {
|
||||||
const { selectedNetwork } = useSelectedNetwork();
|
const { selectedNetwork } = useSelectedNetwork();
|
||||||
@ -29,8 +31,10 @@ export const useTokenConfigs = (): {
|
|||||||
return {
|
return {
|
||||||
tokensConfigs,
|
tokensConfigs,
|
||||||
usdcDenom: tokensConfigs[DydxChainAsset.USDC].denom,
|
usdcDenom: tokensConfigs[DydxChainAsset.USDC].denom,
|
||||||
|
usdcDecimals: tokensConfigs[DydxChainAsset.USDC].decimals,
|
||||||
usdcLabel: tokensConfigs[DydxChainAsset.USDC].name,
|
usdcLabel: tokensConfigs[DydxChainAsset.USDC].name,
|
||||||
chainTokenDenom: tokensConfigs[DydxChainAsset.CHAINTOKEN].denom,
|
chainTokenDenom: tokensConfigs[DydxChainAsset.CHAINTOKEN].denom,
|
||||||
|
chainTokenDecimals: tokensConfigs[DydxChainAsset.CHAINTOKEN].decimals,
|
||||||
chainTokenLabel: tokensConfigs[DydxChainAsset.CHAINTOKEN].name,
|
chainTokenLabel: tokensConfigs[DydxChainAsset.CHAINTOKEN].name,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user