Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Fix async state updates
Browse files Browse the repository at this point in the history
Fixes #39
Fixes #41
  • Loading branch information
adityapk00 committed Apr 1, 2020
1 parent 7376ec2 commit bbd0388
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
14 changes: 12 additions & 2 deletions app/components/Receive.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable react/prop-types */
import React, { Component, useState } from 'react';
import React, { Component, useState, useEffect } from 'react';
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
import {
Accordion,
Expand All @@ -20,6 +20,16 @@ const AddressBlock = ({ addressBalance, label, currencyName, zecPrice, privateKe
const { address } = addressBalance;

const [copied, setCopied] = useState(false);
const [timerID, setTimerID] = useState(null);

useEffect(() => {
return () => {
if (timerID) {
clearTimeout(timerID);
}
};
});

const balance = addressBalance.balance || 0;

const openAddress = () => {
Expand Down Expand Up @@ -72,7 +82,7 @@ const AddressBlock = ({ addressBalance, label, currencyName, zecPrice, privateKe
onClick={() => {
clipboard.writeText(address);
setCopied(true);
setTimeout(() => setCopied(false), 5000);
setTimerID(setTimeout(() => setCopied(false), 5000));
}}
>
{copied ? <span>Copied!</span> : <span>Copy Address</span>}
Expand Down
8 changes: 4 additions & 4 deletions app/components/ScrollPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ export default class ScrollPane extends Component<Props, PaneState> {

componentDidMount() {
this.updateDimensions();
window.addEventListener('resize', this.updateDimensions.bind(this));
window.addEventListener('resize', this.updateDimensions);
}

componentWillUnmount() {
window.removeEventListener('resize', this.updateDimensions.bind(this));
window.removeEventListener('resize', this.updateDimensions);
}

/**
* Calculate & Update state of height, needed for the scrolling
*/
updateDimensions() {
updateDimensions = () => {
// eslint-disable-next-line react/destructuring-assignment
const updateHeight = window.innerHeight - this.props.offsetHeight;
this.setState({ height: updateHeight });
}
};

render() {
const { children, className } = this.props;
Expand Down
11 changes: 8 additions & 3 deletions app/components/Send.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const ToAddrBox = ({
amountError = 'Amount cannot be empty';
}

let buttonstate;
if (
!addressIsValid ||
amountError ||
Expand All @@ -72,11 +73,15 @@ const ToAddrBox = ({
parseFloat(toaddr.amount) === 0 ||
fromAmount === 0
) {
setSendButtonEnable(false);
buttonstate = false;
} else {
setSendButtonEnable(true);
buttonstate = true;
}

setTimeout(() => {
setSendButtonEnable(buttonstate);
}, 10);

const usdValue = Utils.getZecToUsdString(zecPrice, toaddr.amount);

const addReplyTo = () => {
Expand Down Expand Up @@ -121,7 +126,7 @@ const ToAddrBox = ({
type="number"
step="any"
className={cstyles.inputbox}
value={toaddr.amount}
value={isNaN(toaddr.amount) ? '' : toaddr.amount}
onChange={e => updateToField(toaddr.id, null, e, null)}
/>
<img
Expand Down

0 comments on commit bbd0388

Please sign in to comment.