Skip to content

Commit 57e5303

Browse files
committed
fix: fix mapping id to blockchain logo
1 parent cccaa23 commit 57e5303

File tree

8 files changed

+52
-62
lines changed

8 files changed

+52
-62
lines changed

wallets/core/src/legacy/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ interface NeedsNamespace {
8585
selection: 'single' | 'multiple';
8686
data: {
8787
label: string;
88+
/**
89+
* By using a matched `blockchain.name` (in meta) and `id`, we show logo in Namespace modal
90+
* e.g. ETH
91+
*/
8892
id: string;
8993
value: Namespace;
9094
}[];

wallets/provider-ledger/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
135135
{
136136
label: 'EVM',
137137
value: 'EVM',
138-
id: 'Ethereum',
138+
id: 'ETH',
139139
},
140140
{
141141
label: 'Solana',
142142
value: 'Solana',
143-
id: 'Solana',
143+
id: 'SOLANA',
144144
},
145145
],
146146
},

wallets/provider-phantom/src/legacy/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
109109
],
110110

111111
needsNamespace: {
112-
selection: 'single',
112+
selection: 'multiple',
113113
data: [
114114
{
115115
label: 'EVM',
116116
value: 'EVM',
117-
id: 'Ethereum',
117+
id: 'ETH',
118118
},
119119
{
120120
label: 'Solana',
121121
value: 'Solana',
122-
id: 'Solana',
122+
id: 'SOLANA',
123123
},
124124
],
125125
},

wallets/provider-trezor/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
102102
selection: 'single',
103103
data: [
104104
{
105-
id: 'EVM',
105+
id: 'ETH',
106106
value: 'EVM',
107107
label: 'Ethereum',
108108
},

wallets/react/src/hub/useHubAdapter.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -270,18 +270,23 @@ export function useHubAdapter(params: UseAdapterParams): ProviderContext {
270270
}
271271
});
272272

