diff --git a/package.json b/package.json index e7e15dfc2..64eb91524 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@helium/lazy-distributor-sdk": "^0.6.6", "@helium/onboarding": "^4.10.3", "@helium/proto-ble": "4.0.0", - "@helium/react-native-sdk": "^3.0.2", + "@helium/react-native-sdk": "^3.0.3", "@helium/spl-utils": "^0.6.6", "@helium/transactions": "4.8.1", "@helium/treasury-management-sdk": "^0.6.6", diff --git a/src/features/txnDelegation/useSolTxns.ts b/src/features/txnDelegation/useSolTxns.ts index 80121d296..442ccca4b 100644 --- a/src/features/txnDelegation/useSolTxns.ts +++ b/src/features/txnDelegation/useSolTxns.ts @@ -4,7 +4,12 @@ import { Instruction, Program, } from '@coral-xyz/anchor' -import { getAsset, Asset, heliumAddressToSolAddress } from '@helium/spl-utils' +import { + decodeEntityKey, + init, + keyToAssetForAsset, +} from '@helium/helium-entity-manager-sdk' +import { Asset, getAsset, heliumAddressToSolAddress } from '@helium/spl-utils' import { SignHotspotResponse } from '@helium/wallet-link' import { getLeafAssetId } from '@metaplex-foundation/mpl-bubblegum' import * as web3 from '@solana/web3.js' @@ -13,10 +18,6 @@ import bs58 from 'bs58' import { get, last } from 'lodash' import { useCallback, useMemo, useRef, useState } from 'react' import { useAsync } from 'react-async-hook' -import { - decodeEntityKey, - keyToAssetForAsset, -} from '@helium/helium-entity-manager-sdk' import { useSolana } from '../../solana/SolanaProvider' import { getSolanaKeypair } from '../../storage/secureStorage' import { submitSolana } from '../../utils/solanaUtils' @@ -43,7 +44,7 @@ type Txn = { } const useSolTxns = (heliumAddress: string, solanaTransactions?: string) => { - const { anchorProvider, hemProgram } = useSolana() + const { anchorProvider } = useSolana() const [submitLoading, setSubmitLoading] = useState(false) const handledTxnStr = useRef('') const [transactions, setTransactions] = useState< @@ -152,8 +153,9 @@ const useSolTxns = (heliumAddress: string, solanaTransactions?: string) => { ) const assetToAddress = useCallback( - async (asset?: Asset) => { - if (!hemProgram || !asset) return '' + async (asset?: Asset): Promise => { + if (!anchorProvider || !asset) return '' + const hemProgram = await init(anchorProvider) const keyToAssetKey = keyToAssetForAsset(asset) const keyToAsset = await hemProgram.account.keyToAssetV0.fetch( keyToAssetKey, @@ -164,7 +166,7 @@ const useSolTxns = (heliumAddress: string, solanaTransactions?: string) => { ) return entityKey || '' }, - [hemProgram], + [anchorProvider], ) const handleUpdateMeta = useCallback( diff --git a/src/solana/SolanaProvider.tsx b/src/solana/SolanaProvider.tsx index 51fabf157..cc89d4915 100644 --- a/src/solana/SolanaProvider.tsx +++ b/src/solana/SolanaProvider.tsx @@ -1,11 +1,8 @@ import { AnchorProvider, Wallet } from '@coral-xyz/anchor' import { AccountFetchCache } from '@helium/account-fetch-cache' -import { init as initDc } from '@helium/data-credits-sdk' -import { init as initHem } from '@helium/helium-entity-manager-sdk' -import { init as initHsd } from '@helium/helium-sub-daos-sdk' -import { init as initLazy } from '@helium/lazy-distributor-sdk' -import { DC_MINT, HNT_MINT } from '@helium/spl-utils' +import { AccountContext } from '@helium/account-fetch-cache-hooks' import { SolanaProvider as SolanaProviderRnHelium } from '@helium/react-native-sdk' +import { DC_MINT, HNT_MINT } from '@helium/spl-utils' import { AccountInfo, Cluster, @@ -15,6 +12,7 @@ import { Transaction, VersionedTransaction, } from '@solana/web3.js' +import { WrappedConnection } from '@utils/WrappedConnection' import React, { ReactNode, createContext, @@ -23,22 +21,18 @@ import React, { useEffect, useMemo, useRef, - useState, } from 'react' import { useAsync } from 'react-async-hook' import Config from 'react-native-config' import { useSelector } from 'react-redux' import nacl from 'tweetnacl' -import { WrappedConnection } from '@utils/WrappedConnection' -import { AccountContext } from '@helium/account-fetch-cache-hooks' +import LedgerModal, { LedgerModalRef } from '../features/ledger/LedgerModal' import { useAccountStorage } from '../storage/AccountStorageProvider' import { getSessionKey, getSolanaKeypair } from '../storage/secureStorage' import { RootState } from '../store/rootReducer' import { appSlice } from '../store/slices/appSlice' import { useAppDispatch } from '../store/store' -import { DcProgram, HemProgram, HsdProgram, LazyProgram } from '../types/solana' import { getConnection, isVersionedTransaction } from '../utils/solanaUtils' -import LedgerModal, { LedgerModalRef } from '../features/ledger/LedgerModal' const useSolanaHook = () => { const { currentAccount } = useAccountStorage() @@ -46,10 +40,6 @@ const useSolanaHook = () => { const cluster = useSelector( (state: RootState) => state.app.cluster || 'mainnet-beta', ) - const [dcProgram, setDcProgram] = useState() - const [hemProgram, setHemProgram] = useState() - const [hsdProgram, setHsdProgram] = useState() - const [lazyProgram, setLazyProgram] = useState() const { loading, result: sessionKey } = useAsync(getSessionKey, []) const ledgerModalRef = useRef() const connection = useMemo(() => { @@ -241,19 +231,6 @@ const useSolanaHook = () => { return () => cache?.close() }, [cache]) - const handleConnectionChanged = useCallback(async () => { - if (!anchorProvider) return - - initHem(anchorProvider).then(setHemProgram) - initHsd(anchorProvider).then(setHsdProgram) - initDc(anchorProvider).then(setDcProgram) - initLazy(anchorProvider).then(setLazyProgram) - }, [anchorProvider]) - - useEffect(() => { - handleConnectionChanged() - }, [cluster, address, handleConnectionChanged]) - const updateCluster = useCallback( (nextCluster: Cluster) => { dispatch(appSlice.actions.setCluster(nextCluster)) @@ -266,10 +243,6 @@ const useSolanaHook = () => { cluster, isDevnet, connection, - dcProgram, - hemProgram, - hsdProgram, - lazyProgram, updateCluster, cache, signMsg, @@ -282,10 +255,6 @@ const initialState: { cluster: Cluster isDevnet: boolean connection: WrappedConnection | undefined - dcProgram: DcProgram | undefined - hemProgram: HemProgram | undefined - hsdProgram: HsdProgram | undefined - lazyProgram: LazyProgram | undefined cache: AccountFetchCache | undefined updateCluster: (nextCluster: Cluster) => void signMsg: (msg: Buffer) => Promise @@ -295,10 +264,6 @@ const initialState: { cluster: 'mainnet-beta' as Cluster, isDevnet: false, connection: undefined, - dcProgram: undefined, - hemProgram: undefined, - hsdProgram: undefined, - lazyProgram: undefined, cache: undefined, updateCluster: (_nextCluster: Cluster) => {}, signMsg: (_msg: Buffer) => Promise.resolve(_msg), @@ -315,7 +280,7 @@ const SolanaProvider = ({ children }: { children: ReactNode }) => { {values.cache && values.connection && ( {children}