Skip to content

Commit

Permalink
fix(swap): keep fiat polling in routing
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-haynes committed Apr 21, 2022
1 parent 575e6d4 commit b2d90f4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
23 changes: 23 additions & 0 deletions packages/frontend/src/components/Routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ const Container = styled.div`
}
}
`;

class Routing extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -200,6 +201,7 @@ class Routing extends Component {
} = this.props;

fetchTokenFiatValues();
this.startPollingTokenFiatValue();
handleRefreshUrl(router);
refreshAccount();

Expand Down Expand Up @@ -232,6 +234,27 @@ class Routing extends Component {
}
}

componentWillUnmount = () => {
this.stopPollingTokenFiatValue();
}

startPollingTokenFiatValue = () => {
const { fetchTokenFiatValues } = this.props;

const handlePollTokenFiatValue = async () => {
await fetchTokenFiatValues().catch(() => { });
if (this.pollTokenFiatValue) {
this.pollTokenFiatValue = setTimeout(() => handlePollTokenFiatValue(), 30000);
}
};
this.pollTokenFiatValue = setTimeout(() => handlePollTokenFiatValue(), 30000);
}

stopPollingTokenFiatValue = () => {
clearTimeout(this.pollTokenFiatValue);
this.pollTokenFiatValue = null;
}

render() {
const { search, query: { tab }, hash, pathname } = this.props.router.location;
const { account } = this.props;
Expand Down
14 changes: 1 addition & 13 deletions packages/frontend/src/components/wallet/Wallet.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React, { useEffect } from 'react';
import React from 'react';
import { Translate } from 'react-localize-redux';
import { useDispatch } from 'react-redux';
import { Textfit } from 'react-textfit';
import styled from 'styled-components';

import { CREATE_IMPLICIT_ACCOUNT,CREATE_USN_CONTRACT } from '../../../../../features';
import getCurrentLanguage from '../../hooks/getCurrentLanguage';
import { useSplitFungibleTokens } from '../../hooks/splitFungibleTokens';
import { actions as tokenFiatValueActions } from '../../redux/slices/tokenFiatValues';
import classNames from '../../utils/classNames';
import { SHOW_NETWORK_BANNER } from '../../utils/wallet';
import Balance from '../common/balance/Balance';
Expand All @@ -30,8 +28,6 @@ import ReleaseNotesModal from './ReleaseNotesModal';
import Sidebar from './Sidebar';
import Tokens from './Tokens';

const { fetchTokenFiatValues } = tokenFiatValueActions;

const StyledContainer = styled(Container)`
@media (max-width: 991px) {
margin: -5px auto 0 auto;
Expand Down Expand Up @@ -343,20 +339,12 @@ export function Wallet({

const FungibleTokens = ({ balance, tokensLoading, fungibleTokens, accountExists, totalAmount, currentLanguage }) => {
const zeroBalanceAccount = accountExists === false;
const dispatch = useDispatch();
const currentFungibleTokens = CREATE_USN_CONTRACT ? fungibleTokens[0][0] : fungibleTokens[0];
const hideFungibleTokenSection =
zeroBalanceAccount &&
fungibleTokens?.length === 1 &&
currentFungibleTokens?.onChainFTMetadata?.symbol === 'NEAR';

useEffect(() => {
const startPollingTokenFiatValue = setInterval(() => {
dispatch(fetchTokenFiatValues());
},30000);

return () => clearInterval(startPollingTokenFiatValue);
}, []);
return (
<>
<div className='total-balance'>
Expand Down

0 comments on commit b2d90f4

Please sign in to comment.