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

Commit

Permalink
Merge pull request #1883 from OpenBazaar/brian.fix-legacy-payout
Browse files Browse the repository at this point in the history
Check for v4 legacy payout amounts
  • Loading branch information
hoffmabc authored Apr 17, 2020
2 parents 4ba8e36 + b5f8c7b commit fef7fba
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 23 deletions.
58 changes: 42 additions & 16 deletions js/models/order/BaseOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,30 +196,56 @@ export default class extends BaseModel {

if (resolution && resolution.payout) {
if (resolution.payout.buyerOutput) {
resolution.payout.buyerOutput.bigAmount =
integerToDecimal(
resolution.payout.buyerOutput.bigAmount,
divisibility,
{ fieldName: 'buyerOutput.bigAmount' }
// legacy check
if (resolution.payout.buyerOutput.bigAmount === '') {
resolution.payout.buyerOutput.bigAmount = integerToDecimal(
resolution.payout.buyerOutput.amount,
8
);
} else {
resolution.payout.buyerOutput.bigAmount =
integerToDecimal(
resolution.payout.buyerOutput.bigAmount,
divisibility,
{ fieldName: 'buyerOutput.bigAmount' }
);
}
}

if (resolution.payout.vendorOutput) {
resolution.payout.vendorOutput.bigAmount =
integerToDecimal(
resolution.payout.vendorOutput.bigAmount,
divisibility,
{ fieldName: 'vendorOutput.bigAmount' }
// legacy check
if (resolution.payout.vendorOutput.bigAmount === '') {
resolution.payout.vendorOutput.bigAmount = integerToDecimal(
resolution.payout.vendorOutput.amount,
8
);
} else {
resolution.payout.vendorOutput.bigAmount =
integerToDecimal(
resolution.payout.vendorOutput.bigAmount,
divisibility,
{ fieldName: 'vendorOutput.bigAmount' }
);
}
}

if (resolution.payout.moderatorOutput) {
resolution.payout.moderatorOutput.bigAmount =
integerToDecimal(
resolution.payout.moderatorOutput.bigAmount,
divisibility,
{ fieldName: 'moderatorOutput.bigAmount' }
);
if (resolution.payout.moderatorOutput) {
// legacy check
if (resolution.payout.moderatorOutput.bigAmount === '') {
resolution.payout.moderatorOutput.bigAmount = integerToDecimal(
resolution.payout.moderatorOutput.amount,
8
);
} else {
resolution.payout.moderatorOutput.bigAmount =
integerToDecimal(
resolution.payout.moderatorOutput.bigAmount,
divisibility,
{ fieldName: 'moderatorOutput.bigAmount' }
);
}
}
}
}

Expand Down
21 changes: 14 additions & 7 deletions js/models/profile/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,20 @@ export default class Profile extends BaseModel {
response.moderatorInfo.fee.fixedFee
) {
try {
response.moderatorInfo.fee.fixedFee = {
amount: curDefToDecimal(response.moderatorInfo.fee.fixedFee, {
amountKey: 'bigAmount',
currencyKey: 'amountCurrency',
}),
currencyCode: response.moderatorInfo.fee.fixedFee.amountCurrency.code,
};
if (response.moderatorInfo.fee.fixedFee.bigAmount === '') { // legacy fixed fee
response.moderatorInfo.fee.fixedFee = {
amount: response.moderatorInfo.fee.fixedFee.amount,
currencyKey: response.moderatorInfo.fee.fixedFee.currencyCode,
};
} else {
response.moderatorInfo.fee.fixedFee = {
amount: curDefToDecimal(response.moderatorInfo.fee.fixedFee, {
amountKey: 'bigAmount',
currencyKey: 'amountCurrency',
}),
currencyCode: response.moderatorInfo.fee.fixedFee.amountCurrency.code,
};
}
} catch (e) {
delete response.moderatorInfo.fixedFee;
console.error(`Unable to convert the moderator fee from base units: ${e.message}`);
Expand Down
3 changes: 3 additions & 0 deletions js/views/modals/orderDetail/summaryTab/Summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,11 @@ export default class extends BaseVw {
}
}

console.log(this.model.contract);

if (
(orderState !== 'DISPUTED' && !escrowTimeoutHours) ||
(this.model.contract.dispute !== '') ||
(orderState === 'DISPUTED' && !Date.parse(disputeStartTime))
) {
// contract probably forged
Expand Down

0 comments on commit fef7fba

Please sign in to comment.