Skip to content

Commit

Permalink
Merge branch 'fix/zero-tx-amount' into 'develop'
Browse files Browse the repository at this point in the history
fix/zero-tx-amount

See merge request papers/airgap/airgap-wallet!724
  • Loading branch information
godenzim committed Nov 24, 2023
2 parents ebdbb06 + 7f22226 commit 074f49a
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/app/pages/transaction-prepare/transaction-prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class TransactionPreparePage {
receiverAddress: receiverAddress !== undefined ? receiverAddress : '',
disableSendMaxAmount: false,
disablePrepareButton:
this.transactionForm.invalid || receiverAddress === undefined || new BigNumber(this._state.amount.value).lte(0)
this.transactionForm.invalid || receiverAddress === undefined || new BigNumber(this._state.amount.value).lt(0)
})
this.updateFeeEstimate()
})
Expand All @@ -182,13 +182,14 @@ export class TransactionPreparePage {
.valueChanges.pipe(debounceTime(500))
.subscribe((value: string) => {
const amount = new BigNumber(value)

this.updateState({
sendMaxAmount: false,
amount: {
value: amount.isNaN() ? '' : amount.toFixed(),
dirty: true
},
disablePrepareButton: this.transactionForm.invalid || amount.isNaN() || amount.lte(0)
disablePrepareButton: this.transactionForm.invalid || amount.isNaN() || amount.lt(0)
})
this.updateFeeEstimate()
})
Expand All @@ -198,12 +199,13 @@ export class TransactionPreparePage {
.valueChanges.pipe(debounceTime(500))
.subscribe((value: string) => {
const fee = new BigNumber(value)

this.updateState({
fee: {
value: fee.isNaN() ? '' : fee.toFixed(),
dirty: true
},
disablePrepareButton: this.transactionForm.invalid || new BigNumber(this._state.amount.value).lte(0)
disablePrepareButton: this.transactionForm.invalid || new BigNumber(this._state.amount.value).lt(0)
})

if (this._state.sendMaxAmount) {
Expand All @@ -213,6 +215,7 @@ export class TransactionPreparePage {

this.transactionForm.get('feeLevel').valueChanges.subscribe((value: number) => {
const fee = new BigNumber(this.getFeeFromLevel(value))

this.updateState(
{
fee: {
Expand All @@ -223,7 +226,7 @@ export class TransactionPreparePage {
value,
dirty: true
},
disablePrepareButton: this.transactionForm.invalid || new BigNumber(this._state.amount.value).lte(0)
disablePrepareButton: this.transactionForm.invalid || new BigNumber(this._state.amount.value).lt(0)
},
false
)
Expand All @@ -240,7 +243,7 @@ export class TransactionPreparePage {
value,
dirty: true
},
disablePrepareButton: this.transactionForm.invalid || new BigNumber(this._state.amount.value).lte(0)
disablePrepareButton: this.transactionForm.invalid || new BigNumber(this._state.amount.value).lt(0)
},
false
)
Expand All @@ -253,7 +256,7 @@ export class TransactionPreparePage {
value,
dirty: true
},
disablePrepareButton: this.transactionForm.invalid || new BigNumber(this._state.amount.value).lte(0)
disablePrepareButton: this.transactionForm.invalid || new BigNumber(this._state.amount.value).lt(0)
},
false
)
Expand Down Expand Up @@ -460,7 +463,7 @@ export class TransactionPreparePage {
dirty: false
},
disableFeeSlider: !feeDefaults,
disablePrepareButton: !feeDefaults || this.transactionForm.invalid || new BigNumber(this._state.amount.value).lte(0)
disablePrepareButton: !feeDefaults || this.transactionForm.invalid || new BigNumber(this._state.amount.value).lt(0)
})
}
}
Expand All @@ -469,7 +472,7 @@ export class TransactionPreparePage {
const amount = new BigNumber(this._state.amount.value).shiftedBy(this.wallet.protocol.decimals)

const isAddressValid = this.transactionForm.controls.receiver.valid
const isAmountValid = this.transactionForm.controls.amount.valid && !amount.isNaN() && amount.gt(0)
const isAmountValid = this.transactionForm.controls.amount.valid && !amount.isNaN() && amount.gte(0)

return isAddressValid && isAmountValid && this._state.receiverAddress
? this.operationsProvider.estimateFees(this.wallet, this._state.receiverAddress, amount, { assetID: this.collectibleID })
Expand Down Expand Up @@ -575,7 +578,7 @@ export class TransactionPreparePage {
value: formAmount,
dirty: false
},
disablePrepareButton: this.transactionForm.invalid || maxAmount.isNaN() || maxAmount.lte(0)
disablePrepareButton: this.transactionForm.invalid || maxAmount.isNaN() || maxAmount.lt(0)
})
}
}
Expand All @@ -597,7 +600,7 @@ export class TransactionPreparePage {
receiverAddress: receiverAddress !== undefined ? receiverAddress : '',
disableSendMaxAmount: false,
disablePrepareButton:
this.transactionForm.invalid || receiverAddress === undefined || new BigNumber(this._state.amount.value).lte(0)
this.transactionForm.invalid || receiverAddress === undefined || new BigNumber(this._state.amount.value).lt(0)
})
this.transactionForm.controls.receiver.setValue(receiverAddress, { onlySelf: false, emitEvent: true })
},
Expand Down

0 comments on commit 074f49a

Please sign in to comment.