Skip to content

Commit

Permalink
update polling approach for claims (#2266)
Browse files Browse the repository at this point in the history
Co-authored-by: lllwvlvwlll <[email protected]>
  • Loading branch information
lllwvlvwlll and lllwvlvwlll authored Sep 25, 2021
1 parent 80ad898 commit 50c8e72
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions app/modules/claim.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import { api, type Claims } from '@cityofzion/neon-js'
import { api as apiLatest } from '@cityofzion/neon-js-legacy-latest'
import { api as apiLatest, rpc } from '@cityofzion/neon-js-legacy-latest'
import {
api as n3Api,
wallet as n3Wallet,
Expand Down Expand Up @@ -31,7 +31,7 @@ import { getNode, getRPCEndpoint } from '../actions/nodeStorageActions'
// Constants
export const DISABLE_CLAIM = 'DISABLE_CLAIM'
const POLL_ATTEMPTS = 30
const POLL_FREQUENCY = 10000
const POLL_FREQUENCY = 4000

// Actions
export function disableClaim(disableClaimButton: boolean) {
Expand Down Expand Up @@ -82,23 +82,18 @@ const updateClaimableAmount = async ({
throw new Error('Rejected by RPC server.')
}

return response.result.response
return response
}

const pollForUpdatedClaimableAmount = async ({
net,
address,
claimableAmount,
}) =>
const pollForUpdatedClaimableAmount = async ({ net, address, txid }) =>
poll(
async () => {
const updatedClaimableAmount = await getClaimableAmount({ net, address })

if (toBigNumber(updatedClaimableAmount).eq(claimableAmount)) {
throw new Error('Waiting for updated claims took too long.')
}
// watch the sendAsset txid until it has been published
const client = new rpc.RPCClient('https://mainnet2.neo2.coz.io:443')
await client.getRawTransaction(txid)

return updatedClaimableAmount
// get the new claimable amount
return getClaimableAmount({ net, address })
},
{ attempts: POLL_ATTEMPTS, frequency: POLL_FREQUENCY },
)
Expand All @@ -116,15 +111,15 @@ const getUpdatedClaimableAmount = async ({
if (toBigNumber(balance).eq(0)) {
return claimableAmount
}
await updateClaimableAmount({
const { txid } = await updateClaimableAmount({
net,
address,
balance,
publicKey,
privateKey,
signingFunction,
})
return pollForUpdatedClaimableAmount({ net, address, claimableAmount })
return pollForUpdatedClaimableAmount({ net, address, txid })
}

export const handleN3GasClaim = async ({
Expand Down

0 comments on commit 50c8e72

Please sign in to comment.