Skip to content

Commit

Permalink
fix(wallet-mobile): Memo avoiding subs to render (#3101)
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed Mar 19, 2024
1 parent fcd9519 commit 675fdb0
Showing 1 changed file with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as React from 'react'

import {useSelectedWallet} from '../../../SelectedWallet'
import {AddressMode} from '../../../wallet-manager/types'
import {useReceiveAddresses} from '../../../yoroi-wallets/hooks'
Expand All @@ -16,25 +14,23 @@ export const useReceiveAddressesStatus = (addressMode: AddressMode): Readonly<Re
const isSingle = addressMode === 'single'
const singleAddress = receiveAddresses[0]

return React.useMemo(() => {
const addressesStatus = receiveAddresses.reduce(
(addresses, address) => {
if (wallet.isUsedAddressIndex[address]) {
addresses.used = [...addresses.used, address]
} else {
addresses.unused = [...addresses.unused, address]
}
return addresses
},
{used: [], unused: []} as Omit<ReceiveAddressesStatus, 'next'>,
)
const multipleAddress = addressesStatus.unused[0] ?? addressesStatus.used[0]
const nextAddress = isSingle ? singleAddress : multipleAddress
const result: ReceiveAddressesStatus = {
used: addressesStatus.used,
unused: addressesStatus.unused,
next: nextAddress,
} as const
return result
}, [isSingle, receiveAddresses, singleAddress, wallet.isUsedAddressIndex])
const addressesStatus = receiveAddresses.reduce(
(addresses, address) => {
if (wallet.isUsedAddressIndex[address]) {
addresses.used = [...addresses.used, address]
} else {
addresses.unused = [...addresses.unused, address]
}
return addresses
},
{used: [], unused: []} as Omit<ReceiveAddressesStatus, 'next'>,
)
const multipleAddress = addressesStatus.unused[0] ?? addressesStatus.used[0]
const nextAddress = isSingle ? singleAddress : multipleAddress
const result: ReceiveAddressesStatus = {
used: addressesStatus.used,
unused: addressesStatus.unused,
next: nextAddress,
} as const
return result
}

0 comments on commit 675fdb0

Please sign in to comment.