Use totalExecutedPerDay instead of totalSpentPerDay for calculating quota (#460)

This commit is contained in:
Kirill Fedoseev 2020-10-02 19:07:40 +03:00 committed by GitHub
parent 125b66b86d
commit 4cc87ef61a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

@ -325,7 +325,7 @@ class ForeignStore {
@action
async getCurrentLimit() {
try {
const result = await getCurrentLimit(this.foreignBridge, this.tokenDecimals)
const result = await getCurrentLimit(this.foreignBridge, this.homeStore.homeBridge, this.tokenDecimals)
this.maxCurrentDeposit = result.maxCurrentDeposit
this.dailyLimit = result.dailyLimit
this.totalSpentPerDay = result.totalSpentPerDay

@ -429,7 +429,11 @@ class HomeStore {
@action
async getCurrentLimit() {
try {
const result = await getCurrentLimit(this.homeBridge, this.tokenDecimals)
const result = await getCurrentLimit(
this.homeBridge,
this.rootStore.foreignStore.foreignBridge,
this.tokenDecimals
)
this.maxCurrentDeposit = result.maxCurrentDeposit
this.dailyLimit = result.dailyLimit
this.totalSpentPerDay = result.totalSpentPerDay

@ -21,10 +21,10 @@ export const getMinPerTxLimit = async (contract, decimals) => {
return fromDecimals(minPerTx, decimals)
}
export const getCurrentLimit = async (contract, decimals) => {
export const getCurrentLimit = async (contract, otherContract, decimals) => {
const currentDay = await contract.methods.getCurrentDay().call()
const dailyLimit = await contract.methods.dailyLimit().call()
const totalSpentPerDay = await contract.methods.totalSpentPerDay(currentDay).call()
const totalSpentPerDay = await otherContract.methods.totalExecutedPerDay(currentDay).call()
const maxCurrentDeposit = new BN(dailyLimit).minus(new BN(totalSpentPerDay)).toString(10)
return {
maxCurrentDeposit: fromDecimals(maxCurrentDeposit, decimals),