Skip to content

Commit

Permalink
Use name registry in recipients list (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut authored Oct 19, 2023
1 parent cacb136 commit 244076a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/ui/cypress/tests/transactions.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { landingPageUrl } from '../fixtures/landingData'
import { multisigPage } from '../support/page-objects/multisigPage'
import { notifications } from '../support/page-objects/notifications'
import { sendTxModal } from '../support/page-objects/sendTxModal'
import { topMenuItems } from '../support/page-objects/topMenuItems'
import { clickOnConnect } from '../utils/clickOnConnect'
import { waitForTxRequest } from '../utils/waitForTxRequests'

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/EasySetup/BalancesTransfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface Props {
}

const BalancesTransfer = ({ className, onSetExtrinsic, onSetErrorMessage, from }: Props) => {
const accountBase = useAccountBaseFromAccountList()
const accountBase = useAccountBaseFromAccountList({ withAccountsFromAddressBook: true })
const [selected, setSelected] = useState<AccountBaseInfo | undefined>()
const { api, chainInfo } = useApi()
const [amountString, setAmountString] = useState('')
Expand Down
21 changes: 16 additions & 5 deletions packages/ui/src/hooks/useAccountBaseFromAccountList.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { useMemo } from 'react'
import { AccountBaseInfo } from '../components/select/GenericAccountSelection'
import { useAccounts } from '../contexts/AccountsContext'
import { useAccountNames } from '../contexts/AccountNamesContext'

export const useAccountBaseFromAccountList = () => {
interface Params {
withAccountsFromAddressBook: boolean
}

export const useAccountBaseFromAccountList = (params?: Params) => {
const { withAccountsFromAddressBook = false } = params || {}
const { ownAccountList } = useAccounts()
const { accountNames } = useAccountNames()

const accountBase = useMemo((): AccountBaseInfo[] => {
return (
(ownAccountList && ownAccountList?.map((account) => ({ address: account.address }))) || []
)
}, [ownAccountList])
const ownAccountListAddresses =
(ownAccountList && ownAccountList.map(({ address }) => address)) || []
const accountFromNameRegistry =
(withAccountsFromAddressBook && Object.keys(accountNames).map((address) => address)) || []
const addressesSet = new Set([...accountFromNameRegistry, ...ownAccountListAddresses])

return Array.from(addressesSet).map((address) => ({ address }))
}, [accountNames, ownAccountList, withAccountsFromAddressBook])

return accountBase
}

0 comments on commit 244076a

Please sign in to comment.