Skip to content

Commit

Permalink
fix: fix mapping id to blockchain logo
Browse files Browse the repository at this point in the history
  • Loading branch information
yeager-eren committed Dec 16, 2024
1 parent a6d4c11 commit a45da11
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 62 deletions.
4 changes: 4 additions & 0 deletions wallets/core/src/legacy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ interface NeedsNamespace {
selection: 'single' | 'multiple';
data: {
label: string;
/**
* By using a matched `blockchain.name` (in meta) and `id`, we show logo in Namespace modal
* e.g. ETH
*/
id: string;
value: Namespace;
}[];
Expand Down
4 changes: 2 additions & 2 deletions wallets/provider-ledger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
{
label: 'EVM',
value: 'EVM',
id: 'Ethereum',
id: 'ETH',
},
{
label: 'Solana',
value: 'Solana',
id: 'Solana',
id: 'SOLANA',
},
],
},
Expand Down
6 changes: 3 additions & 3 deletions wallets/provider-phantom/src/legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,17 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
],

needsNamespace: {
selection: 'single',
selection: 'multiple',
data: [
{
label: 'EVM',
value: 'EVM',
id: 'Ethereum',
id: 'ETH',
},
{
label: 'Solana',
value: 'Solana',
id: 'Solana',
id: 'SOLANA',
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion wallets/provider-trezor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
selection: 'single',
data: [
{
id: 'EVM',
id: 'ETH',
value: 'EVM',
label: 'Ethereum',
},
Expand Down
9 changes: 7 additions & 2 deletions wallets/react/src/hub/useHubAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,23 @@ export function useHubAdapter(params: UseAdapterParams): ProviderContext {
}
});

const walletInfoFromLegacy = provider.getWalletInfo(
params.allBlockChains || []
);

return {
name: info.name,
img: info.icon,
installLink: installLink,
// We don't have this values anymore, fill them with some values that communicate this.
color: 'red',
supportedChains: provider.getWalletInfo(params.allBlockChains || [])
.supportedChains,
supportedChains: walletInfoFromLegacy.supportedChains,
isContractWallet: false,
mobileWallet: false,
// 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.
showOnMobile: undefined,
needsNamespace: walletInfoFromLegacy.needsNamespace,
needsDerivationPath: walletInfoFromLegacy.needsDerivationPath,

isHub: true,
properties: wallet.info()?.properties,
Expand Down
67 changes: 30 additions & 37 deletions widget/embedded/src/components/WalletStatefulConnect/Namespaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
Radio,
RadioRoot,
} from '@rango-dev/ui';
import { namespaces } from '@rango-dev/wallets-shared';
import React, { useMemo, useState } from 'react';
import React, { useState } from 'react';

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

export function Namespaces(props: PropTypes) {
const { singleNamespace, availableNamespaces, providerImage } = props.value;
const { targetWallet } = props.value;
const singleNamespace = targetWallet.needsNamespace?.selection === 'single';
const providerImage = targetWallet.image;

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

const blockchains = useAppStore().blockchains();

const namespacesInfo = useMemo(
() =>
availableNamespaces?.map((namespace) => ({
name: namespace,
logo: getBlockchainLogo(
blockchains,
namespaces[namespace].mainBlockchain
),
title: namespaces[namespace].title,
})),
[availableNamespaces]
);

const onSelect = (namespace: Namespace) => {
if (singleNamespace) {
setSelectedNamespaces([namespace]);
Expand Down Expand Up @@ -83,28 +71,33 @@ export function Namespaces(props: PropTypes) {
<NamespaceList>
{wrapRadioRoot(
<>
{namespacesInfo?.map((namespaceInfoItem) => (
<ListItemButton
key={namespaceInfoItem.name}
id={namespaceInfoItem.name}
title={namespaceInfoItem.title}
hasDivider
style={{ height: 60 }}
onClick={() => onSelect(namespaceInfoItem.name)}
start={<Image src={namespaceInfoItem.logo} size={22} />}
end={
singleNamespace ? (
<Radio value={namespaceInfoItem.name} />
) : (
<Checkbox
checked={selectedNamespaces.includes(
namespaceInfoItem.name
)}
{targetWallet.needsNamespace?.data.map((ns) => {
return (
<ListItemButton
key={ns.id}
id={ns.id}
title={ns.label}
hasDivider
style={{ height: 60 }}
onClick={() => onSelect(ns.value)}
start={
<Image
src={getBlockchainLogo(blockchains, ns.id)}
size={22}
/>
)
}
/>
))}
}
end={
singleNamespace ? (
<Radio value={ns.value} />
) : (
<Checkbox
checked={selectedNamespaces.includes(ns.value)}
/>
)
}
/>
);
})}
</>
)}
</NamespaceList>
Expand Down
16 changes: 3 additions & 13 deletions widget/embedded/src/hooks/useStatefulConnect/useStatefulConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,10 @@ export function useStatefulConnect(): UseStatefulConnect {
detachedInstances && wallet.state !== 'connected';

if (needsNamespace) {
const availableNamespaces = detachedInstances.value;

dispatch({
type: 'needsNamespace',
payload: {
providerType: wallet.type,
providerImage: wallet.image,
availableNamespaces,
singleNamespace: false,
targetWallet: wallet,
},
});
return { status: ResultStatus.Namespace };
Expand All @@ -131,12 +126,7 @@ export function useStatefulConnect(): UseStatefulConnect {
dispatch({
type: 'needsNamespace',
payload: {
providerType: wallet.type,
providerImage: wallet.image,
availableNamespaces: wallet.needsNamespace.data.map(
(ns) => ns.value
),
singleNamespace: wallet.needsNamespace.selection === 'single',
targetWallet: wallet,
},
});
return { status: ResultStatus.Namespace };
Expand Down Expand Up @@ -215,7 +205,7 @@ export function useStatefulConnect(): UseStatefulConnect {
);
}

const type = connectState.namespace.providerType;
const type = connectState.namespace.targetWallet.type;
const namespaces = selectedNamespaces.map((namespace) => ({
namespace,
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ExtendedModalWalletInfo } from '../../utils/wallets';
import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';

export interface HandleConnectOptions {
Expand All @@ -6,10 +7,7 @@ export interface HandleConnectOptions {
}

export interface NeedsNamespacesState {
providerType: string;
providerImage: string;
availableNamespaces?: Namespace[];
singleNamespace?: boolean;
targetWallet: ExtendedModalWalletInfo;
}

export interface NeedsDerivationPathState {
Expand Down

0 comments on commit a45da11

Please sign in to comment.