Skip to content

Commit

Permalink
feat: add more props to wallet connected event
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Sep 25, 2024
1 parent 38a7a7d commit f195165
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
18 changes: 11 additions & 7 deletions packages/wallet-management/src/components/EVMListItemButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export const EVMListItemButton = ({
const config = useConfig();
const { setLastConnectedAccount } = useLastConnectedAccount();

const connectorName =
(connector as CreateConnectorFnExtended).displayName || connector.name;
const connectorDisplayName: string = ecosystemSelection
? 'Ethereum'
: connectorName;

const handleEVMConnect = async () => {
try {
const identityCheckPassed = await isWalletInstalledAsync(
Expand All @@ -49,17 +55,15 @@ export const EVMListItemButton = ({
address: data.accounts[0],
chainId: data.chainId,
chainType: ChainType.EVM,
connectorId: connector.id,
connectorName: connectorName,
});
onConnected?.();
} catch (error) {
onError?.(error);
}
};

const connectorName: string = ecosystemSelection
? 'Ethereum'
: (connector as CreateConnectorFnExtended).displayName || connector.name;

return (
<ListItemButton key={connector.id} onClick={handleEVMConnect}>
<ListItemAvatar>
Expand All @@ -69,12 +73,12 @@ export const EVMListItemButton = ({
? 'https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/chains/ethereum.svg'
: getConnectorIcon(connector as Connector)
}
alt={connectorName}
alt={connectorDisplayName}
>
{connectorName?.[0]}
{connectorDisplayName?.[0]}
</Avatar>
</ListItemAvatar>
<ListItemText primary={connectorName} />
<ListItemText primary={connectorDisplayName} />
</ListItemButton>
);
};
19 changes: 11 additions & 8 deletions packages/wallet-management/src/components/SVMListItemButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export const SVMListItemButton = ({
const { select, disconnect, connected } = useWallet();
const { setLastConnectedAccount } = useLastConnectedAccount();

const connectorName = walletAdapter.name;
const connectorDisplayName: string = ecosystemSelection
? 'Solana'
: walletAdapter.name;

const connect = async () => {
try {
onConnecting?.();
Expand All @@ -39,6 +44,8 @@ export const SVMListItemButton = ({
address: publicKey?.toString(),
chainId: ChainId.SOL,
chainType: ChainType.SVM,
connectorId: connectorName,
connectorName: connectorName,
});
});
onConnected?.();
Expand All @@ -47,25 +54,21 @@ export const SVMListItemButton = ({
}
};

const connectorName: string = ecosystemSelection
? 'Solana'
: walletAdapter.name;

return (
<ListItemButton key={connectorName} onClick={connect}>
<ListItemButton key={connectorDisplayName} onClick={connect}>
<ListItemAvatar>
<Avatar
src={
ecosystemSelection
? 'https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/chains/solana.svg'
: walletAdapter.icon
}
alt={connectorName}
alt={connectorDisplayName}
>
{connectorName[0]}
{connectorDisplayName[0]}
</Avatar>
</ListItemAvatar>
<ListItemText primary={connectorName} />
<ListItemText primary={connectorDisplayName} />
</ListItemButton>
);
};
18 changes: 11 additions & 7 deletions packages/wallet-management/src/components/UTXOListItemButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export const UTXOListItemButton = ({
const config = useConfig();
const { setLastConnectedAccount } = useLastConnectedAccount();

const connectorName =
(connector as CreateConnectorFnExtended).displayName || connector.name;
const connectorDisplayName: string = ecosystemSelection
? 'Bitcoin'
: connectorName;

const handleUTXOConnect = async () => {
try {
const identityCheckPassed = await isWalletInstalledAsync(
Expand All @@ -49,17 +55,15 @@ export const UTXOListItemButton = ({
address: data.accounts[0],
chainId: data.chainId,
chainType: ChainType.UTXO,
connectorId: connector.id,
connectorName: connectorName,
});
onConnected?.();
} catch (error) {
onError?.(error);
}
};

const connectorName: string = ecosystemSelection
? 'Bitcoin'
: (connector as CreateConnectorFnExtended).displayName || connector.name;

return (
<ListItemButton key={connector.id} onClick={handleUTXOConnect}>
<ListItemAvatar>
Expand All @@ -69,12 +73,12 @@ export const UTXOListItemButton = ({
? 'https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/chains/bitcoin.svg'
: getConnectorIcon(connector as Connector)
}
alt={connectorName}
alt={connectorDisplayName}
>
{connectorName?.[0]}
{connectorDisplayName?.[0]}
</Avatar>
</ListItemAvatar>
<ListItemText primary={connectorName} />
<ListItemText primary={connectorDisplayName} />
</ListItemButton>
);
};
8 changes: 5 additions & 3 deletions packages/wallet-management/src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export type WalletManagementEvents = {
};

export interface WalletConnected {
address?: string;
chainId?: number;
chainType?: ChainType;
address: string;
chainId: number;
chainType: ChainType;
connectorId: string;
connectorName: string;
}

0 comments on commit f195165

Please sign in to comment.