Browse Source

rate小数点改为4位

master
mac 6 months ago
parent
commit
f288c42bfe
  1. 4
      README.md
  2. 27
      src/contract/index.ts
  3. 9
      src/pages/home/index.tsx
  4. 5
      src/pages/invitation-detail/index.tsx
  5. 2
      src/pages/invitation/index.tsx
  6. 4
      src/pages/nft-detail/index.tsx
  7. 12
      src/pages/pledge/index.tsx
  8. 8
      src/utils/index.ts

4
README.md

@ -13,4 +13,8 @@
<!-- 打包并部署到生產環境 --> <!-- 打包并部署到生產環境 -->
yarn deploy:prod or npm run deploy:prod yarn deploy:prod or npm run deploy:prod
本地域名:http://192.168.124.20:3002
测试域名:https://test-sofil.hippoim.us
生产域名:https://app.sofil.io
``` ```

27
src/contract/index.ts

@ -19,30 +19,29 @@ import { ContractType } from '~/types/store';
chainId: 97, chainId: 97,
rpc: "https://bsc-testnet.blockpi.network/v1/rpc/public", rpc: "https://bsc-testnet.blockpi.network/v1/rpc/public",
address: { address: {
FIL__factory: "0xfa01Ef257b47578063741D3E4b60e16764FA6fa8",
NFT__factory: "0x1eF6AAc9B468d7B310675409EFE5f954dFe59dDF",
Pool__factory: "0xe861046E610B6f6A0E79eEf8Dd0aF5a42dC83293",
Pledge__factory: "0xD8553004442098415734A9EFE49e13E29919BfF9",
FIL__factory: "0xfa01ef257b47578063741d3e4b60e16764fa6fa8",
NFT__factory: "0x3D4B3611912a58548BD925E1A1fA9DFA73061966",
Pool__factory: "0x2CEd9862567e0FD98EdB3Db3147c68841b311687",
Pledge__factory: "0xD1D827B8B5337C1c3c22ccFD47BCC16899b509e9",
} }
}, },
31337: { 31337: {
chainId: 31337, chainId: 31337,
rpc: "http://127.0.0.1:8545", rpc: "http://127.0.0.1:8545",
address: { address: {
FIL__factory: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
NFT__factory: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
Pool__factory: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
Pledge__factory: "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707",
FIL__factory: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
NFT__factory: "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6",
Pool__factory: "0x610178dA211FEF7D417bC0e6FeD39F05609AD788",
Pledge__factory: "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0",
} }
}, },
} as any } as any
if(process.env.REACT_APP_CHAINID === '56'){
delete config[97]
}else{
delete config[56]
}
console.log(config);
// if(process.env.REACT_APP_CHAINID === '56'){
// delete config[97]
// }else{
// delete config[56]
// }
// 57.333333333333333332 // 57.333333333333333332
const contractObj = { const contractObj = {

9
src/pages/home/index.tsx

@ -6,6 +6,7 @@ import { eth_pledgeProducts } from '~/contract/api'
import { useRouter } from '~/hooks/useRouter' import { useRouter } from '~/hooks/useRouter'
import '~/styles/home.scss' import '~/styles/home.scss'
import { openGitBook } from '~/utils' import { openGitBook } from '~/utils'
import { toString } from '~/utils/wei'
const Home = () => { const Home = () => {
@ -13,9 +14,9 @@ const Home = () => {
const { t } = useTranslation() const { t } = useTranslation()
const [pledgeList, setPledgeList] = useState([ const [pledgeList, setPledgeList] = useState([
{ day: 180, rate: 14 },
{ day: 270, rate: 15 },
{ day: 360, rate: 16 },
{ day: 180, rate: 1408 },
{ day: 270, rate: 1521 },
{ day: 360, rate: 1623 },
]) ])
const [pledgeIndex, setPledgeIndex] = useState(0) const [pledgeIndex, setPledgeIndex] = useState(0)
@ -70,7 +71,7 @@ const Home = () => {
</div> </div>
<div className='mt-2 row-between'> <div className='mt-2 row-between'>
<div>{t('Annualized Percentage Rate (APR)')}</div> <div>{t('Annualized Percentage Rate (APR)')}</div>
<div className='fz-26 fz-wb-550'>{pledgeList[pledgeIndex].rate}%</div>
<div className='fz-26 fz-wb-550'>{toString(pledgeList[pledgeIndex].rate,2)}%</div>
</div> </div>
</div> </div>
</div> </div>

5
src/pages/invitation-detail/index.tsx

@ -11,6 +11,7 @@ import store from '~/store'
import '~/styles/pledge.scss' import '~/styles/pledge.scss'
import { PledgeInfoType } from '~/types/api.d' import { PledgeInfoType } from '~/types/api.d'
import { calcExtractableAmount, calcReleasedIncome, calcWithdrawnAmount, getTime, splitAddress } from '~/utils' import { calcExtractableAmount, calcReleasedIncome, calcWithdrawnAmount, getTime, splitAddress } from '~/utils'
import { toString } from '~/utils/wei'
const InvitationDetail = () => { const InvitationDetail = () => {
@ -111,7 +112,7 @@ const InvitationDetail = () => {
</div> </div>
<div className='mt-1 row-between'> <div className='mt-1 row-between'>
<div>{t('Status')}</div> <div>{t('Status')}</div>
<div>{data.endTime > currentTime ? 'Active' : 'Matured'}</div>
<div>{data.endTime > currentTime ? t('Active') : t('Matured')}</div>
</div> </div>
<div className='mt-1 row-between'> <div className='mt-1 row-between'>
<div>{t('Staked Amount')}</div> <div>{t('Staked Amount')}</div>
@ -119,7 +120,7 @@ const InvitationDetail = () => {
</div> </div>
<div className='mt-1 row-between'> <div className='mt-1 row-between'>
<div>{t('Est. APR')}</div> <div>{t('Est. APR')}</div>
<div>{rate}%</div>
<div>{toString(rate, 2)}%</div>
</div> </div>
<div className='mt-1 row-between'> <div className='mt-1 row-between'>
<div>{t('Created Time')}</div> <div>{t('Created Time')}</div>

2
src/pages/invitation/index.tsx

@ -28,7 +28,7 @@ const Invitation = () => {
const [userRecord, setUserRecord] = useState([] as InvitationUserRecordType[]) const [userRecord, setUserRecord] = useState([] as InvitationUserRecordType[])
const [contractRecord, setContractRecord] = useState([] as PledgeInfoType[]) const [contractRecord, setContractRecord] = useState([] as PledgeInfoType[])
const [withdrawtRecord, setWithdrawRecord] = useState([] as InvitationWithdrawRecordType[]) const [withdrawtRecord, setWithdrawRecord] = useState([] as InvitationWithdrawRecordType[])
const [rate, setRate] = useState(0);
const [rate, setRate] = useState(100);
const [currentTime, setCurrentTime] = useState(0) const [currentTime, setCurrentTime] = useState(0)
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)

4
src/pages/nft-detail/index.tsx

@ -12,7 +12,7 @@ import store from '~/store'
import '~/styles/pledge.scss' import '~/styles/pledge.scss'
import { PledgeInfoType } from '~/types/api.d' import { PledgeInfoType } from '~/types/api.d'
import { calcExtractableAmount, calcIncome, calcReleasedIncome, calcWithdrawnAmount, getTime, splitAddress } from '~/utils' import { calcExtractableAmount, calcIncome, calcReleasedIncome, calcWithdrawnAmount, getTime, splitAddress } from '~/utils'
import { toBigInt } from '~/utils/wei'
import { toBigInt, toString } from '~/utils/wei'
const NFTDetail = () => { const NFTDetail = () => {
@ -174,7 +174,7 @@ const NFTDetail = () => {
</div> </div>
<div className='mt-1 row-between'> <div className='mt-1 row-between'>
<div>{t('Est. APR')}</div> <div>{t('Est. APR')}</div>
<div>{data.rate}%</div>
<div>{toString(data.rate, 2)}%</div>
</div> </div>
<div className='mt-1 row-between'> <div className='mt-1 row-between'>
<div>{t('Created Time')}</div> <div>{t('Created Time')}</div>

12
src/pages/pledge/index.tsx

@ -12,7 +12,7 @@ import store from '~/store';
import '~/styles/pledge.scss' import '~/styles/pledge.scss'
import { Contract_Factory } from '~/types/store'; import { Contract_Factory } from '~/types/store';
import { toFixed2 } from '~/utils'; import { toFixed2 } from '~/utils';
import { toBigInt, toWei, wei } from '~/utils/wei';
import { toBigInt, toString, toWei, wei } from '~/utils/wei';
// //
const Pledge = () => { const Pledge = () => {
@ -23,9 +23,9 @@ const Pledge = () => {
const { Pledge__factory, FIL__factory, Pool__factory } = contract._contract ? contract._contract : {} as Contract_Factory const { Pledge__factory, FIL__factory, Pool__factory } = contract._contract ? contract._contract : {} as Contract_Factory
const [pledgeList, setPledgeList] = useState([ const [pledgeList, setPledgeList] = useState([
{ day: 180, rate: 14 },
{ day: 270, rate: 15 },
{ day: 360, rate: 16 },
{ day: 180, rate: 1408 },
{ day: 270, rate: 1521 },
{ day: 360, rate: 1623 },
]) ])
const [amount, setAmount] = useState('') const [amount, setAmount] = useState('')
@ -134,7 +134,7 @@ const Pledge = () => {
const rate = toBigInt(pledgeList[tabIndex].rate) const rate = toBigInt(pledgeList[tabIndex].rate)
const year = toBigInt(365) const year = toBigInt(365)
const total = pledgeAmount * rate / year * pledgeDay; const total = pledgeAmount * rate / year * pledgeDay;
const _profit = ethers.formatUnits(total, 20)
const _profit = ethers.formatUnits(total, 22)
const _totalProfit = ethers.formatUnits(toWei(toFixed2(_profit, 18)) + pledgeAmount, 18) const _totalProfit = ethers.formatUnits(toWei(toFixed2(_profit, 18)) + pledgeAmount, 18)
setProfit(_profit) setProfit(_profit)
@ -178,7 +178,7 @@ const Pledge = () => {
> >
<div> <div>
<div className=''><span className='fz-wb-550 fz-18'>{item.day}</span> {t('Days')}</div> <div className=''><span className='fz-wb-550 fz-18'>{item.day}</span> {t('Days')}</div>
<div className='mt-5px'><span className='fz-24 fz-wb-550'>{item.rate}</span> %</div>
<div className='mt-5px'><span className='fz-24 fz-wb-550'>{toString(item.rate, 2)}</span> %</div>
<div className='fz-14 mt-5px'>{t('Est.APR')}</div> <div className='fz-14 mt-5px'>{t('Est.APR')}</div>
</div> </div>
</div> </div>

8
src/utils/index.ts

@ -116,7 +116,7 @@ const calcIncome = (data: PledgeInfoType) => {
const day = toBigInt(data.pledgeDay); const day = toBigInt(data.pledgeDay);
const income = const income =
((toWei(data.pledgeAmount) * rate) / ethers.toBigInt(365)) * day; ((toWei(data.pledgeAmount) * rate) / ethers.toBigInt(365)) * day;
return toFixed2(ethers.formatUnits(income, 20), 4) || "0.00";
return toFixed2(ethers.formatUnits(income, 22), 4) || "0.00";
} catch (error) { } catch (error) {
return "0.00"; return "0.00";
} }
@ -138,7 +138,7 @@ const calcReleasedIncome = (data: PledgeInfoType, currentTime: number) => {
const pledgeAmount = toWei(data.pledgeAmount); const pledgeAmount = toWei(data.pledgeAmount);
const year = toBigInt(365); const year = toBigInt(365);
const income = ((pledgeAmount * rate) / year) * toBigInt(daysDifference); const income = ((pledgeAmount * rate) / year) * toBigInt(daysDifference);
return toFixed2(ethers.formatUnits(income, 20), 4);
return toFixed2(ethers.formatUnits(income, 22), 4);
} catch (error) { } catch (error) {
return "0.00"; return "0.00";
} }
@ -157,7 +157,7 @@ const calcWithdrawnAmount = (data: PledgeInfoType) => {
const pledgeAmount = toWei(data.pledgeAmount); const pledgeAmount = toWei(data.pledgeAmount);
const year = toBigInt(365); const year = toBigInt(365);
const income = ((pledgeAmount * rate) / year) * toBigInt(daysDifference); const income = ((pledgeAmount * rate) / year) * toBigInt(daysDifference);
return toFixed2(ethers.formatUnits(income, 20), 4);
return toFixed2(ethers.formatUnits(income, 22), 4);
} catch (error) { } catch (error) {
return "0.00"; return "0.00";
} }
@ -179,7 +179,7 @@ const calcExtractableAmount = (data: PledgeInfoType, currentTime: number) => {
const pledgeAmount = toWei(data.pledgeAmount); const pledgeAmount = toWei(data.pledgeAmount);
const year = toBigInt(365); const year = toBigInt(365);
const income = ((pledgeAmount * rate) / year) * toBigInt(daysDifference); const income = ((pledgeAmount * rate) / year) * toBigInt(daysDifference);
return toFixed2(ethers.formatUnits(income, 20), 4);
return toFixed2(ethers.formatUnits(income, 22), 4);
} catch (error) { } catch (error) {
return "0.00"; return "0.00";
} }

Loading…
Cancel
Save