Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate options argument on signAndSubmitTransaction #210

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/grumpy-forks-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@aptos-labs/wallet-adapter-react": patch
"@aptos-labs/wallet-adapter-core": patch
---

Consolidate options argument on signAndSubmitTransaction
30 changes: 13 additions & 17 deletions packages/wallet-adapter-core/src/WalletCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
* @returns The pending transaction hash (V1 output) | PendingTransactionResponse (V2 output)
*/
async signAndSubmitTransaction(
transactionInput: InputTransactionData,
options?: InputGenerateTransactionOptions
transactionInput: InputTransactionData
): Promise<
{ hash: Types.HexEncodedBytes; output?: any } | PendingTransactionResponse
> {
Expand All @@ -300,13 +299,10 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {

// wallet supports sdk v2
if (this._wallet?.version === "v2") {
const response = await this._wallet.signAndSubmitTransaction(
{
...transactionInput,
sender: transactionInput.sender ?? this._account!.address,
},
options
);
const response = await this._wallet.signAndSubmitTransaction({
...transactionInput,
sender: transactionInput.sender ?? this._account!.address,
});
// response should be PendingTransactionResponse
return response;
}
Expand All @@ -330,11 +326,11 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
oldTransactionPayload,
this._wallet!,
{
max_gas_amount: options?.maxGasAmount
? BigInt(options?.maxGasAmount)
max_gas_amount: transactionInput.options?.maxGasAmount
? BigInt(transactionInput.options?.maxGasAmount)
: undefined,
gas_unit_price: options?.gasUnitPrice
? BigInt(options?.gasUnitPrice)
gas_unit_price: transactionInput.options?.gasUnitPrice
? BigInt(transactionInput.options?.gasUnitPrice)
: undefined,
}
);
Expand All @@ -350,11 +346,11 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
oldTransactionPayload,
this._wallet!,
{
max_gas_amount: options?.maxGasAmount
? BigInt(options?.maxGasAmount)
max_gas_amount: transactionInput.options?.maxGasAmount
? BigInt(transactionInput.options?.maxGasAmount)
: undefined,
gas_unit_price: options?.gasUnitPrice
? BigInt(options?.gasUnitPrice)
gas_unit_price: transactionInput.options?.gasUnitPrice
? BigInt(transactionInput.options?.gasUnitPrice)
: undefined,
}
);
Expand Down
11 changes: 6 additions & 5 deletions packages/wallet-adapter-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
InputSubmitTransactionData,
PendingTransactionResponse,
AccountAddressInput,
InputGenerateTransactionPayloadData,
} from "@aptos-labs/ts-sdk";
import { WalletReadyState } from "./constants";

Expand Down Expand Up @@ -128,8 +129,8 @@ export interface TransactionOptions {
gas_unit_price?: bigint;
}

// Omit the ts-sdk InputGenerateTransactionData type to make "sender" optional
export type InputTransactionData = Omit<
InputGenerateTransactionData,
"sender"
> & { sender?: AccountAddressInput };
export type InputTransactionData = {
sender?: AccountAddressInput;
data: InputGenerateTransactionPayloadData;
options?: InputGenerateTransactionOptions;
};
5 changes: 2 additions & 3 deletions packages/wallet-adapter-react/src/WalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,10 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
};

const signAndSubmitTransaction = async (
transaction: InputTransactionData,
options?: InputGenerateTransactionOptions
transaction: InputTransactionData
) => {
try {
return await walletCore.signAndSubmitTransaction(transaction, options);
return await walletCore.signAndSubmitTransaction(transaction);
} catch (error: any) {
if (onError) onError(error);
return Promise.reject(error);
Expand Down
5 changes: 1 addition & 4 deletions packages/wallet-adapter-react/src/useWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ export interface WalletContextState {
disconnect(): void;
wallet: WalletInfo | null;
wallets: ReadonlyArray<Wallet>;
signAndSubmitTransaction(
transaction: InputTransactionData,
options?: InputGenerateTransactionOptions
): Promise<any>;
signAndSubmitTransaction(transaction: InputTransactionData): Promise<any>;
signTransaction(
transactionOrPayload: AnyRawTransaction | Types.TransactionPayload,
asFeePayer?: boolean,
Expand Down
Loading