Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion react/lib/util/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const removeAddressPrefix = function (addressString: string): string {

type NetworkSlugsType = 'ecash' | 'bitcoincash'

const getAddressPrefix = function (addressString: string): NetworkSlugsType {
export const getAddressPrefix = function (addressString: string): NetworkSlugsType {
try {
const format = xecaddr.detectAddressFormat(addressString)
if (format === xecaddr.Format.Xecaddr) {
Expand Down
21 changes: 13 additions & 8 deletions react/lib/util/validate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BigNumber from "bignumber.js";
import { getCurrencyTypeFromAddress } from "./address";
import { getAddressPrefix, getCurrencyTypeFromAddress } from "./address";
import { resolveNumber } from "./number";
import { Currency, CurrencyObject, Transaction } from "./types";
import { DECIMALS } from "./constants";
Expand All @@ -19,9 +19,11 @@ export const shouldTriggerOnSuccess = (
paymentId,
rawMessage:rawOpReturn,
message,
amount,
address } = transaction;

amount,
address } = transaction;

const addressPrefix = getAddressPrefix(address);
const isBCH = addressPrefix === 'bitcoincash';
let isAmountValid = true;

if(expectedAmount) {
Expand All @@ -44,13 +46,16 @@ export const shouldTriggerOnSuccess = (
let isOpReturnValid = true

if(!randomSatoshis || randomSatoshis === 0){
const paymentIdsMatch = expectedPaymentId === paymentId;
isPaymentIdValid = disablePaymentId ? true : paymentIdsMatch;

if(!isBCH){
const paymentIdsMatch = expectedPaymentId === paymentId;
isPaymentIdValid = disablePaymentId ? true : paymentIdsMatch;
}
}
if(!isBCH){
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is really weird.

  1. Identation is missing
  2. The first three lines of the if clause are identical to what has just been done before entering the if (!isBCH) {...}
  3. The last two lines of the if clause are identical to what will be done after leaving the if (!isBCH) {...}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

should be good now

const rawOpReturnIsEmptyOrUndefined = rawOpReturn === '' || rawOpReturn === undefined;
const opReturn = rawOpReturnIsEmptyOrUndefined ? message : rawOpReturn
const opReturnIsEmptyOrUndefined = opReturn === '' || opReturn === undefined;

const opReturnsMatch = opReturn === expectedOpReturn;
isOpReturnValid = expectedOpReturn ? opReturnsMatch : opReturnIsEmptyOrUndefined;
}
Expand Down