Skip to content

Commit

Permalink
🚸 Query for send NFT tx before posting (#189)
Browse files Browse the repository at this point in the history
* 🚸 Query for send NFT tx before posting

* Update utils/cosmos.ts

Co-authored-by: Ng Wing Tat, David <[email protected]>

---------

Co-authored-by: Ng Wing Tat, David <[email protected]>
  • Loading branch information
williamchong and nwingt authored Sep 12, 2024
1 parent eab1de8 commit 90c9378
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion utils/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parseAndCalculateStakeholderRewards } from '@likecoin/iscn-js/dist/iscn
import { MsgSend } from 'cosmjs-types/cosmos/nft/v1beta1/tx'
import { DeliverTxResponse } from '@cosmjs/stargate'
import { PageRequest } from 'cosmjs-types/cosmos/base/query/v1beta1/pagination'
import { parseAuthzGrant } from '@likecoin/iscn-js/dist/messages/parsing'
import { parseAuthzGrant, parseTxInfoFromIndexedTx } from '@likecoin/iscn-js/dist/messages/parsing'
import { GenericAuthorization } from 'cosmjs-types/cosmos/authz/v1beta1/authz'
import { formatMsgSend } from '@likecoin/iscn-js/dist/messages/likenft'
import { addParamToUrl } from '.'
Expand Down Expand Up @@ -54,6 +54,16 @@ export function getGasFee (count: number) {
}
}

export async function queryTxByHash (txHash: string) {
const client = await (await getSigningClient()).getISCNQueryClient().getStargateClient()
const tx = await client.getTx(txHash)
if (!tx) { return null }
const { code } = tx
if (code) { throw new Error(`Tx failed with code: ${code}`) }
const parsed = parseTxInfoFromIndexedTx(tx)
return parsed
}

export async function queryISCNById (iscnId: string) {
const c = (await getSigningClient()).getISCNQueryClient()
const res = await c.queryRecordsById(iscnId)
Expand Down Expand Up @@ -382,5 +392,16 @@ export async function sendNFTsToAPIWallet (
if (!transactionHash || code !== 0) {
throw new Error('Failed to sign and send NFTs')
}

for (let tryCount = 0; tryCount < 3; tryCount++) {
await sleep(3000)
try {
const tx = await queryTxByHash(transactionHash)
if (tx) {
break
}
} catch {}
}

return transactionHash
}

0 comments on commit 90c9378

Please sign in to comment.