Skip to content

Commit

Permalink
DDW-500 Implement design for native tokens - fixes for remove asset a…
Browse files Browse the repository at this point in the history
…nd dropdown values update
  • Loading branch information
DeeJayElly committed Feb 24, 2021
1 parent c1f0b71 commit 4bba50b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
34 changes: 26 additions & 8 deletions source/renderer/app/components/wallet/WalletAssetsSendForm.js
Expand Up @@ -192,13 +192,15 @@ type Props = {
assets: Array<WalletSummaryAsset>,
isClearTooltipOpeningDownward?: boolean,
hasAssets: boolean,
selectedToken?: Asset,
};

type State = {
isTransactionFeeCalculated: boolean,
transactionFee: BigNumber,
feeCalculationRequestQue: number,
transactionFeeError: ?string | ?Node,
assetsError: ?Array<?string | ?Node>,
showReceiverRemoveBtn: boolean,
showAssetRemoveBtn: Array<boolean>,
sendFormFields: Object,
Expand All @@ -208,7 +210,6 @@ type State = {
filteredAssets: any,
minimumAda: BigNumber,
isReceiverAddressValid: boolean,
selectedToken: Asset,
};

@observer
Expand All @@ -222,6 +223,7 @@ export default class WalletAssetsSendForm extends Component<Props, State> {
transactionFee: new BigNumber(0),
feeCalculationRequestQue: 0,
transactionFeeError: null,
assetsError: null,
showReceiverRemoveBtn: false,
showAssetRemoveBtn: [],
sendFormFields: {},
Expand All @@ -239,6 +241,7 @@ export default class WalletAssetsSendForm extends Component<Props, State> {
// disable the "Submit" button as soon as the value changes and then wait for
// the validation to end in order to see if the button should be enabled or not.
_isCalculatingTransactionFee = false;
_isCalculatingAssetsFee = false;

// We need to track the mounted state in order to avoid calling
// setState promise handling code after the component was already unmounted:
Expand Down Expand Up @@ -448,7 +451,9 @@ export default class WalletAssetsSendForm extends Component<Props, State> {
handleSubmitOnEnter = submitOnEnter.bind(this, this.handleOnSubmit);

isDisabled = () =>
this._isCalculatingTransactionFee || !this.state.isTransactionFeeCalculated;
this._isCalculatingTransactionFee ||
this._isCalculatingAssetsFee ||
!this.state.isTransactionFeeCalculated;

// FORM VALIDATION
form = new ReactToolboxMobxForm(
Expand Down Expand Up @@ -570,10 +575,12 @@ export default class WalletAssetsSendForm extends Component<Props, State> {
resetTransactionFee() {
if (this._isMounted) {
this._isCalculatingTransactionFee = false;
this._isCalculatingAssetsFee = false;
this.setState({
isTransactionFeeCalculated: false,
transactionFee: new BigNumber(0),
transactionFeeError: null,
assetsError: null,
});
}
}
Expand All @@ -600,6 +607,7 @@ export default class WalletAssetsSendForm extends Component<Props, State> {
isTransactionFeeCalculated: false,
transactionFee: new BigNumber(0),
transactionFeeError: null,
assetsError: null,
feeCalculationRequestQue: prevState.feeCalculationRequestQue + 1,
}));
try {
Expand Down Expand Up @@ -726,6 +734,7 @@ export default class WalletAssetsSendForm extends Component<Props, State> {
isTransactionFeeCalculated,
transactionFee,
transactionFeeError,
assetsError,
sendFormFields,
filteredAssets,
minimumAda,
Expand Down Expand Up @@ -981,7 +990,7 @@ export default class WalletAssetsSendForm extends Component<Props, State> {
minimumFractionDigits: tokenDecimalPlaces,
}}
onChange={(value) => {
this._isCalculatingTransactionFee = true;
this._isCalculatingAssetsFee = true;
this.setState({
isResetButtonDisabled: false,
});
Expand All @@ -990,7 +999,12 @@ export default class WalletAssetsSendForm extends Component<Props, State> {
}}
currency={metadata ? metadata.acronym : null}
value={amount[assetIndex]}
error={asset.error || transactionFeeError}
error={
asset.error ||
(assetsError && assetsError[assetIndex]
? assetsError[assetIndex]
: null)
}
skin={AmountInputSkin}
onKeyPress={this.handleSubmitOnEnter}
allowSigns={false}
Expand Down Expand Up @@ -1190,6 +1204,7 @@ export default class WalletAssetsSendForm extends Component<Props, State> {
const adaAssetFieldValue = adaAssetField.value;
const isAdaAssetValid = adaAssetField.isValid;
const { sendFormFields } = this.state;
let { assetsError } = this.state;
const receiver = sendFormFields[receiverId];
const selectedTokens = receiver.selectedNativeTokens;
const selectedTokenId = selectedTokens.length
Expand All @@ -1209,14 +1224,17 @@ export default class WalletAssetsSendForm extends Component<Props, State> {
) {
this.calculateTransactionFee(receiverValue, adaAssetFieldValue);
} else if (!isAmountLessThenMax) {
const transactionFeeError = this.context.intl.formatMessage(
messages.invalidAmount
);
const error = this.context.intl.formatMessage(messages.invalidAmount);
if (!assetsError) {
assetsError = [];
}
assetsError[selectedTokenId] = error;
this._isCalculatingTransactionFee = false;
this._isCalculatingAssetsFee = false;
this.setState({
isTransactionFeeCalculated: false,
transactionFee: new BigNumber(0),
transactionFeeError,
assetsError,
});
} else {
this.resetTransactionFee();
Expand Down
11 changes: 6 additions & 5 deletions source/renderer/app/containers/wallet/WalletSendPage.js
Expand Up @@ -83,12 +83,13 @@ export default class WalletSendPage extends Component<Props> {
hardwareWallets,
assets: assetsStore,
} = this.props.stores;
const { location } = this.props;
const { pathname } = location;
const splittedPath = pathname.split('/send/');
// $FlowFixMe
const locationPath = this.props.location;
const { pathname } = locationPath;
const splicedPath = pathname.split('/send/');
let tokenFingerprint = '';
if (splittedPath && splittedPath.length) {
tokenFingerprint = splittedPath[splittedPath.length - 1];
if (splicedPath && splicedPath.length) {
tokenFingerprint = splicedPath[splicedPath.length - 1];
}
const { isValidAddress } = wallets;
const { validateAmount } = transactions;
Expand Down

0 comments on commit 4bba50b

Please sign in to comment.