-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from hyperweb-io/fix-inj
Fix inj
- Loading branch information
Showing
6 changed files
with
885 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,44 @@ | ||
// import { useGetBalance } from 'interchainjs/cosmos/bank/v1beta1/query.rpc.func' | ||
import { useGetBalance } from 'injective-react/cosmos/bank/v1beta1/query.rpc.react'; | ||
import { defaultRpcEndpoint as rpcEndpoint } from '@/config'; | ||
// import { defaultContext } from '@tanstack/react-query' | ||
import BigNumber from "bignumber.js"; | ||
import { defaultAssetList } from "@/config"; | ||
import { createRpcQueryHooks, useRpcClient } from '../src/codegen'; | ||
|
||
export default function useBalance({ | ||
address, | ||
}:{ | ||
address: string, | ||
}) { | ||
import BigNumber from 'bignumber.js'; | ||
import { defaultAssetList } from '@/config'; | ||
import { defaultContext } from '@tanstack/react-query'; | ||
|
||
export default function useBalance({ address }: { address: string }) { | ||
const coin = defaultAssetList?.assets[0]; | ||
|
||
const denom = coin!.base! | ||
const denom = coin!.base!; | ||
|
||
const COIN_DISPLAY_EXPONENT = coin!.denomUnits.find( | ||
(unit) => unit.denom === coin!.display | ||
)?.exponent as number; | ||
|
||
const { data: rpcClient } = useRpcClient({ | ||
rpcEndpoint, | ||
options: { | ||
enabled: !!rpcEndpoint && !!address, | ||
}, | ||
}); | ||
|
||
const hooks = createRpcQueryHooks({ rpc: rpcClient }); | ||
|
||
const { | ||
data: balance, | ||
isSuccess: isBalanceLoaded, | ||
isLoading: isFetchingBalance, | ||
refetch: refetchBalance, | ||
} = hooks.useBalance({ | ||
} = useGetBalance({ | ||
request: { | ||
address: address || '', | ||
denom, | ||
}, | ||
options: { | ||
enabled: !!address && !!rpcClient, | ||
// transform the returned balance into a BigNumber | ||
context: defaultContext, | ||
enabled: !!address, | ||
select: ({ balance }) => | ||
new BigNumber(balance?.amount ?? 0).multipliedBy( | ||
10 ** -COIN_DISPLAY_EXPONENT | ||
), | ||
} | ||
staleTime: 0, | ||
}, | ||
clientResolver: rpcEndpoint, | ||
}); | ||
|
||
return { | ||
balance, | ||
isBalanceLoaded, | ||
isFetchingBalance, | ||
refetchBalance, | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useChain } from '@interchain-kit/react'; | ||
import { defaultContext, useQuery } from '@tanstack/react-query'; | ||
|
||
import { DEFAULT_SIGNING_CLIENT_QUERY_KEY } from 'injective-react/react-query'; | ||
import { WalletState } from '@interchain-kit/core'; | ||
|
||
export enum TxStatus { | ||
Failed = 'Transaction Failed', | ||
Successful = 'Transaction Successful', | ||
Broadcasting = 'Transaction Broadcasting', | ||
} | ||
|
||
export const useSigningClient = ( | ||
chainName: string, | ||
options: { | ||
walletStatus?: WalletState; | ||
} | ||
) => { | ||
const { getSigningClient } = useChain(chainName); | ||
|
||
return useQuery( | ||
[DEFAULT_SIGNING_CLIENT_QUERY_KEY, chainName], | ||
async () => { | ||
const client = await getSigningClient(); | ||
return client; | ||
}, | ||
{ | ||
enabled: | ||
!!chainName && | ||
(!options || options?.walletStatus === WalletState.Connected), | ||
context: defaultContext, | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.