Skip to content

Commit

Permalink
fix: fix wallet button state in swap details page
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikari-Shinji-re committed Dec 9, 2023
1 parent b28a984 commit 8f26453
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
import type { WalletStateContentProps } from './SwapDetailsModal.types';

import { MessageBox, Wallet, WalletState } from '@rango-dev/ui';
import { MessageBox, Wallet } from '@rango-dev/ui';
import { useWallets } from '@rango-dev/wallets-react';
import React from 'react';

import { getContainer } from '../../utils/common';
import { mapStatusToWalletState } from '../../utils/wallets';

import { WalletContainer } from './SwapDetailsModal.styles';

export const WalletStateContent = (props: WalletStateContentProps) => {
const { type, title, currentStepWallet, message, showWalletButton } = props;
const { connect, getWalletInfo, state: walletState } = useWallets();
const { connect, getWalletInfo, state } = useWallets();
const walletType = currentStepWallet?.walletType;
const isConnected = walletType && walletState(walletType).connected;
const state = isConnected ? WalletState.CONNECTED : WalletState.DISCONNECTED;
const walletState = !!walletType && mapStatusToWalletState(state(walletType));
const walletInfo = !!walletType && getWalletInfo(walletType);
const shouldShowWallet = showWalletButton && walletState && walletInfo;
return (
<>
<MessageBox type={type} title={title} description={message} />
{showWalletButton && walletType && (
{shouldShowWallet && (
<WalletContainer>
<Wallet
container={getContainer()}
title={getWalletInfo(walletType).name}
image={getWalletInfo(walletType).img}
title={walletInfo.name}
image={walletInfo.img}
type={walletType}
state={state}
state={walletState}
link={walletInfo.installLink}
onClick={async () => connect(walletType)}
/>
</WalletContainer>
Expand Down
26 changes: 3 additions & 23 deletions widget/ui/src/components/Wallet/Wallet.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,18 @@ export interface Info {
tooltipText: string;
}

interface StateConnected {
state: WalletState.CONNECTED;
}
interface StateDisconnected {
state: WalletState.DISCONNECTED;
}
interface StateConnecting {
state: WalletState.CONNECTING;
}
interface StateNotInstalled {
state: WalletState.NOT_INSTALLED;
link: InstallObjects | string;
}

type State =
| StateConnected
| StateDisconnected
| StateConnecting
| StateNotInstalled;

export interface ContentProps {
image: string;
title: string;
description: string;
descriptionColor?: string;
}

interface WalletProps {
export interface WalletPropTypes {
state: WalletState;
title: string;
image: string;
link: InstallObjects | string;
type: WalletType;
onClick: (type: WalletType) => void;
selected?: boolean;
Expand All @@ -59,8 +41,6 @@ interface WalletProps {
container?: HTMLElement;
}

export type WalletPropTypes = State & WalletProps;

export type SelectablePropTypes = WalletPropTypes & {
selected: boolean;
};

0 comments on commit 8f26453

Please sign in to comment.