Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 27 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,41 @@
"@coral-xyz/anchor": "0.31.0",
"@gorhom/bottom-sheet": "5.1.2",
"@gorhom/portal": "1.0.14",
"@helium/account-fetch-cache": "0.11.4",
"@helium/account-fetch-cache-hooks": "0.11.4",
"@helium/account-fetch-cache": "0.11.14",
"@helium/account-fetch-cache-hooks": "0.11.14",
"@helium/address": "^5.0.4",
"@helium/automation-hooks": "^0.11.4",
"@helium/blockchain-api": "^0.3.12",
"@helium/circuit-breaker-sdk": "0.11.4",
"@helium/automation-hooks": "^0.11.14",
"@helium/blockchain-api": "^0.11.14",
"@helium/circuit-breaker-sdk": "0.11.14",
"@helium/cron-sdk": "^0.0.8",
"@helium/crypto-react-native": "^5.0.4",
"@helium/currency-utils": "0.11.4",
"@helium/data-credits-sdk": "0.11.4",
"@helium/distributor-oracle": "0.11.4",
"@helium/fanout-sdk": "0.11.4",
"@helium/helium-entity-manager-sdk": "0.11.4",
"@helium/helium-react-hooks": "0.11.4",
"@helium/helium-sub-daos-sdk": "0.11.4",
"@helium/hpl-crons-sdk": "^0.11.4",
"@helium/currency-utils": "0.11.14",
"@helium/data-credits-sdk": "0.11.14",
"@helium/distributor-oracle": "0.11.14",
"@helium/fanout-sdk": "0.11.14",
"@helium/helium-entity-manager-sdk": "0.11.14",
"@helium/helium-react-hooks": "0.11.14",
"@helium/helium-sub-daos-sdk": "0.11.14",
"@helium/hpl-crons-sdk": "^0.11.14",
"@helium/http": "^5.0.4",
"@helium/idls": "0.11.4",
"@helium/lazy-distributor-sdk": "0.11.4",
"@helium/idls": "0.11.14",
"@helium/lazy-distributor-sdk": "0.11.14",
"@helium/modular-governance-hooks": "0.1.5",
"@helium/modular-governance-idls": "0.1.5",
"@helium/no-emit-sdk": "0.11.4",
"@helium/no-emit-sdk": "0.11.14",
"@helium/onboarding": "^5.0.4",
"@helium/organization-sdk": "0.1.5",
"@helium/proto-ble": "^5.0.4",
"@helium/react-native-sdk": "^4.0.4",
"@helium/spl-utils": "0.11.4",
"@helium/spl-utils": "0.11.14",
"@helium/state-controller-sdk": "0.1.5",
"@helium/sus": "0.11.4",
"@helium/sus": "0.11.14",
"@helium/transactions": "^5.0.4",
"@helium/treasury-management-sdk": "0.11.4",
"@helium/treasury-management-sdk": "0.11.14",
"@helium/tuktuk-idls": "^0.0.8",
"@helium/tuktuk-sdk": "^0.0.8",
"@helium/voter-stake-registry-hooks": "0.11.4",
"@helium/voter-stake-registry-sdk": "0.11.4",
"@helium/voter-stake-registry-hooks": "0.11.14",
"@helium/voter-stake-registry-sdk": "0.11.14",
"@helium/wallet-link": "^5.0.4",
"@jup-ag/api": "6.0.6",
"@keystonehq/keystone-sdk": "0.11.7",
Expand Down Expand Up @@ -263,14 +263,14 @@
"@types/react": "^19.0.0",
"react": "19.0.0",
"@solana/wallet-adapter-react": "0.15.33",
"@helium/account-fetch-cache": "0.11.4",
"@helium/account-fetch-cache-hooks": "0.11.4",
"@helium/helium-react-hooks": "0.11.4",
"@helium/voter-stake-registry-hooks": "0.11.4",
"@helium/voter-stake-registry-sdk": "0.11.4",
"@helium/account-fetch-cache": "0.11.14",
"@helium/account-fetch-cache-hooks": "0.11.14",
"@helium/helium-react-hooks": "0.11.14",
"@helium/voter-stake-registry-hooks": "0.11.14",
"@helium/voter-stake-registry-sdk": "0.11.14",
"@helium/modular-governance-hooks": "0.1.5",
"@helium/onboarding": "^5.0.4",
"@keystonehq/bc-ur-registry": "0.7.1"
},
"packageManager": "yarn@4.9.2"
}
}
10 changes: 9 additions & 1 deletion src/features/payment/PaymentSubmitLoading.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, useCallback, useState } from 'react'
import React, { memo, useCallback, useEffect, useState } from 'react'
import { StyleSheet } from 'react-native'
import Video from 'react-native-video'
import videoSource from '@assets/videos/paymentSent.mp4'
Expand All @@ -13,6 +13,8 @@ type Props = {
onVideoEnd: () => void
}

