diff --git a/src/features/keystone/KeystoneAccountAssignScreen.tsx b/src/features/keystone/KeystoneAccountAssignScreen.tsx index b40171f38..bca13beab 100644 --- a/src/features/keystone/KeystoneAccountAssignScreen.tsx +++ b/src/features/keystone/KeystoneAccountAssignScreen.tsx @@ -16,6 +16,9 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context' import base58 from 'bs58' import { CSAccountVersion } from '@storage/cloudStorage' import { hex } from '@coral-xyz/anchor/dist/cjs/utils/bytes' +import { PublicKey } from '@solana/web3.js' +import Address from '@helium/address' +import { ED25519_KEY_TYPE } from '@helium/address/build/KeyTypes' import { RootNavigationProp } from '../../navigation/rootTypes' import { useAccountStorage } from '../../storage/AccountStorageProvider' import { ImportAccountNavigationProp } from '../onboarding/import/importAccountNavTypes' @@ -50,11 +53,18 @@ const KeystoneAccountAssignScreen = () => { return getName(index + 1) } + // convert solana public key to helium address + const solanaPublicKeyToHeliumAddress = (publicKey: string): string => { + const pkey = new PublicKey(hex.decode(publicKey)) + const heliumAddr = new Address(0, 0, ED25519_KEY_TYPE, pkey.toBytes()) + const heliumAddress = heliumAddr.b58 + return heliumAddress + } const accountBulk = keystoneOnboardingData.accounts.map( (account, index) => ({ alias: getName(index), - address: base58.encode( - hex.decode(keystoneOnboardingData.accounts[index].publicKey), + address: solanaPublicKeyToHeliumAddress( + keystoneOnboardingData.accounts[index].publicKey, ), solanaAddress: base58.encode( hex.decode(keystoneOnboardingData.accounts[index].publicKey), diff --git a/src/storage/cloudStorage.ts b/src/storage/cloudStorage.ts index b232bead6..012c58aaa 100644 --- a/src/storage/cloudStorage.ts +++ b/src/storage/cloudStorage.ts @@ -72,12 +72,7 @@ export const sortAccounts = ( ) => { const acctList = values(accts) const sortedByAlias = sortBy(acctList, 'alias') || [] - // if account is keystone account, add solanaAddress const sortedByAliasWithSolanaAddress = sortedByAlias.map((acct) => { - // here we need to check if the account is keystone account - if (acct.keystoneDevice) { - return { ...acct, solanaAddress: acct.address } - } return acct }) if (defaultAddress) { @@ -137,7 +132,7 @@ export const restoreAccounts = async () => { } } - if (!acct.solanaAddress && !acct.keystoneDevice) { + if (!acct.solanaAddress) { // eslint-disable-next-line no-param-reassign acct.solanaAddress = heliumAddressToSolAddress(acct.address) }