From de87a41685ecc8e9adbc8f5e6a4af5ec3bb1367d Mon Sep 17 00:00:00 2001 From: akaster99 Date: Wed, 13 Sep 2023 15:51:22 +0900 Subject: [PATCH] billingconfig --- src/modules/app.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/modules/app.ts b/src/modules/app.ts index 7f92ce5..5ea4eb2 100644 --- a/src/modules/app.ts +++ b/src/modules/app.ts @@ -161,11 +161,19 @@ export default class App extends ModuleBase { */ async checkCostAndBalance(appName: string, serviceName: string, value: string, requesterAddress?: string) { requesterAddress = requesterAddress ? requesterAddress : this.getDefaultAccount().address; - const billingConfig = await this.getBillingConfig(appName); + const billingConfig = (await this.getBillingConfig(appName)).service; + const serviceBillingConfig = billingConfig.default; // TODO(woojae): calculate cost more accurately - let serviceBillingConfig = billingConfig.service.default; - if(billingConfig.service[serviceName]) { - serviceBillingConfig = billingConfig.service[serviceName]; + if(billingConfig[serviceName]) { + if(billingConfig[serviceName].costPerToken) { + serviceBillingConfig.costPerToken = billingConfig[serviceName].costPerToken; + } + if(billingConfig[serviceName].minCost) { + serviceBillingConfig.minCost = billingConfig[serviceName].minCost; + } + if(billingConfig[serviceName].maxCost) { + serviceBillingConfig.maxCost = billingConfig[serviceName].maxCost; + } } const token = value.split(' ').length; let cost = token * serviceBillingConfig.costPerToken;