Skip to content

Commit

Permalink
Add get claims, fix balance
Browse files Browse the repository at this point in the history
  • Loading branch information
faizov committed Mar 22, 2024
1 parent 4f97bf3 commit e5bf195
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/app/hooks/use-read-state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useReadState } from '.';
import { ENV } from '../сonsts';
import { useProgramMetadata } from './api';
import { useSendMessageHandler } from '@gear-js/react-hooks';
import { useMemo } from 'react';

export const programIdState = ENV.CONTRACT;
export const programIdAirdrop = ENV.AIRDROP;
Expand All @@ -19,10 +20,22 @@ export function useState() {
return { state };
}

export function useStateAirdrop() {
const payloadAllState = useMemo(() => ({ GetClaimers: null }), []);

const { state: claimers } = useReadState<any>({
programId: programIdAirdrop,
meta: metaAirdrop,
payload: payloadAllState,
});

return { claimers };
}

export function useStateMessage() {
const metadata = useProgramMetadata(metaAirdrop);
return useSendMessageHandler(programIdAirdrop, metadata, {
disableAlerts: true,
disableAlerts: false,
isMaxGasLimit: true,
});
}
4 changes: 2 additions & 2 deletions src/features/wallet/components/wallet/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useModal } from '@/hooks/use-modal';

import { AccountButton } from '../account-button';
import { WalletModal } from '../wallet-modal';
import { useState } from '@/app/hooks/use-read-state';
import { useState, useStateAirdrop } from '@/app/hooks/use-read-state';

import style from './wallet.module.scss'

Expand All @@ -19,7 +19,7 @@ function Wallet() {
{account ? (
<>
<div className={style.token}>
<h2>{state?.totalSupply}</h2>
<h2>{state?.balances.find((balance: any) => balance[0] === account.decodedAddress)[1]}</h2>
<h2>{state?.symbol}</h2>
</div>
<AccountButton color="dark" address={account.address} name={account.meta.name} onClick={openModal} />
Expand Down
22 changes: 20 additions & 2 deletions src/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
import { useStateMessage } from '@/app/hooks/use-read-state'
import { useStateAirdrop, useStateMessage } from '@/app/hooks/use-read-state'
import { Container } from '@/components'
import { useAccount } from '@gear-js/react-hooks'
import { Button } from '@gear-js/vara-ui'
import React from 'react'

export const Home = () => {
const { account } = useAccount()
const handleMessage = useStateMessage()
const { claimers } = useStateAirdrop()
const claimAccount = claimers?.Claimers.find((claimer: any) => claimer.address === account?.decodedAddress)

return (
<Container>
<Button text='Claim' onClick={() => handleMessage({ payload: { Claim: null } })} />
{claimAccount ?
<Button
disabled={!claimAccount}
text='Claim'
onClick={() => handleMessage({
payload: { Claim: null },
onSuccess: () => {

},
onError: () => {

}
})}
/> : <h1>Claim is not available</h1>
}
</Container>
)
}

0 comments on commit e5bf195

Please sign in to comment.