Skip to content

Commit

Permalink
Minimum amount fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy committed Dec 23, 2020
1 parent 3390081 commit 37e7580
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/pages/EthBridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const LargeButton = (props: {
};

export const EthBridge = observer((props: any) => {
const { user, exchange, routing } = useStores();
const { tokens, exchange, routing } = useStores();

useEffect(() => {
if (props.match.params.token) {
Expand All @@ -73,6 +73,11 @@ export const EthBridge = observer((props: any) => {
}
}, []);

useEffect(() => {
tokens.init();
tokens.fetch();
}, []);

return (
<BaseContainer>
<PageContainer>
Expand Down
44 changes: 40 additions & 4 deletions src/pages/Exchange/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import {
} from 'components/Form';
import { inject, observer } from 'mobx-react';
import { IStores } from 'stores';
import { Button, Checkbox, Icon, Select, Text } from 'components/Base';
import { Button, Icon, Text } from 'components/Base';
import { formatWithSixDecimals, moreThanZero } from 'utils';
import { Spinner } from 'ui/Spinner';
import { EXCHANGE_STEPS } from '../../stores/Exchange';
import { Details } from './Details';
import { AuthWarning } from '../../components/AuthWarning';
import { Steps } from './Steps';
import { autorun, computed, observable } from 'mobx';
import { TOKEN, EXCHANGE_MODE } from 'stores/interfaces';
import { autorun, computed } from 'mobx';
import { EXCHANGE_MODE, TOKEN } from 'stores/interfaces';
import cn from 'classnames';
import { ERC20Select } from './ERC20Select';

Expand All @@ -27,12 +27,13 @@ export interface ITokenInfo {
maxAmount: string;
}

@inject('user', 'exchange', 'actionModals', 'userMetamask', 'routing')
@inject('user', 'exchange', 'actionModals', 'userMetamask', 'routing', 'tokens')
@observer
export class Exchange extends React.Component<
Pick<IStores, 'user'> &
Pick<IStores, 'exchange'> &
Pick<IStores, 'routing'> &
Pick<IStores, 'tokens'> &
Pick<IStores, 'actionModals'> &
Pick<IStores, 'userMetamask'>
> {
Expand Down Expand Up @@ -317,6 +318,41 @@ export class Exchange extends React.Component<
errors.push(defaultMsg);
}

callback(errors);
},
(_, value, callback) => {
const errors = [];

const tokens = this.props.tokens;
let token: any;

if (exchange.token === TOKEN.BUSD) {
token = tokens.allData.find(t => t.symbol === 'BUSD');
}

if (exchange.token === TOKEN.LINK) {
token = tokens.allData.find(t => t.symbol === 'LINK');
}

if (exchange.token === TOKEN.ERC20) {
token = tokens.allData.find(
t =>
t.erc20Address ===
exchange.transaction.erc20Address,
);
}

if (
exchange.mode === EXCHANGE_MODE.ONE_TO_ETH &&
value &&
token &&
token.usdPrice &&
Number(value * token.usdPrice) < 100
) {
const defaultMsg = `Minimum amount must be more than 100$`;
errors.push(defaultMsg);
}

callback(errors);
},
]}
Expand Down

0 comments on commit 37e7580

Please sign in to comment.