Skip to content

Commit

Permalink
Fix location updates failing to parse when linking from other applica…
Browse files Browse the repository at this point in the history
…tions.
  • Loading branch information
matthewcarlreetz committed Aug 14, 2024
1 parent 4c90e38 commit e88c926
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 34 deletions.
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ SPEC CHECKSUMS:
BCrypt: 712b656110e5020d319c547e4d8f3053ded82b2a
bcrypt-react-native: 399775585257ae6c8717370a1119c7da0113e3bf
BEMCheckBox: 5ba6e37ade3d3657b36caecc35c8b75c6c2b1a4e
boost: 64032b9e9b938fda23325e68a3771f0fabf414dc
boost: 57d2868c099736d80fcd648bf211b4431e51a558
BVLinearGradient: 34a999fda29036898a09c6a6b728b0b4189e1a44
Charts: ce0768268078eee0336f122c3c4ca248e4e204c5
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
57 changes: 36 additions & 21 deletions src/features/txnDelegation/useSolTxns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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({
Expand All @@ -344,8 +357,8 @@ const useSolTxns = ({
return await handleUpdateMeta({
decodedInstruction,
instruction,
idlInstruction,
connection,
coder,
})
case 'transfer':
return await handleTransfer({
Expand All @@ -364,6 +377,7 @@ const useSolTxns = ({
})
}
} catch (e) {
console.error(e)
return {}
}
},
Expand Down Expand Up @@ -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
Expand Down
33 changes: 22 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2371,17 +2371,6 @@
retry-axios "^2.1.2"
snakecase-keys "^5.1.0"

"@helium/[email protected]", "@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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit e88c926

Please sign in to comment.