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

feat: display same source and destination token warning on widget #945

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
7 changes: 2 additions & 5 deletions widget/embedded/src/components/NoResult/NoResult.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import type { Info } from './NoResult.types';
import type { NoResultError, QuoteRequestFailed } from '../../types';

import { i18n } from '@lingui/core';

import { errorMessages } from '../../constants/errors';
import {
type NoResultError,
QuoteErrorType,
type QuoteRequestFailed,
} from '../../types';
import { QuoteErrorType } from '../../types';

const SMALL_NO_ROUTE__ICON_SIZE = 24;
const LARGE_NO_ROUTE_ICON_SIZE = 60;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { styled } from '@rango-dev/ui';

export const Container = styled('div', {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { i18n } from '@lingui/core';
import { Alert, Divider, NoRouteIcon, Typography } from '@rango-dev/ui';
import React from 'react';

import { useQuoteStore } from '../../store/quote';
import { areTokensEqual } from '../../utils/wallets';

import { Container } from './SameTokensWarning.styles';

export function SameTokensWarning() {
const { fromToken, toToken } = useQuoteStore();
const showWarningMessage =
fromToken && toToken && areTokensEqual(fromToken, toToken);
Ikari-Shinji-re marked this conversation as resolved.
Show resolved Hide resolved

return showWarningMessage ? (
<Container>
<NoRouteIcon size={24} color="gray" />
<Divider size={4} />
<Typography variant="title" size={'small'}>
{i18n.t('No Routes Found')}
</Typography>
<Divider size={4} />
<Alert
title={i18n.t('You cannot use the same token for From and To.')}
type={'warning'}
variant="alarm"
/>
</Container>
) : null;
}
1 change: 1 addition & 0 deletions widget/embedded/src/components/SameTokensWarning/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SameTokensWarning } from './SameTokensWarning';
3 changes: 3 additions & 0 deletions widget/embedded/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useNavigate } from 'react-router-dom';
import { HeaderButtons } from '../components/HeaderButtons';
import { Layout, PageContainer } from '../components/Layout';
import { QuoteWarningsAndErrors } from '../components/QuoteWarningsAndErrors';
import { SameTokensWarning } from '../components/SameTokensWarning';
import { navigationRoutes } from '../constants/navigationRoutes';
import { ExpandedQuotes } from '../containers/ExpandedQuotes';
import { Inputs } from '../containers/Inputs';
Expand Down Expand Up @@ -123,6 +124,7 @@ export function Home() {
setSelectedQuote(quote);
}
};

return (
<MainContainer>
<Layout
Expand Down Expand Up @@ -226,6 +228,7 @@ export function Home() {
/>
</>
) : null}
<SameTokensWarning />
</PageContainer>
</Layout>
{isExpandable ? (
Expand Down