-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e372e4
commit e60d527
Showing
9 changed files
with
65 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
import { Account } from '@stacks/wallet-sdk'; | ||
import { useMemo } from 'react'; | ||
|
||
import { useCurrentAccount } from '@app/store/accounts/account.hooks'; | ||
import { useAllAccountNames, useCurrentAccountNames } from '@app/query/bns/bns.hooks'; | ||
import { useCurrentAccountNames, useGetAccountNamesByAddressQuery } from '@app/query/bns/bns.hooks'; | ||
|
||
export function useCurrentAccountDisplayName() { | ||
const names = useCurrentAccountNames(); | ||
const account = useCurrentAccount(); | ||
if (!account || typeof account?.index !== 'number') return 'Account'; | ||
return names?.[0] || `Account ${account?.index + 1}`; | ||
return useMemo(() => { | ||
if (!account || typeof account?.index !== 'number') return 'Account'; | ||
return names?.[0] || `Account ${account?.index + 1}`; | ||
}, [account, names]); | ||
} | ||
|
||
export function useAccountDisplayName(providedAccount?: Account) { | ||
// if we don't pass an account, we should use this | ||
// as it will only fetch the single name if we need it | ||
const accountDisplayName = useCurrentAccountDisplayName(); | ||
const names = useAllAccountNames(); | ||
const account = providedAccount; | ||
export function useAccountDisplayName(address: string, index: number) { | ||
const names = useGetAccountNamesByAddressQuery(address); | ||
|
||
if (!providedAccount) return accountDisplayName; | ||
if (!account || typeof account?.index !== 'number') return 'Account'; | ||
return names?.[account.index]?.names?.[0] || `Account ${account?.index + 1}`; | ||
return useMemo(() => { | ||
if (!names.length) return `Account ${index + 1}`; | ||
return names[0]; | ||
}, [index, names]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,16 @@ | ||
import { useMemo } from 'react'; | ||
import { logger } from '@shared/logger'; | ||
import { useAccounts, useCurrentAccountStxAddressState } from '@app/store/accounts/account.hooks'; | ||
import { useGetBnsNamesOwnedByAddress, useGetBnsNamesOwnedByAddressList } from './bns.query'; | ||
|
||
export function useAllAccountNames() { | ||
const accounts = useAccounts() ?? []; | ||
const result = useGetBnsNamesOwnedByAddressList(accounts.map(a => a.address)); | ||
return accounts.map(({ address, index }) => ({ | ||
address, | ||
index, | ||
names: result[index].data?.names ?? [], | ||
})); | ||
} | ||
import { useCurrentAccountStxAddressState } from '@app/store/accounts/account.hooks'; | ||
import { useGetBnsNamesOwnedByAddress } from './bns.query'; | ||
|
||
export function useCurrentAccountNames() { | ||
const principal = useCurrentAccountStxAddressState(); | ||
if (!principal) logger.error('No principal defined'); | ||
const namesResponse = useGetBnsNamesOwnedByAddress(principal ?? ''); | ||
return namesResponse.data?.names ?? []; | ||
return useMemo(() => namesResponse.data?.names ?? [], [namesResponse.data?.names]); | ||
} | ||
|
||
export function useGetAccountNamesByAddressQuery(address: string) { | ||
const namesResponse = useGetBnsNamesOwnedByAddress(address); | ||
return namesResponse.data?.names ?? []; | ||
return useMemo(() => namesResponse.data?.names ?? [], [namesResponse.data?.names]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters