Skip to content

Commit

Permalink
Fixed immutablex fixed solana displayname&logo
Browse files Browse the repository at this point in the history
  • Loading branch information
babkenmes committed Dec 13, 2024
1 parent 0e7e98f commit 33b9198
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Models/WalletProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type Wallet = {


export type WalletProvider = {
connectWallet: (props?: { chain?: string | number | undefined | null, destination?: RouteNetwork }) => Promise<Wallet | undefined>,
connectWallet: () => Promise<Wallet | undefined>,
connectConnector?: (props?: { connector: InternalConnector }) => Promise<Wallet | undefined> | undefined
disconnectWallets: () => Promise<void> | undefined | void,
switchAccount?: (connector: Wallet, address: string) => Promise<void>
Expand Down
2 changes: 1 addition & 1 deletion components/Campaigns/Details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ConnectWalletButton: FC<Props> = ({ 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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ConnectedWallets: FC<Props> = ({ 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)
}
Expand Down
3 changes: 1 addition & 2 deletions components/Input/SourceWalletPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion components/Swap/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const SwapForm: FC<Props> = ({ 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
Expand Down
2 changes: 1 addition & 1 deletion components/Swap/Withdraw/Wallet/WalletTransfer/buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const ConnectWalletButton: FC<SubmitButtonProps> = ({ ...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)
Expand Down
4 changes: 2 additions & 2 deletions components/Swap/Withdraw/Wallet/paradex/buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const ConnectWalletButton: FC<ConnectProps> = ({ 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) {
Expand Down
20 changes: 9 additions & 11 deletions lib/wallets/imtblX/useImtblX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -19,20 +19,18 @@ 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) {
return [wallet]
}
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
Expand All @@ -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,
Expand All @@ -63,7 +61,7 @@ export default function useImtblX(): WalletProvider {
}

const disconnectWallet = () => {
return removeWallet(name)
return removeWallet(id)
}

return {
Expand Down
8 changes: 4 additions & 4 deletions lib/wallets/solana/useSolana.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 33b9198

Please sign in to comment.