Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix wallet button state in swap details page #467

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
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))
: null;
const walletInfo = walletType ? getWalletInfo(walletType) : null;
const shouldShowWallet =
showWalletButton && !!walletType && !!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;
};