Skip to content

Commit

Permalink
remove useless check
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwbabylonlab committed Dec 3, 2024
1 parent 27a56b5 commit 5152a67
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
10 changes: 5 additions & 5 deletions src/app/hooks/client/query/useBbnQueryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useCosmosWallet } from "@/app/context/wallet/CosmosWalletProvider";
* interacting with Babylon RPC nodes
*/
export const useBbnQueryClient = () => {
const { bech32Address } = useCosmosWallet();
const { bech32Address, connected } = useCosmosWallet();
const [queryClient, setQueryClient] = useState<QueryClient>();

useEffect(() => {
Expand All @@ -35,7 +35,7 @@ export const useBbnQueryClient = () => {
const getRewards = useCallback(async (): Promise<
incentivequery.QueryRewardGaugesResponse | undefined
> => {
if (!queryClient || !bech32Address) {
if (!connected || !queryClient || !bech32Address) {
return undefined;
}
const { incentive } = setupIncentiveExtension(queryClient);
Expand All @@ -46,17 +46,17 @@ export const useBbnQueryClient = () => {
});

return incentive.RewardGauges(req);
}, [queryClient, bech32Address]);
}, [connected, queryClient, bech32Address]);

const getBalance = useCallback(async (): Promise<number> => {
if (!queryClient || !bech32Address) {
if (!connected || !queryClient || !bech32Address) {
return 0;
}

const { bank } = setupBankExtension(queryClient);
const balance = await bank.balance(bech32Address, "ubbn");
return Number(balance?.amount ?? 0);
}, [queryClient, bech32Address]);
}, [connected, queryClient, bech32Address]);

return {
getRewards,
Expand Down
23 changes: 4 additions & 19 deletions src/app/hooks/services/useRewardsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import { useBbnTransaction } from "../client/query/useBbnTransaction";
const REWARD_GAUGE_KEY_BTC_DELEGATION = "btc_delegation";

export const useRewardsService = () => {
const {
connected: cosmosConnected,
bech32Address,
signingStargateClient,
} = useCosmosWallet();
const { bech32Address } = useCosmosWallet();

const { getRewards: getBbnRewards } = useBbnQueryClient();
const { estimateBbnGasFee, sendBbnTx } = useBbnTransaction();
Expand All @@ -24,9 +20,6 @@ export const useRewardsService = () => {
* @returns {Promise<number>} The rewards from the user's account.
*/
const getRewards = useCallback(async (): Promise<number> => {
if (!cosmosConnected || !bech32Address || !signingStargateClient) {
return 0;
}
const rewards = await getBbnRewards();
if (!rewards) {
return 0;
Expand All @@ -45,35 +38,27 @@ export const useRewardsService = () => {
coins.reduce((acc, coin) => acc + Number(coin.amount), 0) -
(withdrawnCoins || 0)
);
}, [cosmosConnected, bech32Address, signingStargateClient, getBbnRewards]);
}, [getBbnRewards]);

/**
* Estimates the gas fee for claiming rewards.
* @returns {Promise<number>} The gas fee for claiming rewards.
*/
const estimateClaimRewardsGas = useCallback(async (): Promise<number> => {
if (!signingStargateClient || !bech32Address) {
return 0;
}

const withdrawRewardMsg = createWithdrawRewardMsg(bech32Address);

const gasFee = await estimateBbnGasFee(withdrawRewardMsg);
return gasFee.amount.reduce((acc, coin) => acc + Number(coin.amount), 0);
}, [signingStargateClient, bech32Address, estimateBbnGasFee]);
}, [bech32Address, estimateBbnGasFee]);

/**
* Claims the rewards from the user's account.
*/
const claimRewards = useCallback(async () => {
if (!signingStargateClient || !bech32Address) {
return;
}

const msg = createWithdrawRewardMsg(bech32Address);

await sendBbnTx(msg);
}, [bech32Address, signingStargateClient, sendBbnTx]);
}, [bech32Address, sendBbnTx]);

return {
getRewards,
Expand Down

0 comments on commit 5152a67

Please sign in to comment.