Skip to content

Commit

Permalink
csov-2 added to my wallet; hide top-up history (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
creed-victor authored Feb 5, 2021
1 parent 060204b commit e5b33c8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
52 changes: 40 additions & 12 deletions src/app/components/UserAssets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { translations } from '../../../locales/i18n';
import { useAccount, useIsConnected } from '../../hooks/useAccount';
import { AssetsDictionary } from '../../../utils/dictionaries/assets-dictionary';
import { AssetDetails } from '../../../utils/models/asset-details';
import { useAssetBalanceOf } from '../../hooks/useAssetBalanceOf';
import { weiToFixed } from '../../../utils/blockchain/math-helpers';
import { LoadableValue } from '../LoadableValue';
import { useCachedAssetPrice } from '../../hooks/trading/useCachedAssetPrice';
Expand All @@ -24,8 +23,9 @@ import {
numberToUSD,
weiToNumberFormat,
} from '../../../utils/display-text/format';

// import { actions } from 'app/containers/FastBtcForm/slice';
import { contractReader } from '../../../utils/sovryn/contract-reader';
import { getTokenContractName } from '../../../utils/blockchain/contract-helpers';
import { Sovryn } from '../../../utils/sovryn';

export function UserAssets() {
const { t } = useTranslation();
Expand Down Expand Up @@ -87,25 +87,56 @@ interface AssetProps {

function AssetRow({ item }: AssetProps) {
const { t } = useTranslation();
const tokens = useAssetBalanceOf(item.asset);
const account = useAccount();
const [loading, setLoading] = useState(true);
const [tokens, setTokens] = useState('0');
const dollars = useCachedAssetPrice(item.asset, Asset.USDT);
// const dispatch = useDispatch();
const history = useHistory();

const [dollarValue, setDollarValue] = useState('0');

useEffect(() => {
const get = async () => {
setLoading(true);
let tokenA: string = '0';
if (item.asset === Asset.BTC) {
tokenA = await Sovryn.getWeb3().eth.getBalance(account);
} else {
tokenA = await contractReader.call(
getTokenContractName(item.asset),
'balanceOf',
[account],
);
}

let tokenB: string = '0';
if (item.asset === Asset.CSOV) {
tokenB = await contractReader.call('CSOV2_token', 'balanceOf', [
account,
]);
}
setTokens(
bignumber(tokenA)
.add(tokenB || '0')
.toFixed(0),
);
setLoading(false);
};
get().catch();
}, [item.asset, account]);

useEffect(() => {
if ([Asset.USDT, Asset.DOC].includes(item.asset)) {
setDollarValue(tokens.value);
setDollarValue(tokens);
} else {
setDollarValue(
bignumber(tokens.value)
bignumber(tokens)
.mul(dollars.value)
.div(10 ** item.decimals)
.toFixed(0),
);
}
}, [dollars.value, tokens.value, item.asset, item.decimals]);
}, [dollars.value, tokens, item.asset, item.decimals]);

return (
<tr key={item.asset}>
Expand All @@ -119,10 +150,7 @@ function AssetRow({ item }: AssetProps) {
{item.symbol}
</td>
<td className="text-right">
<LoadableValue
value={weiToNumberFormat(tokens.value, 4)}
loading={tokens.loading}
/>
<LoadableValue value={weiToNumberFormat(tokens, 4)} loading={loading} />
</td>
<td className="text-right d-none d-md-table-cell">
<LoadableValue
Expand Down
3 changes: 1 addition & 2 deletions src/app/containers/WalletPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { Header } from '../../components/Header';
import { Footer } from '../../components/Footer';
import WalletConnector from '../../containers/WalletConnector';
import { UserAssets } from '../../components/UserAssets';
import { TopUpHistory } from '../../components/TopUpHistory';
import { SovGenerationNFTS } from '../../components/SovGenerationNFTS';
import { Tab } from '../../components/Tab';
import { SkeletonRow } from '../../components/Skeleton/SkeletonRow';
Expand Down Expand Up @@ -66,7 +65,7 @@ export function WalletPage() {
{activeAssets ? (
<>
<UserAssets />
<TopUpHistory />
{/*<TopUpHistory />*/}
</>
) : (
<SovGenerationNFTS />
Expand Down
5 changes: 5 additions & 0 deletions src/utils/blockchain/contracts.testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ export const contracts = {
abi: CSOVTokenAbi,
blockNumber: 1218833,
},
CSOV2_token: {
address: '0x1dA260149ffee6fD4443590ee58F65b8dC2106B9',
abi: CSOVTokenAbi,
blockNumber: 1218833,
},
...(process.env.REACT_APP_WHITELIST_TOKEN &&
process.env.REACT_APP_WHITELIST === 'true' && {
whitelistToken: {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/blockchain/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ export const contracts = {
abi: CSOVTokenAbi,
blockNumber: 1218833,
},

CSOV2_token: {
address: '0x7f7Dcf9DF951C4A332740e9a125720DA242A34ff',
abi: CSOVTokenAbi,
blockNumber: 1218833,
},
// end non-mainnet //
...(process.env.REACT_APP_WHITELIST_TOKEN &&
process.env.REACT_APP_WHITELIST === 'true' && {
Expand Down

1 comment on commit e5b33c8

@vercel
Copy link

@vercel vercel bot commented on e5b33c8 Feb 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.