@@ -13,6 +13,11 @@ import { transformXPAddresses } from './transformXPAddresses'
1313
1414const STALE_TIME = 60 * 1000 // 1 minute
1515
16+ const EMPTY_XP_ADDRESSES = {
17+ xpAddresses : [ ] as string [ ] ,
18+ xpAddressDictionary : { } as XPAddressDictionary
19+ }
20+
1621const getQueryKey = ( {
1722 walletId,
1823 walletType,
@@ -53,6 +58,14 @@ export const useXPAddresses = (
5358
5459 const shouldDisable = ! wallet || ! account
5560
61+ // Keystone SDK currently only exposes a single XP xpub (account index 0)
62+ // for all accounts. Until their SDK supports per-account xpubs, non-primary
63+ // accounts must return empty to avoid duplicate XP balances caused by the
64+ // addressPVM fallback in transformXPAddresses.
65+ // TODO: Remove this workaround once the Keystone SDK is fixed.
66+ const isKeystoneNonPrimary =
67+ walletType === WalletType . KEYSTONE && accountIndex > 0
68+
5669 const queryResult = useQuery ( {
5770 staleTime : STALE_TIME ,
5871 queryKey : getQueryKey ( {
@@ -62,17 +75,18 @@ export const useXPAddresses = (
6275 accountId,
6376 isDeveloperMode
6477 } ) ,
65- queryFn : shouldDisable
66- ? skipToken
67- : ( ) => {
68- return getAddressesFromXpubXP ( {
69- isDeveloperMode,
70- walletId,
71- walletType : walletType as WalletType ,
72- accountIndex,
73- onlyWithActivity : true
74- } )
75- }
78+ queryFn :
79+ shouldDisable || isKeystoneNonPrimary
80+ ? skipToken
81+ : ( ) => {
82+ return getAddressesFromXpubXP ( {
83+ isDeveloperMode,
84+ walletId,
85+ walletType : walletType as WalletType ,
86+ accountIndex,
87+ onlyWithActivity : true
88+ } )
89+ }
7690 } )
7791
7892 const transformed = useMemo (
@@ -81,7 +95,7 @@ export const useXPAddresses = (
8195 )
8296
8397 return {
84- ...transformed ,
98+ ...( isKeystoneNonPrimary ? EMPTY_XP_ADDRESSES : transformed ) ,
8599 isLoading : queryResult . isLoading
86100 }
87101}
@@ -100,6 +114,11 @@ export async function getCachedXPAddresses({
100114 xpAddresses : string [ ]
101115 xpAddressDictionary : XPAddressDictionary
102116} > {
117+ // TODO: Remove this workaround once the Keystone SDK supports per-account XP xpubs.
118+ if ( walletType === WalletType . KEYSTONE && account . index > 0 ) {
119+ return EMPTY_XP_ADDRESSES
120+ }
121+
103122 try {
104123 const result = await queryClient . fetchQuery ( {
105124 staleTime : STALE_TIME ,
0 commit comments