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

Refactor flows to pages and modals, Add Aliases #180

Merged
merged 4 commits into from
Aug 20, 2024
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
16 changes: 8 additions & 8 deletions packages/widget-v2/src/components/AssetChainInput.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { styled } from 'styled-components';
import { Column, Row, Spacer } from './Layout';
import { SmallText, Text } from './Typography';
import { ChevronIcon } from '../icons/ChevronIcon';
import { Column, Row, Spacer } from '@/components/Layout';
import { SmallText, Text } from '@/components/Typography';
import { ChevronIcon } from '@/icons/ChevronIcon';
import { useTheme } from 'styled-components';
import { CogIcon } from '../icons/CogIcon';
import { Button, GhostButton } from './Button';
import { CogIcon } from '@/icons/CogIcon';
import { Button, GhostButton } from '@/components/Button';
import { useAtom } from 'jotai';
import { skipAssets } from '../state/skip';
import { useUsdValue } from '../utils/useUsdValue';
import { formatUSD } from '../utils/intl';
import { skipAssets } from '@/state/skip';
import { useUsdValue } from '@/utils/useUsdValue';
import { formatUSD } from '@/utils/intl';

export type AssetChainInputProps = {
value?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/widget-v2/src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { css, styled } from 'styled-components';
import { FlexProps, flexProps } from './Layout';
import { removeButtonStyles, SmallText } from './Typography';
import { FlexProps, flexProps } from '@/components/Layout';
import { removeButtonStyles, SmallText } from '@/components/Typography';

export type GhostButtonProps = {
secondary?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions packages/widget-v2/src/components/ErrorState.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { styled, useTheme } from 'styled-components';
import { Column } from './Layout';
import { iconMap, ICONS } from '../icons';
import { SmallText, Text } from './Typography';
import { Column } from '@/components/Layout';
import { iconMap, ICONS } from '@/icons';
import { SmallText, Text } from '@/components/Typography';

export type ErrorStateProps = {
icon?: ICONS;
Expand Down
8 changes: 4 additions & 4 deletions packages/widget-v2/src/components/MainButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { styled } from 'styled-components';
import { Row } from './Layout';
import { SmallText, Text } from './Typography';
import { Row } from '@/components/Layout';
import { SmallText, Text } from '@/components/Typography';
import { useTheme } from 'styled-components';
import { ICONS, iconMap } from '../icons';
import { getBrandButtonTextColor } from '../utils/colors';
import { ICONS, iconMap } from '@/icons';
import { getBrandButtonTextColor } from '@/utils/colors';

export type MainButtonProps = {
label: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/widget-v2/src/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { css, styled } from 'styled-components';
import * as Dialog from '@radix-ui/react-dialog';
import { ShadowDomAndProviders } from '../widget/ShadowDomAndProviders';
import { ShadowDomAndProviders } from '@/widget/ShadowDomAndProviders';
import { useModal } from '@ebay/nice-modal-react';
import { useEffect } from 'react';
import { PartialTheme } from '../widget/theme';
import { PartialTheme } from '@/widget/theme';

export type ModalProps = {
children: React.ReactNode;
Expand Down
4 changes: 2 additions & 2 deletions packages/widget-v2/src/components/ModalRowItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { css, styled } from 'styled-components';
import { Row } from './Layout';
import { removeButtonStyles, Text } from './Typography';
import { Row } from '@/components/Layout';
import { removeButtonStyles, Text } from '@/components/Typography';

export type ModalRowItemProps = {
leftContent?: React.ReactNode;
Expand Down
10 changes: 5 additions & 5 deletions packages/widget-v2/src/components/RenderWalletList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useCallback, useMemo } from 'react';
import styled, { useTheme } from 'styled-components';
import { LeftArrowIcon } from '../icons/ArrowIcon';
import { hashObject } from '../utils/misc';
import { Button } from './Button';
import { Row, Column } from './Layout';
import { LeftArrowIcon } from '@/icons/ArrowIcon';
import { hashObject } from '@/utils/misc';
import { Button } from '@/components/Button';
import { Row, Column } from '@/components/Layout';
import { ModalRowItem } from './ModalRowItem';
import { VirtualList } from './VirtualList';
import { Text } from '../components/Typography';
import { Text } from '@/components/Typography';

export type RenderWalletListProps = {
title: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/widget-v2/src/components/Skeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { css, styled } from 'styled-components';
import { getHexColor, opacityToHex } from '../utils/colors';
import { getHexColor, opacityToHex } from '@/utils/colors';

export const SkeletonElement = styled.div<{
width: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/widget-v2/src/components/Typography.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { css, styled } from 'styled-components';
import { getBrandButtonTextColor } from '../utils/colors';
import { getBrandButtonTextColor } from '@/utils/colors';

type TextProps = {
fontSize?: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/widget-v2/src/components/VirtualList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import List from 'rc-virtual-list';
import { getHexColor, opacityToHex } from '../utils/colors';
import { getHexColor, opacityToHex } from '@/utils/colors';
import { useTheme } from 'styled-components';

export type VirtualListProps<T> = {
Expand Down
2 changes: 1 addition & 1 deletion packages/widget-v2/src/icons/ArrowIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { withBoundProps } from '../utils/misc';
import { withBoundProps } from '@/utils/misc';

type IconProps = {
color?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import NiceModal, { useModal } from '@ebay/nice-modal-react';
import { Modal, ModalProps } from '../../components/Modal';
import { Column, Row } from '../../components/Layout';
import { Modal, ModalProps } from '@/components/Modal';
import { Column, Row } from '@/components/Layout';
import { css, styled } from 'styled-components';
import { useCallback, useMemo, useState } from 'react';
import { RightArrowIcon } from '../../icons/ArrowIcon';
import { RightArrowIcon } from '@/icons/ArrowIcon';
import {
RenderWalletList,
RenderWalletListHeader,
Wallet,
} from '../../components/RenderWalletList';
import { WALLET_LIST } from '../WalletSelectorFlow/WalletSelectorFlow';
import { Button } from '../../components/Button';
import { SmallText, Text } from '../../components/Typography';
import { destinationAssetAtom, destinationWalletAtom } from '../../state/swap';
} from '@/components/RenderWalletList';
import { WALLET_LIST } from '@/modals/WalletSelectorModal/WalletSelectorFlow';
import { Button } from '@/components/Button';
import { SmallText, Text } from '@/components/Typography';
import { destinationAssetAtom, destinationWalletAtom } from '@/state/swap';
import { useAtom } from 'jotai';
import { getChain } from '../../state/skip';
import { getChain } from '@/state/skip';

export const ManualAddressFlow = NiceModal.create((modalProps: ModalProps) => {
export const ManualAddressModal = NiceModal.create((modalProps: ModalProps) => {
const { theme } = modalProps;
const modal = useModal();
const [destinationAsset] = useAtom(destinationAssetAtom);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import NiceModal, { useModal } from '@ebay/nice-modal-react';
import { Modal, ModalProps } from '../../components/Modal';
import { Column } from '../../components/Layout';
import { Modal, ModalProps } from '@/components/Modal';
import { Column } from '@/components/Layout';
import { styled } from 'styled-components';
import { useAtom } from 'jotai';
import { ChainWithAsset, ClientAsset, skipAssets } from '../../state/skip';
import { ChainWithAsset, ClientAsset, skipAssets } from '@/state/skip';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { VirtualList } from '../../components/VirtualList';
import { VirtualList } from '@/components/VirtualList';
import {
isChainWithAsset,
RowItem,
TokenAndChainSelectorModalRowItem,
Skeleton,
} from './TokenAndChainSelectorFlowRowItem';
import { SearchInput } from './TokenAndChainSelectorFlowSearchInput';
} from './TokenAndChainSelectorModalRowItem';
import { TokenAndChainSelectorModalSearchInput } from './TokenAndChainSelectorModalSearchInput';

export type TokenAndChainSelectorFlowProps = ModalProps & {
export type TokenAndChainSelectorModalProps = ModalProps & {
onSelect: (token: ClientAsset | null) => void;
chainsContainingAsset?: ChainWithAsset[];
asset?: Partial<ClientAsset>;
};

export const TokenAndChainSelectorFlow = NiceModal.create(
(modalProps: TokenAndChainSelectorFlowProps) => {
export const TokenAndChainSelectorModal = NiceModal.create(
(modalProps: TokenAndChainSelectorModalProps) => {
const modal = useModal();
const { onSelect, chainsContainingAsset, asset } = modalProps;
const [{ data: assets, isPending }] = useAtom(skipAssets);
Expand Down Expand Up @@ -66,7 +66,7 @@ export const TokenAndChainSelectorFlow = NiceModal.create(
const renderItem = useCallback(
(asset: ClientAsset | ChainWithAsset, index: number) => {
return (
<RowItem
<TokenAndChainSelectorModalRowItem
item={asset}
index={index}
onSelect={onSelect}
Expand All @@ -80,7 +80,10 @@ export const TokenAndChainSelectorFlow = NiceModal.create(
return (
<Modal {...modalProps}>
<StyledContainer>
<SearchInput onSearch={handleSearch} asset={asset} />
<TokenAndChainSelectorModalSearchInput
onSearch={handleSearch}
asset={asset}
/>
{showSkeleton || (!filteredAssets && !filteredChains) ? (
<Column>
{Array.from({ length: 10 }, (_, index) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import { Row } from '../../components/Layout';
import { ModalRowItem } from '../../components/ModalRowItem';
import { SmallText, Text } from '../../components/Typography';
import { ChainWithAsset, ClientAsset } from '../../state/skip';
import {
CircleSkeletonElement,
SkeletonElement,
} from '../../components/Skeleton';
import { Row } from '@/components/Layout';
import { ModalRowItem } from '@/components/ModalRowItem';
import { SmallText, Text } from '@/components/Typography';
import { ChainWithAsset, ClientAsset } from '@/state/skip';
import { CircleSkeletonElement, SkeletonElement } from '@/components/Skeleton';
import { styled } from 'styled-components';
import { Chain } from '@chain-registry/types';

export type RowItemType = {
item: ClientAsset | ChainWithAsset;
index: number;
skeleton: React.ReactElement;
onSelect: (token: ClientAsset | null) => void;
};

export const isClientAsset = (
item: ClientAsset | ChainWithAsset
): item is ClientAsset => {
Expand All @@ -28,7 +18,19 @@ export const isChainWithAsset = (
return (item as Chain).chain_id !== undefined;
};

export const RowItem = ({ item, index, skeleton, onSelect }: RowItemType) => {
export type TokenAndChainSelectorModalRowItemProps = {
item: ClientAsset | ChainWithAsset;
index: number;
skeleton: React.ReactElement;
onSelect: (token: ClientAsset | null) => void;
};

export const TokenAndChainSelectorModalRowItem = ({
item,
index,
skeleton,
onSelect,
}: TokenAndChainSelectorModalRowItemProps) => {
if (!item) return skeleton;

if (isClientAsset(item)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import React, { useState, useCallback, useEffect, useRef } from 'react';
import { styled, useTheme } from 'styled-components';
import { Row } from '../../components/Layout';
import { SkipLogoIcon } from '../../icons/SkipLogoIcon';
import { SmallText } from '../../components/Typography';
import { SearchIcon } from '../../icons/SearchIcon.tsx';
import { StyledAssetLabel } from '../../components/AssetChainInput.tsx';
import { ClientAsset } from '../../state/skip.ts';
import { LeftArrowIcon } from '../../icons/ArrowIcon.tsx';
import { Row } from '@/components/Layout';
import { SkipLogoIcon } from '@/icons/SkipLogoIcon';
import { SmallText } from '@/components/Typography';
import { SearchIcon } from '@/icons/SearchIcon';
import { StyledAssetLabel } from '@/components/AssetChainInput';
import { ClientAsset } from '@/state/skip';
import { LeftArrowIcon } from '@/icons/ArrowIcon';
import { useModal } from '@ebay/nice-modal-react';
import { Button } from '../../components/Button.tsx';
import { Text } from '../../components/Typography';
import { Button } from '@/components/Button';
import { Text } from '@/components/Typography';

interface SearchInputProps {
type TokenAndChainSelectorModalSearchInputProps = {
onSearch: (term: string) => void;
asset?: Partial<ClientAsset>;
}
};

export const SearchInput: React.FC<SearchInputProps> = ({
export const TokenAndChainSelectorModalSearchInput = ({
onSearch,
asset,
}) => {
}: TokenAndChainSelectorModalSearchInputProps) => {
const theme = useTheme();
const modal = useModal();
const inputRef = useRef<HTMLInputElement>(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import NiceModal from '@ebay/nice-modal-react';
import { Modal, ModalProps } from '../../components/Modal';
import { Column } from '../../components/Layout';
import { Modal, ModalProps } from '@/components/Modal';
import { Column } from '@/components/Layout';
import { styled } from 'styled-components';
import { SwapFlowHeader } from '../SwapFlow/SwapFlowHeader';
import { SwapFlowFooter } from '../SwapFlow/SwapFlowFooter';
import { ICONS } from '../../icons';
import { VirtualList } from '../../components/VirtualList';
import { SwapPageHeader } from '@/pages/SwapPage/SwapPageHeader';
import { SwapPageFooter } from '@/pages/SwapPage/SwapPageFooter';
import { ICONS } from '@/icons';
import { VirtualList } from '@/components/VirtualList';
import {
TransactionHistoryFlowItem,
TransactionHistoryModalItem,
TxHistoryItem,
} from './TransactionHistoryFlowItem';
} from './TransactionHistoryModalItem';
import { useState } from 'react';
import { HistoryIcon } from '../../icons/HistoryIcon';
import { SmallText } from '../../components/Typography';
import { HistoryIcon } from '@/icons/HistoryIcon';
import { SmallText } from '@/components/Typography';

const ITEM_HEIGHT = 40;
const ITEM_GAP = 5;

export type TransactionHistoryFlowProps = ModalProps & {
export type TransactionHistoryModalProps = ModalProps & {
txHistory: TxHistoryItem[];
};

export const TransactionHistoryFlow = NiceModal.create(
({ txHistory, ...modalProps }: TransactionHistoryFlowProps) => {
export const TransactionHistoryModal = NiceModal.create(
({ txHistory, ...modalProps }: TransactionHistoryModalProps) => {
const [itemIndexToShowDetail, setItemIndexToShowDetail] = useState<
number | undefined
>();
return (
<Modal {...modalProps}>
<SwapFlowHeader
<SwapPageHeader
leftButton={{
label: 'Back',
icon: ICONS.thinArrow,
Expand All @@ -55,7 +55,7 @@ export const TransactionHistoryFlow = NiceModal.create(
height={300}
itemHeight={ITEM_HEIGHT + ITEM_GAP}
renderItem={(item, index) => (
<TransactionHistoryFlowItem
<TransactionHistoryModalItem
txHistoryItem={item}
showDetails={index === itemIndexToShowDetail}
onClickRow={() => {
Expand All @@ -74,7 +74,7 @@ export const TransactionHistoryFlow = NiceModal.create(
/>
)}
</StyledContainer>
<SwapFlowFooter />
<SwapPageFooter />
</Modal>
);
}
Expand Down
Loading
Loading