Skip to content

Commit

Permalink
#add value config itokenDecimals depostLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
LancelotM committed Oct 18, 2020
1 parent f1b477b commit daad474
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
24 changes: 24 additions & 0 deletions src/features/configure/pools.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import BigNumber from "bignumber.js";
// id: '池子id',
// name: '池子名字',
// token: '池子代币',
// tokenDescription: '代币描述',
// tokenAddress: '代币ERC20地址',
// tokenDecimals: '存入精度'
// itokenDecimals: '提取精度'
// depostLimit: '存入最大数量限制' 0时不限制
// earnedToken: '奖励代币',
// earnedTokenAddress: '奖励代币ERC20地址',
// earnContractAddress: '池子合约地址',
Expand All @@ -16,6 +20,8 @@ export const pools = [
tokenDescription: 'ETH',
tokenAddress: '',
tokenDecimals: 18,
itokenDecimals: 18,
depostLimit:0,
tokenDescriptionUrl: '',
tokenDescriptionUrl2: '',
earnedToken: 'iWETH',
Expand All @@ -32,6 +38,8 @@ export const pools = [
tokenDescription: 'WETH',
tokenAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
tokenDecimals: 18,
itokenDecimals: 18,
depostLimit:0,
tokenDescriptionUrl: '',
tokenDescriptionUrl2: '',
earnedToken: 'iWETH',
Expand All @@ -48,6 +56,8 @@ export const pools = [
tokenDescription: 'USDT',
tokenAddress: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
tokenDecimals: 6,
itokenDecimals: 6,
depostLimit:0,
tokenDescriptionUrl: '',
tokenDescriptionUrl2: '',
earnedToken: 'iUSDT',
Expand All @@ -63,6 +73,8 @@ export const pools = [
tokenDescription: 'USDC',
tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
tokenDecimals: 6,
itokenDecimals: 6,
depostLimit:0,
tokenDescriptionUrl: '',
tokenDescriptionUrl2: '',
earnedToken: 'iUSDC',
Expand All @@ -79,6 +91,8 @@ export const pools = [
tokenDescription: 'DAI',
tokenAddress: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
tokenDecimals: 18,
itokenDecimals: 18,
depostLimit:0,
tokenDescriptionUrl: '',
tokenDescriptionUrl2: 'https://docs.dfi.money/#/zh-cn/buy-tokens?id=_2-dai%e5%85%91%e6%8d%a2',
earnedToken: 'iDAI',
Expand All @@ -95,6 +109,8 @@ export const pools = [
tokenDescription: 'HUSD',
tokenAddress: '0xdF574c24545E5FfEcb9a659c229253D4111d87e1',
tokenDecimals: 8,
itokenDecimals: 18,
depostLimit:new BigNumber('10').pow(5).toNumber(),
tokenDescriptionUrl: '',
tokenDescriptionUrl2: '',
earnedToken: 'iHUSD',
Expand All @@ -110,6 +126,8 @@ export const pools = [
tokenDescription: 'BUSD',
tokenAddress: '0x4Fabb145d64652a948d72533023f6E7A623C7C53',
tokenDecimals: 18,
itokenDecimals: 18,
depostLimit:0,
tokenDescriptionUrl: '',
tokenDescriptionUrl2: '',
earnedToken: 'iBUSD',
Expand All @@ -126,6 +144,8 @@ export const pools = [
tokenDescription: 'HBTC',
tokenAddress: '0x0316eb71485b0ab14103307bf65a021042c6d380',
tokenDecimals: 18,
itokenDecimals: 18,
depostLimit:0,
tokenDescriptionUrl: '',
tokenDescriptionUrl2: '',
earnedToken: 'iHBTC',
Expand All @@ -142,6 +162,8 @@ export const pools = [
tokenDescription: 'TUSD',
tokenAddress: '0x0000000000085d4780B73119b644AE5ecd22b376',
tokenDecimals: 18,
itokenDecimals: 18,
depostLimit:0,
tokenDescriptionUrl: '',
tokenDescriptionUrl2: '',
earnedToken: 'iTUSD',
Expand All @@ -158,6 +180,8 @@ export const pools = [
tokenDescription: 'yCRV',
tokenAddress: '0xdF5e0e81Dff6FAF3A7e52BA697820c5e32D806A8',
tokenDecimals: 18,
itokenDecimals: 18,
depostLimit:0,
tokenDescriptionUrl: 'https://docs.dfi.money/#/using-crv?id=how-to-get-ycrv',
tokenDescriptionUrl2: 'https://docs.dfi.money/#/zh-cn/buy-tokens?id=_5-ycrv%e5%85%91%e6%8d%a2',
earnedToken: 'iYCRV',
Expand Down
21 changes: 14 additions & 7 deletions src/features/vault/sections/SectionPools.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import CustomSlider from 'components/CustomSlider/CustomSlider';

import sectionPoolsStyle from "../jss/sections/sectionPoolsStyle";
import { reflect } from 'async';
import { inputLimitPass,inputFinalVal } from 'features/helpers/utils';
import { inputLimitPass,inputFinalVal,isEmpty } from 'features/helpers/utils';

const useStyles = makeStyles(sectionPoolsStyle);

Expand Down Expand Up @@ -174,7 +174,7 @@ export default function SectionPools() {
address,
web3,
isAll,
amount: new BigNumber(amountValue).multipliedBy(new BigNumber(10).exponentiatedBy(pool.tokenDecimals)).toString(10),
amount: new BigNumber(amountValue).multipliedBy(new BigNumber(10).exponentiatedBy(pool.itokenDecimals)).toString(10),
contractAddress: pool.earnContractAddress,
index
}).then(
Expand All @@ -187,7 +187,7 @@ export default function SectionPools() {
address,
web3,
isAll,
amount: new BigNumber(amountValue).multipliedBy(new BigNumber(10).exponentiatedBy(pool.tokenDecimals)).toString(10),
amount: new BigNumber(amountValue).multipliedBy(new BigNumber(10).exponentiatedBy(pool.itokenDecimals)).toString(10),
contractAddress: pool.earnContractAddress,
index
}).then(
Expand Down Expand Up @@ -223,6 +223,13 @@ export default function SectionPools() {
}
}, [address, web3, fetchBalances, fetchPoolBalances]);

const isMoreDepostLimit = (inputValueNum,depostLimit) => {
if(isEmpty(inputValueNum) || depostLimit==0 || inputValueNum<depostLimit){
return false;
}
return true;
}

useEffect(() => {
fetchContractApy();
}, [pools, fetchContractApy]);
Expand Down Expand Up @@ -261,7 +268,7 @@ export default function SectionPools() {
let balanceSingle = byDecimals(tokens[pool.token].tokenBalance, pool.tokenDecimals);
// balanceSingle = byDecimals(random(1, 1000000), 1)
// balanceSingle = new BigNumber(random(1, 1000000000000000))
let singleDepositedBalance = byDecimals(tokens[pool.earnedToken].tokenBalance, pool.tokenDecimals);
let singleDepositedBalance = byDecimals(tokens[pool.earnedToken].tokenBalance, pool.itokenDecimals);
// singleDepositedBalance = byDecimals(random(1, 1000000), 1)
// singleDepositedBalance = new BigNumber(random(1, 1000))
let depositedApy = contractApy[pool.id] || 0;
Expand Down Expand Up @@ -433,7 +440,7 @@ export default function SectionPools() {
round
onFocus={(event) => event.stopPropagation()}
disabled={
!Boolean(depositedBalance[index]) || fetchDepositPending[index] || (new BigNumber(depositedBalance[index]).toNumber() > balanceSingle.toNumber())
!Boolean(depositedBalance[index]) || fetchDepositPending[index] || (new BigNumber(depositedBalance[index]).toNumber() > balanceSingle.toNumber() || isMoreDepostLimit(new BigNumber(depositedBalance[index]).toNumber(),pool.depostLimit))
}
onClick={onDeposit.bind(this, pool, index, false, balanceSingle)}
>{t('Vault-DepositButton')}
Expand All @@ -451,7 +458,7 @@ export default function SectionPools() {
round
onFocus={(event) => event.stopPropagation()}
disabled={
fetchDepositPending[index] || (new BigNumber(depositedBalance[index]).toNumber() > balanceSingle.toNumber())
fetchDepositPending[index] || (new BigNumber(depositedBalance[index]).toNumber() > balanceSingle.toNumber() || isMoreDepostLimit(new BigNumber(depositedBalance[index]).toNumber(),pool.depostLimit))
}
onClick={onDeposit.bind(this, pool, index, true, balanceSingle)}
>{t('Vault-DepositButtonAll')}
Expand All @@ -469,7 +476,7 @@ export default function SectionPools() {
<FormControl fullWidth variant="outlined">
<CustomOutlinedInput
value={withdrawAmount[index]!=undefined ? withdrawAmount[index] : '0'}
onChange={changeDetailInputValue.bind(this,'withdrawAmount',index,singleDepositedBalance.toNumber(),pool.tokenDecimals)}
onChange={changeDetailInputValue.bind(this,'withdrawAmount',index,singleDepositedBalance.toNumber(),pool.itokenDecimals)}
/>
</FormControl>
<CustomSlider
Expand Down

0 comments on commit daad474

Please sign in to comment.