Skip to content

Commit

Permalink
billingconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
akastercomcom committed Sep 13, 2023
1 parent 778b297 commit de87a41
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/modules/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit de87a41

Please sign in to comment.