Skip to content

Commit

Permalink
fix: remove gross code
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhenQian committed Sep 12, 2024
1 parent 534eab7 commit 874b80a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
14 changes: 12 additions & 2 deletions src/features/keystone/KeystoneAccountAssignScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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),
Expand Down
7 changes: 1 addition & 6 deletions src/storage/cloudStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 874b80a

Please sign in to comment.