const VIDEO_TIMEOUT_MS = 5000

const PaymentSubmitLoading = ({ onVideoEnd }: Props) => {
const { t } = useTranslation()
const [videoEnded, setVideoEnded] = useState(false)
Expand All @@ -22,6 +24,12 @@ const PaymentSubmitLoading = ({ onVideoEnd }: Props) => {
onVideoEnd()
}, [onVideoEnd])

// Fallback timeout in case video onEnd never fires
useEffect(() => {
const timer = setTimeout(handleVideoEnded, VIDEO_TIMEOUT_MS)
return () => clearTimeout(timer)
}, [handleVideoEnded])

return (
<>
<Box style={StyleSheet.absoluteFill} justifyContent="center">
Expand Down
62 changes: 18 additions & 44 deletions src/hooks/useImplicitBurn.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import { Program } from '@coral-xyz/anchor'
import {
init as initDataCredits,
mintDataCredits,
} from '@helium/data-credits-sdk'
import { useOwnedAmount } from '@helium/helium-react-hooks'
import { DataCredits } from '@helium/idls/lib/types/data_credits'
import { DC_MINT } from '@helium/spl-utils'
import { useCurrentWallet } from '@hooks/useCurrentWallet'
import { useSubmitAndAwait } from '@hooks/useSubmitAndAwait'
import { useBalance } from '@utils/Balance'
import { humanReadable } from '@utils/formatting'
import { toTransactionData, hashTagParams } from '@utils/transactionUtils'
import BN from 'bn.js'
import { Buffer } from 'buffer'
import React from 'react'
Expand All @@ -20,6 +13,7 @@ import { MessagePreview } from '../solana/MessagePreview'
import { useSolana } from '../solana/SolanaProvider'
import { useWalletSign } from '../solana/WalletSignProvider'
import { WalletStandardMessageTypes } from '../solana/walletSignBottomSheetTypes'
import { useBlockchainApi } from '../storage/BlockchainApiProvider'

export function useImplicitBurn(): {
implicitBurn: (requiredDc: number) => void
Expand All @@ -33,6 +27,7 @@ export function useImplicitBurn(): {
const wallet = useCurrentWallet()
const { amount: myDc, loading: loadingDc } = useOwnedAmount(wallet, DC_MINT)
const { submitAndAwait } = useSubmitAndAwait()
const client = useBlockchainApi()

const {
execute: implicitBurn,
Expand All @@ -44,27 +39,28 @@ export function useImplicitBurn(): {
if (!wallet) throw new Error('No wallet')

if ((myDc || BigInt(0)) < BigInt(totalDcReq)) {
const program = (await initDataCredits(
anchorProvider,
)) as unknown as Program<DataCredits>
const dcDeficit = BigInt(totalDcReq) - (myDc || BigInt(0))
const hntAmount = dcToNetworkTokens(new BN(dcDeficit.toString()))
const ownerAddress = wallet.toBase58()

const { txs } = await mintDataCredits({
dcAmount: new BN(dcDeficit.toString()),
dcMint: DC_MINT,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
program,
recipient: wallet,
const transactionData = await client.dataCredits.mint({
owner: ownerAddress,
dcAmount: dcDeficit.toString(),
recipient: ownerAddress,
})

if (!walletSignBottomSheetRef) {
throw new Error('No wallet bottom sheet')
}

const serializedTxs = transactionData.transactions.map((tx) =>
Buffer.from(tx.serializedTransaction, 'base64'),
)

const decision = await walletSignBottomSheetRef.show({
type: WalletStandardMessageTypes.signTransaction,
url: '',
serializedTxs: txs.map(({ tx }) => Buffer.from(tx.serialize())),
serializedTxs,
header: t('transactions.buyDc'),
message: t('transactions.signMintDataCreditsTxn'),
renderer: () => (
Expand All @@ -77,37 +73,15 @@ export function useImplicitBurn(): {
),
})
if (decision) {
const paramsHash = hashTagParams({
wallet: wallet.toBase58(),
dcAmount: dcDeficit.toString(),
})
const tag = `implicit-burn-${paramsHash}`
const transactionData = toTransactionData(
txs.map(({ tx }) => tx),
{
tag,
metadata: { type: 'mint', description: 'Implicit DC Burn' },
},
)
// This will await completion and handle blockhash expiration with retry
await submitAndAwait({
transactionData,
onNeedsResign: async () => {
const { txs: freshTxs } = await mintDataCredits({
dcAmount: new BN(dcDeficit.toString()),
dcMint: DC_MINT,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
program,
recipient: wallet,
return client.dataCredits.mint({
owner: ownerAddress,
dcAmount: dcDeficit.toString(),
recipient: ownerAddress,
})
return toTransactionData(
freshTxs.map(({ tx }) => tx),
{
tag,
metadata: { type: 'mint', description: 'Implicit DC Burn' },
},
)
},
})
} else {
Expand Down
85 changes: 30 additions & 55 deletions src/hooks/useSubmitTxn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,11 @@ export default () => {
dcAmount: BN
recipient: PublicKey
}) => {
if (!currentAccount || !anchorProvider || !walletSignBottomSheetRef) {
if (
!currentAccount?.solanaAddress ||
!anchorProvider ||
!walletSignBottomSheetRef
) {
throw new Error(t('errors.account'))
}

Expand All @@ -760,18 +764,22 @@ export default () => {
await connection.getAccountInfo(recipient),
)

const txs = await solUtils.mintDataCredits({
anchorProvider,
dcAmount,
recipient,
const transactionData = await client.dataCredits.mint({
owner: currentAccount.solanaAddress,
dcAmount: dcAmount.toString(),
recipient: recipient.toBase58(),
})

const serializedTxs = transactionData.transactions.map((tx) =>
Buffer.from(tx.serializedTransaction, 'base64'),
)

const decision = await walletSignBottomSheetRef.show({
type: WalletStandardMessageTypes.signTransaction,
url: '',
warning: recipientExists ? '' : t('transactions.recipientNonExistent'),
message: t('transactions.signMintDataCreditsTxn'),
serializedTxs: txs.map(({ tx }) => Buffer.from(tx.serialize())),
serializedTxs,
renderer: () => (
<MessagePreview
message={t('transactions.signMintDataCreditsTxnPreview', {
Expand All @@ -786,26 +794,12 @@ export default () => {
throw new Error('User rejected transaction')
}

const signedTxs = await Promise.all(
txs.map(async ({ tx, signers }) => {
const signed = await anchorProvider.wallet.signTransaction(tx)
if (signers.length > 0) {
await signed.sign(signers)
}
return signed
}),
const signedTxnData = await signTransactionData(
anchorProvider.wallet,
transactionData,
)

const mintParamsHash = hashTagParams({
dcAmount: dcAmount.toString(),
recipient: recipient.toBase58(),
})
const txnData = toTransactionData(signedTxs, {
tag: `mint-dc-${mintParamsHash}`,
metadata: { type: 'mint', description: 'Mint data credits' },
})

const { batchId } = await client.transactions.submit(txnData)
const { batchId } = await client.transactions.submit(signedTxnData)
queryClient.invalidateQueries({ queryKey: ['pendingTransactions'] })
return batchId
},
Expand All @@ -831,41 +825,23 @@ export default () => {
mint: PublicKey
memo?: string
}) => {
if (!currentAccount || !anchorProvider || !walletSignBottomSheetRef) {
if (
!currentAccount?.solanaAddress ||
!anchorProvider ||
!walletSignBottomSheetRef
) {
throw new Error(t('errors.account'))
}

// Build the draft transaction
const delegateDCTxnDraft = await solUtils.delegateDataCredits(
anchorProvider,
delegateAddress,
amount,
mint,
const transactionData = await client.dataCredits.delegate({
owner: currentAccount.solanaAddress,
routerKey: delegateAddress,
amount: amount.toString(),
mint: mint.toBase58(),
memo,
)

// Populate blockhash and other missing info
const delegateDCTxn = await populateMissingDraftInfo(
anchorProvider.connection,
{
...delegateDCTxnDraft,
recentBlockhash: (
await anchorProvider.connection.getLatestBlockhash('finalized')
).blockhash,
},
)

// Convert to TransactionData format
const delegateParamsHash = hashTagParams({
delegateAddress,
timestamp: Date.now(),
})
const txnData = toTransactionData([toVersionedTx(delegateDCTxn)], {
tag: `delegate-dc-${delegateParamsHash}`,
metadata: { type: 'delegate', description: 'Delegate data credits' },
})

const serializedTxs = txnData.transactions.map((tx) =>
const serializedTxs = transactionData.transactions.map((tx) =>
Buffer.from(tx.serializedTransaction, 'base64'),
)

Expand Down Expand Up @@ -894,10 +870,9 @@ export default () => {
throw new Error('User rejected transaction')
}

// Sign and submit via API
const signedTxnData = await signTransactionData(
anchorProvider.wallet,
txnData,
transactionData,
)
const { batchId } = await client.transactions.submit(signedTxnData)
queryClient.invalidateQueries({ queryKey: ['pendingTransactions'] })
Expand Down
Loading
Loading