Skip to content

Commit

Permalink
fix(billing): properly check fee grant before tx
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrishajev committed Dec 30, 2024
1 parent 0cb2d0d commit b721141
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class ManagedUserWalletService {

private async authorizeFeeSpending(options: Omit<SpendingAuthorizationMsgOptions, "denom">) {
const messages: EncodeObject[] = [];
const hasValidFeeAllowance = await this.authzHttpService.hasValidFeeAllowance(options.granter, options.grantee);
const hasValidFeeAllowance = await this.authzHttpService.hasFeeAllowance(options.granter, options.grantee);

if (hasValidFeeAllowance) {
messages.push(this.rpcMessageService.getRevokeAllowanceMsg(options));
Expand All @@ -119,7 +119,7 @@ export class ManagedUserWalletService {
deploymentGrant: false
};

if (await this.authzHttpService.hasValidFeeAllowance(params.granter, params.grantee)) {
if (await this.authzHttpService.hasFeeAllowance(params.granter, params.grantee)) {
revokeSummary.feeAllowance = true;
messages.push(this.rpcMessageService.getRevokeAllowanceMsg(params));
}
Expand Down
2 changes: 1 addition & 1 deletion apps/api/test/functional/start-trial.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("start trial", () => {
const masterWalletAddress = await resolveWallet("MANAGED").getFirstAddress();
const allowances = await Promise.all([
authzHttpService.getDepositDeploymentGrantsForGranterAndGrantee(masterWalletAddress, userWallet.address),
authzHttpService.getFeeAllowancesForGrantee(userWallet.address)
authzHttpService.getValidFeeAllowancesForGrantee(userWallet.address)
]);

expect(createWalletResponse.status).toBe(200);
Expand Down
2 changes: 1 addition & 1 deletion apps/deploy-web/src/hooks/useWalletBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const useDenomData = (denom: string) => {

setDepositData(depositData);
}
}, [denom, isLoaded, price, walletBalance, usdcIbcDenom, minDeposit]);
}, [denom, isLoaded, price, walletBalance, usdcIbcDenom, minDeposit, isManaged, txFeeBuffer, aktToUSD]);

return depositData;
};
14 changes: 12 additions & 2 deletions packages/http-sdk/src/authz/authz-http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ export class AuthzHttpService extends HttpService {

async getFeeAllowancesForGrantee(address: string) {
const allowances = this.extractData(await this.get<FeeAllowanceListResponse>(`cosmos/feegrant/v1beta1/allowances/${address}`));
return allowances.allowances.filter(allowance => this.isValidFeeAllowance(allowance));
return allowances.allowances;
}

async getValidFeeAllowancesForGrantee(address: string) {
const allowances = await this.getFeeAllowancesForGrantee(address);
return allowances.filter(allowance => this.isValidFeeAllowance(allowance));
}

async getFeeAllowanceForGranterAndGrantee(granter: string, grantee: string): Promise<FeeAllowance | undefined> {
Expand Down Expand Up @@ -86,11 +91,16 @@ export class AuthzHttpService extends HttpService {
return response.grants.find(grant => this.isValidDepositDeploymentGrant(grant));
}

async hasValidFeeAllowance(granter: string, grantee: string) {
async hasFeeAllowance(granter: string, grantee: string) {
const feeAllowances = await this.getFeeAllowancesForGrantee(grantee);
return feeAllowances.some(allowance => allowance.granter === granter);
}

async hasValidFeeAllowance(granter: string, grantee: string) {
const feeAllowances = await this.getValidFeeAllowancesForGrantee(grantee);
return feeAllowances.some(allowance => allowance.granter === granter);
}

async hasValidDepositDeploymentGrant(granter: string, grantee: string) {
return !!(await this.getDepositDeploymentGrantsForGranterAndGrantee(granter, grantee))
}
Expand Down

0 comments on commit b721141

Please sign in to comment.