Skip to content

Commit

Permalink
Add sFUEL check to rewards claim
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrotkk committed Nov 20, 2024
1 parent dd91951 commit 9e05b7b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/components/delegation/ChainRewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
walletClientToSigner,
sendTransaction,
styles,
SkPaper
SkPaper,
Station
} from '@skalenetwork/metaport'
import { types } from '@/core'

Expand Down Expand Up @@ -62,8 +63,8 @@ import { getExplorerUrlForAddress } from '../../core/explorer'
interface ChainRewardsProps {
mpc: MetaportCore
validator: types.staking.IValidator | null | undefined
address?: string
customAddress?: string
address?: types.AddressType
customAddress?: types.AddressType
className?: string
isXs?: boolean
}
Expand Down Expand Up @@ -124,14 +125,25 @@ const ChainRewards: React.FC<ChainRewardsProps> = ({
}

async function retrieveRewards() {
if (!paymaster.runner?.provider || !walletClient || !switchChainAsync) {
if (!paymaster.runner?.provider || !walletClient || !switchChainAsync || !address) {
setErrorMsg('Something is wrong with your wallet, try again')
return
}
setLoading(true)
setBtnText(`Switching network`)
setBtnText('Switching network')
setErrorMsg(undefined)
try {
const sFuelBalance = await paymaster.runner.provider.getBalance(address)
if (sFuelBalance === 0n) {
setBtnText('Mining sFUEL')
const station = new Station(paymasterChain, mpc)
const powResult = await station.doPoW(address)
if (!powResult.ok) {
setErrorMsg('Failed to mine sFUEL')
return
}
}

const { chainId } = await paymaster.runner.provider.getNetwork()
const paymasterAddress = getPaymasterAddress(network)

Expand Down

0 comments on commit 9e05b7b

Please sign in to comment.