273+
const walletInfoFromLegacy = provider.getWalletInfo(
274+
params.allBlockChains || []
275+
);
276+
273277
return {
274278
name: info.name,
275279
img: info.icon,
276280
installLink: installLink,
277281
// We don't have this values anymore, fill them with some values that communicate this.
278282
color: 'red',
279-
supportedChains: provider.getWalletInfo(params.allBlockChains || [])
280-
.supportedChains,
283+
supportedChains: walletInfoFromLegacy.supportedChains,
281284
isContractWallet: false,
282285
mobileWallet: false,
283286
// if set to false here, it will not show the wallet in mobile in anyways. to be compatible with old behavior, undefined is more appropirate.
284287
showOnMobile: undefined,
288+
needsNamespace: walletInfoFromLegacy.needsNamespace,
289+
needsDerivationPath: walletInfoFromLegacy.needsDerivationPath,
285290

286291
isHub: true,
287292
properties: wallet.info()?.properties,

widget/embedded/src/components/WalletStatefulConnect/Namespaces.tsx

+30-37
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import {
1212
Radio,
1313
RadioRoot,
1414
} from '@rango-dev/ui';
15-
import { namespaces } from '@rango-dev/wallets-shared';
16-
import React, { useMemo, useState } from 'react';
15+
import React, { useState } from 'react';
1716

1817
import { useAppStore } from '../../store/AppStore';
1918
import { WalletImageContainer } from '../HeaderButtons/HeaderButtons.styles';
@@ -23,25 +22,14 @@ import { getBlockchainLogo } from './Namespaces.helpers';
2322
import { NamespaceList } from './Namespaces.styles';
2423

2524
export function Namespaces(props: PropTypes) {
26-
const { singleNamespace, availableNamespaces, providerImage } = props.value;
25+
const { targetWallet } = props.value;
26+
const singleNamespace = targetWallet.needsNamespace?.selection === 'single';
27+
const providerImage = targetWallet.image;
2728

2829
const [selectedNamespaces, setSelectedNamespaces] = useState<Namespace[]>([]);
2930

3031
const blockchains = useAppStore().blockchains();
3132

32-
const namespacesInfo = useMemo(
33-
() =>
34-
availableNamespaces?.map((namespace) => ({
35-
name: namespace,
36-
logo: getBlockchainLogo(
37-
blockchains,
38-
namespaces[namespace].mainBlockchain
39-
),
40-
title: namespaces[namespace].title,
41-
})),
42-
[availableNamespaces]
43-
);
44-
4533
const onSelect = (namespace: Namespace) => {
4634
if (singleNamespace) {
4735
setSelectedNamespaces([namespace]);
@@ -83,28 +71,33 @@ export function Namespaces(props: PropTypes) {
8371
<NamespaceList>
8472
{wrapRadioRoot(
8573
<>
86-
{namespacesInfo?.map((namespaceInfoItem) => (
87-
<ListItemButton
88-
key={namespaceInfoItem.name}
89-
id={namespaceInfoItem.name}
90-
title={namespaceInfoItem.title}
91-
hasDivider
92-
style={{ height: 60 }}
93-
onClick={() => onSelect(namespaceInfoItem.name)}
94-
start={<Image src={namespaceInfoItem.logo} size={22} />}
95-
end={
96-
singleNamespace ? (
97-
<Radio value={namespaceInfoItem.name} />
98-
) : (
99-
<Checkbox
100-
checked={selectedNamespaces.includes(
101-
namespaceInfoItem.name
102-
)}
74+
{targetWallet.needsNamespace?.data.map((ns) => {
75+
return (
76+
<ListItemButton
77+
key={ns.id}
78+
id={ns.id}
79+
title={ns.label}
80+
hasDivider
81+
style={{ height: 60 }}
82+
onClick={() => onSelect(ns.value)}
83+
start={
84+
<Image
85+
src={getBlockchainLogo(blockchains, ns.id)}
86+
size={22}
10387
/>
104-
)
105-
}
106-
/>
107-
))}
88+
}
89+
end={
90+
singleNamespace ? (
91+
<Radio value={ns.value} />
92+
) : (
93+
<Checkbox
94+
checked={selectedNamespaces.includes(ns.value)}
95+
/>
96+
)
97+
}
98+
/>
99+
);
100+
})}
108101
</>
109102
)}
110103
</NamespaceList>

widget/embedded/src/hooks/useStatefulConnect/useStatefulConnect.ts

+3-13
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,10 @@ export function useStatefulConnect(): UseStatefulConnect {
9797
detachedInstances && wallet.state !== 'connected';
9898

9999
if (needsNamespace) {
100-
const availableNamespaces = detachedInstances.value;
101-
102100
dispatch({
103101
type: 'needsNamespace',
104102
payload: {
105-
providerType: wallet.type,
106-
providerImage: wallet.image,
107-
availableNamespaces,
108-
singleNamespace: false,
103+
targetWallet: wallet,
109104
},
110105
});
111106
return { status: ResultStatus.Namespace };
@@ -131,12 +126,7 @@ export function useStatefulConnect(): UseStatefulConnect {
131126
dispatch({
132127
type: 'needsNamespace',
133128
payload: {
134-
providerType: wallet.type,
135-
providerImage: wallet.image,
136-
availableNamespaces: wallet.needsNamespace.data.map(
137-
(ns) => ns.value
138-
),
139-
singleNamespace: wallet.needsNamespace.selection === 'single',
129+
targetWallet: wallet,
140130
},
141131
});
142132
return { status: ResultStatus.Namespace };
@@ -215,7 +205,7 @@ export function useStatefulConnect(): UseStatefulConnect {
215205
);
216206
}
217207

218-
const type = connectState.namespace.providerType;
208+
const type = connectState.namespace.targetWallet.type;
219209
const namespaces = selectedNamespaces.map((namespace) => ({
220210
namespace,
221211
}));

widget/embedded/src/hooks/useStatefulConnect/useStatefulConnect.types.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ExtendedModalWalletInfo } from '../../utils/wallets';
12
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
23

34
export interface HandleConnectOptions {
@@ -6,10 +7,7 @@ export interface HandleConnectOptions {
67
}
78

89
export interface NeedsNamespacesState {
9-
providerType: string;
10-
providerImage: string;
11-
availableNamespaces?: Namespace[];
12-
singleNamespace?: boolean;
10+
targetWallet: ExtendedModalWalletInfo;
1311
}
1412

1513
export interface NeedsDerivationPathState {

0 commit comments

Comments
 (0)