Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ vi.mock('@perawallet/wallet-core-accounts', async importOriginal => {
isPending: false,
})),
useAllAccounts: vi.fn(() => []),
useAccountAuthAddresses: vi.fn(() => ({
authAddresses: new Map<string, string | null>(),
isPending: false,
isFetched: true,
})),
isSigningAccount: vi.fn(() => true),
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
isSigningAccount,
useAccountBalancesQuery,
useAllAccounts,
useAccountAuthAddresses,
useSortedAssetBalances,
WalletAccount,
AssetWithAccountBalance,
Expand Down Expand Up @@ -152,7 +153,12 @@ export const useAccountAssetList = ({
}, [sortedBalances, debouncedSearchFilter, assets])

const allAccounts = useAllAccounts()
const isWatch = !isSigningAccount(account, allAccounts)
const { authAddresses } = useAccountAuthAddresses()
const isWatch = !isSigningAccount(
account,
allAccounts,
authAddresses.get(account.address),
)

const goToAssetScreen = useCallback(
(item: AssetWithAccountBalance) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
AccountStatus,
resolveAccountStatus,
useAllAccounts,
useAccountAuthAddresses,
WalletAccount,
} from '@perawallet/wallet-core-accounts'
import { useIsDarkMode } from '@hooks/useIsDarkMode'
Expand Down Expand Up @@ -45,12 +46,17 @@ export const AccountIcon = (props: AccountIconProps) => {
const { account, size = 'md', ...rest } = props
const darkmode = useIsDarkMode()
const accounts = useAllAccounts()
const { authAddresses } = useAccountAuthAddresses()

const icon = useMemo(() => {
if (!account) return <></>

const theme = darkmode ? 'dark' : 'light'
const accountStatus = resolveAccountStatus(account, accounts)
const accountStatus = resolveAccountStatus(
account,
accounts,
authAddresses.get(account.address),
)
const icon = iconNames[accountStatus] ?? FALLBACK_ASSET
const iconName: IconName = icon.replaceAll(
THEME_TOKEN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ vi.mock('@perawallet/wallet-core-accounts', () => ({
resolveAccountStatus: (...args: unknown[]) =>
mockResolveAccountStatus(...(args as [])),
useAllAccounts: vi.fn(() => []),
useAccountAuthAddresses: vi.fn(() => ({
authAddresses: new Map<string, string | null>(),
isPending: false,
isFetched: true,
})),
}))

const account = { address: 'addr' } as WalletAccount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ vi.mock('@perawallet/wallet-core-config', () => ({
}))

const mockUseAllAccounts = vi.fn()
const mockUseAccountAuthAddresses =
vi.fn<() => { authAddresses: Map<string, string | null> }>()
vi.mock('@perawallet/wallet-core-accounts', async importOriginal => {
const actual =
await importOriginal<
Expand All @@ -51,6 +53,7 @@ vi.mock('@perawallet/wallet-core-accounts', async importOriginal => {
return {
...actual,
useAllAccounts: () => mockUseAllAccounts(),
useAccountAuthAddresses: () => mockUseAccountAuthAddresses(),
}
})

Expand Down Expand Up @@ -104,24 +107,36 @@ const multisigAccount: WalletAccount = {
const rekeyedWithAuthAccount: WalletAccount = {
type: 'algo25',
address: 'REKEYEDADDR1234567890ABCDEFGHIJKLMNOPQRSTUVW',
rekeyAddress: 'ALGO25ADDR1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ',
keyPairId: 'key-4',
}

const rekeyedToLedgerAccount: WalletAccount = {
type: 'algo25',
address: 'REKEYLEDGADDR1234567890ABCDEFGHIJKLMNOPQRSTUV',
rekeyAddress: 'LEDGERADDR1234567890ABCDEFGHIJKLMNOPQRSTUVWX',
keyPairId: 'key-5',
}

const rekeyedNoAuthAccount: WalletAccount = {
type: 'algo25',
address: 'REKEYNOAUTHADDR1234567890ABCDEFGHIJKLMNOPQRST',
rekeyAddress: 'UNKNOWNADDR1234567890ABCDEFGHIJKLMNOPQRSTUV',
keyPairId: 'key-6',
}

const authAddressMap = new Map<string, string | null>([
[
rekeyedWithAuthAccount.address,
'ALGO25ADDR1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ',
],
[
rekeyedToLedgerAccount.address,
'LEDGERADDR1234567890ABCDEFGHIJKLMNOPQRSTUVWX',
],
[
rekeyedNoAuthAccount.address,
'UNKNOWNADDR1234567890ABCDEFGHIJKLMNOPQRSTUV',
],
])

describe('useAccountTypeInfo', () => {
const onClose = vi.fn()

Expand All @@ -133,6 +148,9 @@ describe('useAccountTypeInfo', () => {
watchAccount,
hdWalletAccount,
])
mockUseAccountAuthAddresses.mockReturnValue({
authAddresses: authAddressMap,
})
})

it('resolves standard account type', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
canSignWithAccount,
hasSigningKeys,
useAllAccounts,
useAccountAuthAddresses,
resolveAccountStatus,
type AccountStatus,
} from '@perawallet/wallet-core-accounts'
Expand Down Expand Up @@ -91,10 +92,12 @@ export const useAccountTypeInfo = ({
const { showToast } = useToast()
const { pushWebView } = useWebView()
const accounts = useAllAccounts()
const { authAddresses } = useAccountAuthAddresses()
const accountAuthAddress = authAddresses.get(account.address) ?? null

const status = useMemo(
() => resolveAccountStatus(account, accounts),
[account, accounts],
() => resolveAccountStatus(account, accounts, accountAuthAddress),
[account, accounts, accountAuthAddress],
)

const title = t(STATUS_I18N_MAP[status].title)
Expand All @@ -116,7 +119,7 @@ export const useAccountTypeInfo = ({
const actions = useMemo(() => {
const items: AccountTypeAction[] = []

if (canSignWithAccount(account, accounts)) {
if (canSignWithAccount(account, accounts, authAddresses)) {
items.push({
id: 'rekey-to-ledger',
title: t('account_type_info.rekey_to_ledger'),
Expand All @@ -131,7 +134,10 @@ export const useAccountTypeInfo = ({
})
}

if (isRekeyedAccount(account) && hasSigningKeys(account)) {
if (
isRekeyedAccount(account, accountAuthAddress) &&
hasSigningKeys(account)
) {
items.push({
id: 'undo-rekey',
title: t('account_type_info.undo_rekey'),
Expand All @@ -140,7 +146,7 @@ export const useAccountTypeInfo = ({
})
}

if (isRekeyedAccount(account)) {
if (isRekeyedAccount(account, accountAuthAddress)) {
items.push({
id: 'rescan-rekeyed',
title: t('account_type_info.rescan_rekeyed'),
Expand All @@ -150,7 +156,14 @@ export const useAccountTypeInfo = ({
}

return items
}, [account, accounts, t, notImplemented])
}, [
account,
accounts,
accountAuthAddress,
authAddresses,
t,
notImplemented,
])

return {
title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ vi.mock('@perawallet/wallet-core-accounts', async importOriginal => {
useAccountInformationQuery: (...args: unknown[]) =>
mockUseAccountInformationQuery(...args),
useHDWalletGroups: () => mockUseHDWalletGroups(),
useAccountAuthAddresses: () => ({
authAddresses: new Map<string, string | null>(),
isPending: false,
isFetched: true,
}),
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
isHDWalletAccount,
isSigningAccount,
useAllAccounts,
useAccountAuthAddresses,
useHDWalletGroups,
useAccountInformationQuery,
} from '@perawallet/wallet-core-accounts'
Expand Down Expand Up @@ -56,8 +57,13 @@ export const useAccountInfoCard = ({
const { hdWalletGroups } = useHDWalletGroups()

const allAccounts = useAllAccounts()
const { authAddresses } = useAccountAuthAddresses()
const isHDWallet = isHDWalletAccount(account)
const showMinBalance = isSigningAccount(account, allAccounts)
const showMinBalance = isSigningAccount(
account,
allAccounts,
authAddresses.get(account.address),
)

const handleToggleExpanded = useCallback(() => {
setIsExpanded(prev => !prev)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ vi.mock('@perawallet/wallet-core-accounts', async importOriginal => {
useAccountBalancesQuery: (...args: unknown[]) =>
mockUseAccountBalancesQuery(...args),
useAllAccounts: (...args: unknown[]) => mockUseAllAccounts(...args),
useAccountAuthAddresses: () => ({
authAddresses: new Map<string, string | null>(),
isPending: false,
isFetched: true,
}),
isSigningAccount: (...args: unknown[]) => mockIsSigningAccount(...args),
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
useSelectedAccount,
useAccountBalancesQuery,
useAllAccounts,
useAccountAuthAddresses,
isSigningAccount,
} from '@perawallet/wallet-core-accounts'
import {
Expand Down Expand Up @@ -105,6 +106,7 @@ const sortCollectibles = (
export const useAccountNfts = (): UseAccountNftsResult => {
const account = useSelectedAccount()
const allAccounts = useAllAccounts()
const { authAddresses } = useAccountAuthAddresses()
const [searchFilter, setSearchFilter] = useState('')

const sortMode = useCollectiblePreferencesStore(
Expand Down Expand Up @@ -139,8 +141,14 @@ export const useAccountNfts = (): UseAccountNftsResult => {
const navigation = useNavigation<NativeStackNavigationProp<ParamListBase>>()

const canOptIn = useMemo(
() => account !== null && isSigningAccount(account, allAccounts),
[account, allAccounts],
() =>
account !== null &&
isSigningAccount(
account,
allAccounts,
authAddresses.get(account.address),
),
[account, allAccounts, authAddresses],
)

const { accountBalances, isPending } = useAccountBalancesQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const { mockRemoveAccountById } = vi.hoisted(() => ({
const { mockAllAccounts } = vi.hoisted(() => ({
mockAllAccounts: vi.fn((): WalletAccount[] => []),
}))
const { mockAuthAddresses } = vi.hoisted(() => ({
mockAuthAddresses: vi.fn(
(): { authAddresses: Map<string, string | null> } => ({
authAddresses: new Map(),
}),
),
}))
const { mockUpdateAccount } = vi.hoisted(() => ({
mockUpdateAccount: vi.fn(),
}))
Expand Down Expand Up @@ -76,6 +83,7 @@ vi.mock('@perawallet/wallet-core-accounts', async importOriginal => {
useRemoveAccountById: () => mockRemoveAccountById,
useUpdateAccount: () => mockUpdateAccount,
useAllAccounts: () => mockAllAccounts(),
useAccountAuthAddresses: () => mockAuthAddresses(),
}
})

Expand All @@ -102,14 +110,12 @@ describe('useAccountOptions', () => {
address: 'REKEYEDADDRESS',
type: AccountTypes.algo25,
keyPairId: 'key-3',
rekeyAddress: 'AUTHADDRESS',
}

const rekeyedWatchAccount: WalletAccount = {
id: 'acc-5',
address: 'REKEYEDWATCHADDRESS',
type: AccountTypes.watch,
rekeyAddress: 'ALGO25ADDRESS',
}

const hardwareAccount: WalletAccount = {
Expand All @@ -127,6 +133,7 @@ describe('useAccountOptions', () => {
beforeEach(() => {
vi.clearAllMocks()
mockIsAccountEnabled.mockReturnValue(true)
mockAuthAddresses.mockReturnValue({ authAddresses: new Map() })
mockAllAccounts.mockReturnValue([algo25Account, watchAccount])
})

Expand Down Expand Up @@ -173,6 +180,12 @@ describe('useAccountOptions', () => {
})

it('shows all options including rekey for a rekeyed account', () => {
mockAuthAddresses.mockReturnValue({
authAddresses: new Map([
[rekeyedAccount.address, 'AUTHADDRESS'],
]),
})

const { result } = renderHook(() =>
useAccountOptions({
account: rekeyedAccount,
Expand Down Expand Up @@ -201,6 +214,11 @@ describe('useAccountOptions', () => {
algo25Account,
rekeyedWatchAccount,
])
mockAuthAddresses.mockReturnValue({
authAddresses: new Map([
[rekeyedWatchAccount.address, algo25Account.address],
]),
})

const { result } = renderHook(() =>
useAccountOptions({
Expand Down Expand Up @@ -475,6 +493,12 @@ describe('useAccountOptions', () => {
})

it('copies rekey auth address when auth address option is pressed', () => {
mockAuthAddresses.mockReturnValue({
authAddresses: new Map([
[rekeyedAccount.address, 'AUTHADDRESS'],
]),
})

const { result } = renderHook(() =>
useAccountOptions({
account: rekeyedAccount,
Expand Down Expand Up @@ -632,6 +656,12 @@ describe('useAccountOptions', () => {
})

it('shows not implemented toast for undo-rekey', () => {
mockAuthAddresses.mockReturnValue({
authAddresses: new Map([
[rekeyedAccount.address, 'AUTHADDRESS'],
]),
})

const { result } = renderHook(() =>
useAccountOptions({
account: rekeyedAccount,
Expand Down Expand Up @@ -680,9 +710,13 @@ describe('useAccountOptions', () => {
address: 'SOMEOTHERADDRESS',
type: AccountTypes.algo25,
keyPairId: 'key-rekeyed',
rekeyAddress: 'ALGO25ADDRESS',
}
mockAllAccounts.mockReturnValue([algo25Account, rekeyedToAlgo25])
mockAuthAddresses.mockReturnValue({
authAddresses: new Map([
[rekeyedToAlgo25.address, algo25Account.address],
]),
})

const { result } = renderHook(() =>
useAccountOptions({
Expand Down
Loading
Loading