Skip to content
Open
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
8 changes: 4 additions & 4 deletions mb-xrpl/lib/message-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ class MessageBoard {
}
}
console.log(`Refunding tenant ${uriToken.Owner}...`);
await this.hostClient.refundTenant(lease.tx_hash, uriToken.Owner, uriInfo.leaseAmount.toString(), { submissionRef: submissionRefs?.refs[0] });
await this.hostClient.refundTenant(lease.tx_hash, uriToken.Owner, UtilHelper.formatXrplAmount(uriInfo.leaseAmount), { submissionRef: submissionRefs?.refs[0] });
});
}
else {
Expand Down Expand Up @@ -970,7 +970,7 @@ class MessageBoard {
// If lease is in ACQUIRING status acquire response is not received by the tenant and lease is not in expiry list.
if (lease.status === LeaseStatus.ACQUIRING) {
console.log(`Refunding tenant ${uriToken.Owner}...`);
await this.hostClient.refundTenant(lease.tx_hash, uriToken.Owner, uriInfo.leaseAmount.toString(), { submissionRef: submissionRefs?.refs[0] });
await this.hostClient.refundTenant(lease.tx_hash, uriToken.Owner, UtilHelper.formatXrplAmount(uriInfo.leaseAmount), { submissionRef: submissionRefs?.refs[0] });
}
});
}
Expand Down Expand Up @@ -1101,7 +1101,7 @@ class MessageBoard {
}
}
console.log(`Refunding tenant ${eventInfo.data.tenant} for acquire...`);
await this.hostClient.refundTenant(trx.hash, eventInfo.data.tenant, uriInfo.leaseAmount.toString(), { submissionRef: submissionRefs?.refs[0] });
await this.hostClient.refundTenant(trx.hash, eventInfo.data.tenant, UtilHelper.formatXrplAmount(uriInfo.leaseAmount), { submissionRef: submissionRefs?.refs[0] });
});
}
}
Expand All @@ -1128,7 +1128,7 @@ class MessageBoard {
}
// The refund for the extension, if tenant still own the URIToken.
console.log(`Refunding tenant ${eventInfo.data.tenant} for extend...`);
await this.hostClient.refundTenant(trx.hash, eventInfo.data.tenant, eventInfo.data.payment.toString(), { submissionRef: submissionRefs?.refs[0] });
await this.hostClient.refundTenant(trx.hash, eventInfo.data.tenant, UtilHelper.formatXrplAmount(eventInfo.data.payment), { submissionRef: submissionRefs?.refs[0] });
});
} else {
console.log(`No such URIToken (${eventInfo.data.uriTokenId}) was found.`);
Expand Down
3 changes: 2 additions & 1 deletion mb-xrpl/lib/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,8 @@ class Setup {
const remainingMoments = lease.life_moments - spentMoments;
if (remainingMoments > 0) {
console.log(`Refunding tenant ${lease.tenant_xrp_address}...`);
await hostClient.refundTenant(lease.tx_hash, lease.tenant_xrp_address, (uriInfo.leaseAmount * remainingMoments).toString(), { retryOptions: { maxRetryAttempts: MAX_TX_RETRY_ATTEMPTS, feeUplift: Math.floor(acc.affordableExtraFee / MAX_TX_RETRY_ATTEMPTS) } });
const refundAmount = UtilHelper.formatXrplAmount(uriInfo.leaseAmount, remainingMoments);
await hostClient.refundTenant(lease.tx_hash, lease.tenant_xrp_address, refundAmount, { retryOptions: { maxRetryAttempts: MAX_TX_RETRY_ATTEMPTS, feeUplift: Math.floor(acc.affordableExtraFee / MAX_TX_RETRY_ATTEMPTS) } });
}
}

Expand Down
9 changes: 9 additions & 0 deletions mb-xrpl/lib/util-helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const ip6addr = require('ip6addr');
const Decimal = require('decimal.js');

class UtilHelper {

Expand Down Expand Up @@ -38,6 +39,14 @@ class UtilHelper {
return false;
}
}

static formatXrplAmount(amount, multiplier = 1) {
Decimal.set({ precision: 15, rounding: Decimal.ROUND_DOWN, toExpNeg: -15, toExpPos: 15 });
return new Decimal(amount)
.times(multiplier)
.toSignificantDigits(15)
.toFixed();
}
}

module.exports = {
Expand Down
7 changes: 4 additions & 3 deletions mb-xrpl/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mb-xrpl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"build": "npm run lint && ncc build app.js --minify -o dist"
},
"dependencies": {
"decimal.js": "10.6.0",
"evernode-js-client": "0.6.60",
"ip6addr": "0.2.5",
"sqlite3": "5.1.7"
Expand Down