Skip to content

Commit

Permalink
feat: [GSW-2040] Apply a higher-order function to all transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrg committed Jan 13, 2025
1 parent 775ef56 commit 8575a5c
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 118 deletions.
111 changes: 67 additions & 44 deletions packages/web/src/repositories/governance/governance-repository-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
makeVoteMessages,
} from "./governance.message";
import GetExecutableFunctionsResponseMock from "./mock/get-executable-functions-response.json";
import { withSocialWalletApproval } from "@utils/transaction-utils";

export class GovernanceRepositoryImpl implements GovernanceRepository {
private networkClient: NetworkClient | null;
Expand Down Expand Up @@ -165,10 +166,12 @@ export class GovernanceRepositoryImpl implements GovernanceRepository {
const caller = await this.getAddress();
const messages = makeProposalTextMessages({ ...request, caller });

return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
};

Expand All @@ -178,10 +181,12 @@ export class GovernanceRepositoryImpl implements GovernanceRepository {
const caller = await this.getAddress();
const messages = makeProposeCommunityPoolSpendMessages({ ...request, caller });

return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
};

Expand All @@ -191,43 +196,51 @@ export class GovernanceRepositoryImpl implements GovernanceRepository {
const caller = await this.getAddress();
const messages = makeProposeParameterChangeMessages({ ...request, caller });

return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
};

public sendVote = async (request: SendVoteReqeust): Promise<WalletResponse<{ hash: string }>> => {
const caller = await this.getAddress();
const messages = makeVoteMessages({ ...request, caller });

return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
};

public sendCancel = async (request: SendCancelReqeust): Promise<WalletResponse<{ hash: string }>> => {
const caller = await this.getAddress();
const messages = makeCancelMessages({ ...request, caller });

return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
};

public sendExecute = async (request: SendExecuteReqeust): Promise<WalletResponse<{ hash: string }>> => {
const caller = await this.getAddress();
const messages = makeExecuteMessages({ ...request, caller });

return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
};

Expand All @@ -241,21 +254,25 @@ export class GovernanceRepositoryImpl implements GovernanceRepository {
getGRC20Allowance(this.gnoProvider!, packagePath, owner, spender),
);

return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
};

public sendUndelegate = async (request: SendUndelegateReqeust): Promise<WalletResponse<{ hash: string }>> => {
const caller = await this.getAddress();
const messages = makeUnDelegateMessages({ ...request, caller });

return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
};

Expand All @@ -269,32 +286,38 @@ export class GovernanceRepositoryImpl implements GovernanceRepository {
getGRC20Allowance(this.gnoProvider!, packagePath, owner, spender),
);

return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
};

public sendCollectUndelegated = async (): Promise<WalletResponse<{ hash: string }>> => {
const caller = await this.getAddress();
const messages = makeCollectUnDelegatedGNSMessages({ caller });

return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
};

public sendCollectReward = async (): Promise<WalletResponse<{ hash: string }>> => {
const caller = await this.getAddress();
const messages = makeCollectRewardMessages({ caller });

return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CommonError } from "@common/errors";
import { DEFAULT_GAS_FEE } from "@common/values";
import { GnoProvider } from "@gnolang/gno-js-client";
import { makeQueryParameter } from "@utils/network.utils";
import { withSocialWalletApproval } from "@utils/transaction-utils";
import { LaunchpadRepository } from "./launchpad-repository";
import {
makeCollectRewardByDepositIdMessage,
Expand Down Expand Up @@ -109,10 +110,12 @@ export class LaunchpadRepositoryImpl implements LaunchpadRepository {
(packagePath, owner, spender) => getGRC20Allowance(this.gnoProvider!, packagePath, owner, spender),
);

return this.walletClient.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
}

Expand All @@ -123,10 +126,12 @@ export class LaunchpadRepositoryImpl implements LaunchpadRepository {

const messages = makeCollectRewardByProjectIdMessage({ projectId, caller });

return this.walletClient.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
}

Expand All @@ -137,10 +142,12 @@ export class LaunchpadRepositoryImpl implements LaunchpadRepository {

const messages = makeCollectRewardByDepositIdMessage({ depositId, caller });

return this.walletClient.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
}

Expand All @@ -151,10 +158,12 @@ export class LaunchpadRepositoryImpl implements LaunchpadRepository {

const messages = makeCollectRewardWithDepositByProjectIdMessage({ projectId, caller });

return this.walletClient.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
}

Expand All @@ -165,10 +174,12 @@ export class LaunchpadRepositoryImpl implements LaunchpadRepository {

const messages = makeCollectRewardWithDepositByDepositIdMessage({ depositId, caller });

return this.walletClient.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
}
}
19 changes: 13 additions & 6 deletions packages/web/src/repositories/pool/pool-repository-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { PoolDetailRPCModel } from "@models/pool/pool-detail-rpc-model";
import { IncentivizePoolModel, PoolModel } from "@models/pool/pool-model";
import { PoolStakingModel } from "@models/pool/pool-staking";
import { evaluateExpressionToNumber, evaluateExpressionToObject, makeABCIParams } from "@utils/rpc-utils";
import { withSocialWalletApproval } from "@utils/transaction-utils";
import { PoolListResponse, PoolRepository, PoolResponse } from ".";
import {
makeCreateExternalIncentiveMessageWithApproves,
Expand Down Expand Up @@ -248,9 +249,12 @@ export class PoolRepositoryImpl implements PoolRepository {

const messages = [...createPoolMessages, ...mintMessages, nftSetUriMessage];

return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
};

Expand All @@ -274,9 +278,12 @@ export class PoolRepositoryImpl implements PoolRepository {

const messages = [...mintMessages, nftSetUriMessage];

return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
return withSocialWalletApproval(this.walletClient, messages, () => {
return this.walletClient!.sendTransaction({
messages,
gasFee: DEFAULT_GAS_FEE,
memo: "",
});
});
};

Expand Down
Loading

0 comments on commit 8575a5c

Please sign in to comment.