From 33b9198acb5d6ccc8572d9fff7396e7493f31928 Mon Sep 17 00:00:00 2001 From: babkenmes Date: Fri, 13 Dec 2024 19:46:00 +0400 Subject: [PATCH] Fixed immutablex fixed solana displayname&logo --- Models/WalletProvider.ts | 2 +- components/Campaigns/Details/index.tsx | 2 +- .../ConnectedWallets/ConnectWalletButton.tsx | 2 +- .../AddressPicker/ConnectedWallets/index.tsx | 2 +- components/Input/SourceWalletPicker.tsx | 3 +-- components/Swap/Form/Form.tsx | 2 +- .../Wallet/WalletTransfer/buttons.tsx | 2 +- .../Swap/Withdraw/Wallet/paradex/buttons.tsx | 4 ++-- lib/wallets/imtblX/useImtblX.ts | 20 +++++++++---------- lib/wallets/solana/useSolana.tsx | 8 ++++---- 10 files changed, 22 insertions(+), 25 deletions(-) diff --git a/Models/WalletProvider.ts b/Models/WalletProvider.ts index a9c83f780..7a446c4a7 100644 --- a/Models/WalletProvider.ts +++ b/Models/WalletProvider.ts @@ -39,7 +39,7 @@ export type Wallet = { export type WalletProvider = { - connectWallet: (props?: { chain?: string | number | undefined | null, destination?: RouteNetwork }) => Promise, + connectWallet: () => Promise, connectConnector?: (props?: { connector: InternalConnector }) => Promise | undefined disconnectWallets: () => Promise | undefined | void, switchAccount?: (connector: Wallet, address: string) => Promise diff --git a/components/Campaigns/Details/index.tsx b/components/Campaigns/Details/index.tsx index fc757c27f..c6efdc40d 100644 --- a/components/Campaigns/Details/index.tsx +++ b/components/Campaigns/Details/index.tsx @@ -26,7 +26,7 @@ function CampaignDetails() { const { provider } = useWallet(network, 'autofil') const handleConnect = useCallback(async () => { - await provider?.connectWallet({ chain: network?.chain_id }) + await provider?.connectWallet() }, [provider, network]) const wallet = provider?.activeWallet diff --git a/components/Input/Address/AddressPicker/ConnectedWallets/ConnectWalletButton.tsx b/components/Input/Address/AddressPicker/ConnectedWallets/ConnectWalletButton.tsx index e66b53306..22c86e5c8 100644 --- a/components/Input/Address/AddressPicker/ConnectedWallets/ConnectWalletButton.tsx +++ b/components/Input/Address/AddressPicker/ConnectedWallets/ConnectWalletButton.tsx @@ -16,7 +16,7 @@ const ConnectWalletButton: FC = ({ provider, onConnect, destination }) => const connect = async () => { setIsLoading(true) - const result = await provider.connectWallet({ chain: destination.chain_id }) + const result = await provider.connectWallet() if (onConnect && result) onConnect(result) setIsLoading(false) } diff --git a/components/Input/Address/AddressPicker/ConnectedWallets/index.tsx b/components/Input/Address/AddressPicker/ConnectedWallets/index.tsx index 10adfee80..7822cedbb 100644 --- a/components/Input/Address/AddressPicker/ConnectedWallets/index.tsx +++ b/components/Input/Address/AddressPicker/ConnectedWallets/index.tsx @@ -26,7 +26,7 @@ const ConnectedWallets: FC = ({ provider, wallets, onClick, onConnect, de const connect = async () => { setIsLoading(true) - const result = await provider.connectWallet({ chain: destination.chain_id }) + const result = await provider.connectWallet() if (onConnect && result) onConnect(result) setIsLoading(false) } diff --git a/components/Input/SourceWalletPicker.tsx b/components/Input/SourceWalletPicker.tsx index 77ccd8918..f81917941 100644 --- a/components/Input/SourceWalletPicker.tsx +++ b/components/Input/SourceWalletPicker.tsx @@ -170,8 +170,7 @@ export const FormSourceWalletButton: FC = () => { const connect = async () => { setMounWalletPortal(true) - const result = await provider?.connectWallet({ chain: walletNetwork?.chain_id || walletNetwork?.name }) - + const result = await provider?.connectWallet() if (result) { handleSelectWallet(result, result.address) } diff --git a/components/Swap/Form/Form.tsx b/components/Swap/Form/Form.tsx index 607f67895..ac6eacf3a 100644 --- a/components/Swap/Form/Form.tsx +++ b/components/Swap/Form/Form.tsx @@ -57,7 +57,7 @@ const SwapForm: FC = ({ partner }) => { const { selectedSourceAccount } = useSwapDataState() const { setSelectedSourceAccount } = useSwapDataUpdate() const { providers, wallets } = useWallet() - + console.log(providers, wallets) const { minAllowedAmount, valuesChanger } = useFee() const toAsset = values.toCurrency const fromAsset = values.fromCurrency diff --git a/components/Swap/Withdraw/Wallet/WalletTransfer/buttons.tsx b/components/Swap/Withdraw/Wallet/WalletTransfer/buttons.tsx index 54cdc10bf..f080e81c4 100644 --- a/components/Swap/Withdraw/Wallet/WalletTransfer/buttons.tsx +++ b/components/Swap/Withdraw/Wallet/WalletTransfer/buttons.tsx @@ -24,7 +24,7 @@ export const ConnectWalletButton: FC = ({ ...props }) => { if (!provider) throw new Error(`No provider from ${source_network?.name}`) - await provider.connectWallet({ chain: source_network?.chain_id || source_network?.name }) + await provider.connectWallet() } catch (e) { toast.error(e.message) diff --git a/components/Swap/Withdraw/Wallet/paradex/buttons.tsx b/components/Swap/Withdraw/Wallet/paradex/buttons.tsx index 95cfc09f1..0e879db7d 100644 --- a/components/Swap/Withdraw/Wallet/paradex/buttons.tsx +++ b/components/Swap/Withdraw/Wallet/paradex/buttons.tsx @@ -27,8 +27,8 @@ export const ConnectWalletButton: FC = ({ network, text, icon, onC try { onClick && onClick() if (!provider) throw new Error(`No provider from ${network?.name}`) - - await provider.connectWallet({ chain: network?.chain_id }) + + await provider.connectWallet() onConnect && onConnect() } catch (e) { diff --git a/lib/wallets/imtblX/useImtblX.ts b/lib/wallets/imtblX/useImtblX.ts index c83e32f99..52abe2120 100644 --- a/lib/wallets/imtblX/useImtblX.ts +++ b/lib/wallets/imtblX/useImtblX.ts @@ -2,7 +2,7 @@ import { useWalletStore } from "../../../stores/walletStore" import ImtblClient from "../../imtbl" import KnownInternalNames from "../../knownIds" import IMX from "../../../components/icons/Wallets/IMX" -import { WalletProvider } from "../../../Models/WalletProvider" +import { Wallet, WalletProvider } from "../../../Models/WalletProvider" import { useSettingsState } from "../../../context/settings" export default function useImtblX(): WalletProvider { @@ -19,7 +19,7 @@ export default function useImtblX(): WalletProvider { const wallets = useWalletStore((state) => state.connectedWallets) const addWallet = useWalletStore((state) => state.connectWallet) const removeWallet = useWalletStore((state) => state.disconnectWallet) - const wallet = wallets.find(wallet => wallet.providerName === name) + const wallet = wallets.find(wallet => wallet.providerName === id) const getWallet = () => { if (wallet) { @@ -27,12 +27,10 @@ export default function useImtblX(): WalletProvider { } return undefined } - type ConnectProps = { - chain?: string | number - } - const connectWallet = async ({ chain }: ConnectProps) => { + + const connectWallet = async () => { const isMainnet = networks?.some(network => network.name === KnownInternalNames.Networks.ImmutableXMainnet) - chain = chain || (isMainnet ? KnownInternalNames.Networks.ImmutableXMainnet : KnownInternalNames.Networks.ImmutableXGoerli) + const chain = (isMainnet ? KnownInternalNames.Networks.ImmutableXMainnet : KnownInternalNames.Networks.ImmutableXGoerli) if (!chain) throw new Error('No chain id for imx connect wallet') const networkName = chain == 'testnet' ? KnownInternalNames.Networks.ImmutableXGoerli : KnownInternalNames.Networks.ImmutableXMainnet @@ -41,13 +39,13 @@ export default function useImtblX(): WalletProvider { const imtblClient = new ImtblClient(networkName) const res = await imtblClient.ConnectWallet(); - const wallet = { + const wallet: Wallet = { + id: 'immutablex', + displayName: name, address: res.address, - connector: name, providerName: id, icon: IMX, disconnect: () => disconnectWallet(), - connect: () => connectWallet({ chain }), isActive: true, addresses: [res.address], withdrawalSupportedNetworks, @@ -63,7 +61,7 @@ export default function useImtblX(): WalletProvider { } const disconnectWallet = () => { - return removeWallet(name) + return removeWallet(id) } return { diff --git a/lib/wallets/solana/useSolana.tsx b/lib/wallets/solana/useSolana.tsx index aa1127fc5..28d86645c 100644 --- a/lib/wallets/solana/useSolana.tsx +++ b/lib/wallets/solana/useSolana.tsx @@ -36,7 +36,7 @@ export default function useSolana({ network }: { network: Network | undefined }) const wallet: Wallet | undefined = (connectedAddress && connectedAdapterName) ? { id: connectedAdapterName, address: connectedAddress, - displayName: `${connectedAdapterName} - Solana`, + displayName: `${connectedAdapterName} - ${network?.name || 'Solana'}`, providerName: name, icon: resolveWalletConnectorIcon({ connector: String(connectedAdapterName), address: connectedAddress, iconUrl: connectedWallet?.adapter.icon }), disconnect, @@ -46,7 +46,7 @@ export default function useSolana({ network }: { network: Network | undefined }) withdrawalSupportedNetworks: commonSupportedNetworks, asSourceSupportedNetworks: commonSupportedNetworks, autofillSupportedNetworks: commonSupportedNetworks, - networkIcon: networks.find(n => solanaNames.some(name => name === n.name))?.logo, + networkIcon: networks.find(n => network ? n.name === network.name : solanaNames.some(name => name === n.name))?.logo } : undefined if (wallet) { @@ -77,7 +77,7 @@ export default function useSolana({ network }: { network: Network | undefined }) const wallet: Wallet | undefined = connectedAddress && connectedWallet ? { id: connectedWallet.adapter.name, address: connectedAddress, - displayName: `${connectedWallet?.adapter.name} - Solana`, + displayName: `${connectedWallet?.adapter.name} - ${network?.name || 'Solana'}`, providerName: name, icon: resolveWalletConnectorIcon({ connector: String(connectedWallet?.adapter.name), address: connectedAddress, iconUrl: connectedWallet?.adapter.icon }), disconnect, @@ -87,7 +87,7 @@ export default function useSolana({ network }: { network: Network | undefined }) withdrawalSupportedNetworks: commonSupportedNetworks, asSourceSupportedNetworks: commonSupportedNetworks, autofillSupportedNetworks: commonSupportedNetworks, - networkIcon: networks.find(n => solanaNames.some(name => name === n.name))?.logo + networkIcon: networks.find(n => network ? n.name === network.name : solanaNames.some(name => name === n.name))?.logo } : undefined return wallet