From e88c9260420e10c92d6e707b14976e1dd66a8236 Mon Sep 17 00:00:00 2001 From: Matt Reetz Date: Wed, 14 Aug 2024 14:53:58 -0500 Subject: [PATCH] Fix location updates failing to parse when linking from other applications. --- ios/Podfile.lock | 2 +- package.json | 2 +- src/features/txnDelegation/useSolTxns.ts | 57 +++++++++++++++--------- yarn.lock | 33 +++++++++----- 4 files changed, 60 insertions(+), 34 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index bb12917c1..9dba48b62 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -841,7 +841,7 @@ SPEC CHECKSUMS: BCrypt: 712b656110e5020d319c547e4d8f3053ded82b2a bcrypt-react-native: 399775585257ae6c8717370a1119c7da0113e3bf BEMCheckBox: 5ba6e37ade3d3657b36caecc35c8b75c6c2b1a4e - boost: 64032b9e9b938fda23325e68a3771f0fabf414dc + boost: 57d2868c099736d80fcd648bf211b4431e51a558 BVLinearGradient: 34a999fda29036898a09c6a6b728b0b4189e1a44 Charts: ce0768268078eee0336f122c3c4ca248e4e204c5 DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 diff --git a/package.json b/package.json index 73f992bd9..76bf6ee8d 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@helium/helium-react-hooks": "0.9.2", "@helium/helium-sub-daos-sdk": "^0.9.2", "@helium/http": "4.7.5", - "@helium/idls": "0.9.2", + "@helium/idls": "0.9.4", "@helium/lazy-distributor-sdk": "^0.9.2", "@helium/modular-governance-hooks": "^0.0.8", "@helium/modular-governance-idls": "0.0.8-next.22+7098baa", diff --git a/src/features/txnDelegation/useSolTxns.ts b/src/features/txnDelegation/useSolTxns.ts index bcc8f44dc..c2f9908a7 100644 --- a/src/features/txnDelegation/useSolTxns.ts +++ b/src/features/txnDelegation/useSolTxns.ts @@ -19,6 +19,7 @@ import bs58 from 'bs58' import { get, last } from 'lodash' import { useCallback, useMemo, useRef, useState } from 'react' import { useAsync } from 'react-async-hook' +import { IdlInstruction } from '@coral-xyz/anchor/dist/cjs/idl' import { useSolana } from '../../solana/SolanaProvider' import { getKeypair, getSolanaKeypair } from '../../storage/secureStorage' import { submitSolana } from '../../utils/solanaUtils' @@ -185,47 +186,48 @@ const useSolTxns = ({ async ({ decodedInstruction, instruction, + idlInstruction, connection, - coder, }: { - coder: BorshInstructionCoder decodedInstruction: Instruction instruction: web3.TransactionInstruction + idlInstruction: IdlInstruction | undefined connection: Connection }) => { - const formatted = coder.format(decodedInstruction, instruction.keys) - - const merkleTreeAccount = formatted?.accounts.find( - ({ name }) => name === 'Merkle Tree', - ) - if (!merkleTreeAccount) { - throw new Error('Failed to format instruction') - } + const accounts = idlInstruction?.accounts || [] + const merkleIndex = accounts.findIndex((a) => a.name === 'merkleTree') + const merkleTreeAccount = instruction.keys[merkleIndex] - const { location, elevation, gain, index } = get( - decodedInstruction, - 'data.args', - ) as { + const rootInfo = get(decodedInstruction, 'data.args') as { location: BN elevation: number gain: number index: number } + const wifiInfo = get( + decodedInstruction, + 'data.args.deploymentInfo.wifiInfoV0', + ) as { azimuth: number; elevation: number } | undefined + + if (!merkleTreeAccount) { + throw new Error('Failed to format instruction') + } const pubKey = await getLeafAssetId( merkleTreeAccount.pubkey, - new BN(index), + new BN(rootInfo.index), ) const asset = await getAsset(connection.rpcEndpoint, pubKey) const gatewayAddress = await assetToAddress(asset) return { - location: location?.toString('hex'), - elevation, - gain, + location: rootInfo.location?.toString('hex'), + elevation: wifiInfo?.elevation || rootInfo.elevation, + gain: rootInfo.gain, name: decodedInstruction.name, gatewayAddress, + azimuth: wifiInfo?.azimuth, } }, [assetToAddress], @@ -324,12 +326,23 @@ const useSolTxns = ({ try { const idl = await fetchIdl(instruction.programId) + const coder = new BorshInstructionCoder(idl) const decodedInstruction = coder.decode(instruction.data) if (!decodedInstruction) return {} - switch (decodedInstruction.name as ValidTxn) { + const name = decodedInstruction.name as ValidTxn + let idlInstruction: IdlInstruction | undefined + idl.instructions.every((i) => { + const found = i.name === name + if (found) { + idlInstruction = i + } + return !found + }) + + switch (name) { case 'onboardIotHotspotV0': case 'onboardMobileHotspotV0': return await handleOnboard({ @@ -344,8 +357,8 @@ const useSolTxns = ({ return await handleUpdateMeta({ decodedInstruction, instruction, + idlInstruction, connection, - coder, }) case 'transfer': return await handleTransfer({ @@ -364,6 +377,7 @@ const useSolTxns = ({ }) } } catch (e) { + console.error(e) return {} } }, @@ -523,7 +537,8 @@ const useSolTxns = ({ return { newOwner: txn?.newOwner || '' } }, [transactions]) - const hasTransactions = useMemo(() => !!gatewayAddress, [gatewayAddress]) + // const hasTransactions = useMemo(() => !!gatewayAddress, [gatewayAddress]) + const hasTransactions = true const submit = useCallback(async () => { if (!anchorProvider) return diff --git a/yarn.lock b/yarn.lock index cb827f0b9..877a03932 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2371,17 +2371,6 @@ retry-axios "^2.1.2" snakecase-keys "^5.1.0" -"@helium/idls@0.9.2", "@helium/idls@^0.9.2": - version "0.9.2" - resolved "https://registry.yarnpkg.com/@helium/idls/-/idls-0.9.2.tgz#ed2db1cc2e130de89dd1275ab779d0defcd9cfd7" - integrity sha512-biAOkG34i2QPWUL/BoD1N1WFnvY3dxP/vRVVrmfCq5HTFziAGMpgwvvMRBdzaNLZbFKty8JhvLR8udj6Oe+LMQ== - dependencies: - "@coral-xyz/anchor" "^0.28.0" - "@solana/web3.js" "^1.78.8" - bn.js "^5.2.0" - borsh "^0.7.0" - bs58 "^4.0.1" - "@helium/idls@^0.5.0": version "0.5.0" resolved "https://registry.yarnpkg.com/@helium/idls/-/idls-0.5.0.tgz#93f179d41d2dd36a715a70123d38b76ec022f890" @@ -2415,6 +2404,28 @@ borsh "^0.7.0" bs58 "^4.0.1" +"@helium/idls@^0.9.2": + version "0.9.2" + resolved "https://registry.yarnpkg.com/@helium/idls/-/idls-0.9.2.tgz#ed2db1cc2e130de89dd1275ab779d0defcd9cfd7" + integrity sha512-biAOkG34i2QPWUL/BoD1N1WFnvY3dxP/vRVVrmfCq5HTFziAGMpgwvvMRBdzaNLZbFKty8JhvLR8udj6Oe+LMQ== + dependencies: + "@coral-xyz/anchor" "^0.28.0" + "@solana/web3.js" "^1.78.8" + bn.js "^5.2.0" + borsh "^0.7.0" + bs58 "^4.0.1" + +"@helium/idls@^0.9.4": + version "0.9.4" + resolved "https://registry.yarnpkg.com/@helium/idls/-/idls-0.9.4.tgz#66902fb444486108f6a1fd2f5e269d3d41b6ca9f" + integrity sha512-AjEDZGWWBxSNyHGX6fplrFiIMQNCYGBwG85qOarNmczjOpna2ZxR/kqQY0u17Falg9K4i7wMM6EfJUY/g8xYyA== + dependencies: + "@coral-xyz/anchor" "^0.28.0" + "@solana/web3.js" "^1.78.8" + bn.js "^5.2.0" + borsh "^0.7.0" + bs58 "^4.0.1" + "@helium/lazy-distributor-sdk@^0.9.2": version "0.9.2" resolved "https://registry.yarnpkg.com/@helium/lazy-distributor-sdk/-/lazy-distributor-sdk-0.9.2.tgz#312ed260376bf8dfd2b016e312f4128c6f999c02"