28c53b1e59
* keplr/metamask integration initial commit * chains settings and type definitions. notifications prototype * fix: dom nested buttons * address copied toast * react-toastify colors * wallet store and initial queries setup. zustand and react query dependencies added * _app code cleanup * remove obsolete WalletContext * unused import * walletStore initial commit * leftover component reference removed * fix: react hydration mismatch wallet component * metamask conditional click handler * connect modal minor tweaks and wallet installation urls added
38 lines
765 B
TypeScript
38 lines
765 B
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import BigNumber from "bignumber.js";
|
|
|
|
import useWalletStore from "stores/useWalletStore";
|
|
|
|
type Result = {
|
|
balance: {
|
|
amount: number;
|
|
denom: string;
|
|
};
|
|
};
|
|
|
|
const useAllBalances = () => {
|
|
const address = useWalletStore((state) => state.address);
|
|
|
|
const result = useQuery<Result>(
|
|
["injectiveBalance"],
|
|
async () =>
|
|
fetch(
|
|
`https://lcd.injective.network/cosmos/bank/v1beta1/balances/${address}/by_denom?denom=inj`
|
|
).then((res) => res.json()),
|
|
{
|
|
enabled: !!address,
|
|
}
|
|
);
|
|
|
|
return {
|
|
...result,
|
|
data:
|
|
result?.data &&
|
|
BigNumber(result.data.balance.amount)
|
|
.div(10 ** 18)
|
|
.toNumber(),
|
|
};
|
|
};
|
|
|
|
export default useAllBalances;
|