Skip to content

Commit

Permalink
Refactor to return the jetton wallet contract (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharyakir authored Feb 19, 2023
1 parent 2751994 commit 176feb1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/hooks/useFaucetJettonContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ export function useFaucetJettonContract() {
return client.open(contract) as OpenedContract<FaucetJetton>;
}, [client, wallet]);

const jettonWalletAddress = useAsyncInitialize(async () => {
if (!faucetJettonContract) return;
return await faucetJettonContract!.getWalletAddress(Address.parse(wallet!));
}, [faucetJettonContract]);
const jwContract = useAsyncInitialize(async () => {
if (!faucetJettonContract || !client) return;
const jettonWalletAddress = await faucetJettonContract!.getWalletAddress(
Address.parse(wallet!)
);
return client!.open(
new FaucetJettonWallet(Address.parse(jettonWalletAddress))
) as OpenedContract<FaucetJettonWallet>;
}, [faucetJettonContract, client]);

const { data, isFetching } = useQuery(
["jetton"],
async () => {
if (!jettonWalletAddress || !client) return null;
const jwContract = new FaucetJettonWallet(
Address.parse(jettonWalletAddress)
);
return (await client!.open(jwContract).getBalance()).toString();
if (!jwContract) return null;

return (await jwContract.getBalance()).toString();
},
{ refetchInterval: 3000 }
);
Expand All @@ -39,7 +42,7 @@ export function useFaucetJettonContract() {
mint: () => {
faucetJettonContract?.sendMintFromFaucet(sender, Address.parse(wallet!));
},
jettonWalletAddress,
jettonWalletAddress: jwContract?.address.toString(),
balance: isFetching ? null : data,
};
}

1 comment on commit 176feb1

@nnrben
Copy link

@nnrben nnrben commented on 176feb1 Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Снимок экрана (22)
подскажи пожалуйста, где я туплю здесь?

Please sign in to comment.