Skip to content

Commit

Permalink
Merge pull request #208 from aptos-labs/omit_sender_prop
Browse files Browse the repository at this point in the history
Make sender optional when sign and submit single signer transaction
  • Loading branch information
gregnazario authored Dec 5, 2023
2 parents 6257015 + aa3d15a commit ed8fcdc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .changeset/slimy-dingos-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@aptos-labs/wallet-adapter-react": minor
"@aptos-labs/wallet-adapter-core": minor
"@aptos-labs/wallet-adapter-nextjs-example": minor
---

Make sender optional when sign and submit single signer transaction
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ export default function SingleSignerTransaction({

try {
const response = await signAndSubmitTransaction({
sender: account.address,
data: {
function: "0x1::coin::transfer",
typeArguments: [APTOS_COIN],
functionArguments: [account.address, 1], // 1 is in Octas
},
});
console.log("response", response);
await aptosClient(network?.name.toLowerCase()).waitForTransaction({
transactionHash: response.hash,
});
Expand All @@ -74,7 +72,6 @@ export default function SingleSignerTransaction({

try {
const response = await signAndSubmitTransaction({
sender: account.address,
data: {
function: "0x1::coin::transfer",
typeArguments: [parseTypeTag(APTOS_COIN)],
Expand All @@ -90,6 +87,7 @@ export default function SingleSignerTransaction({
}
};

// Legacy typescript sdk support
const onSignTransaction = async () => {
try {
const payload = {
Expand Down
11 changes: 7 additions & 4 deletions packages/wallet-adapter-core/src/WalletCore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { HexString, TxnBuilderTypes, Types, BCS } from "aptos";
import {
InputGenerateTransactionData,
AnyRawTransaction,
AccountAuthenticator,
AccountAuthenticatorEd25519,
Expand Down Expand Up @@ -42,6 +41,7 @@ import {
WalletInfo,
WalletCoreEvents,
SignMessageResponse,
InputTransactionData,
} from "./types";
import {
removeLocalStorage,
Expand Down Expand Up @@ -285,12 +285,12 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
/**
* Signs and submits a transaction to chain
*
* @param transactionInput InputGenerateTransactionData
* @param transactionInput InputTransactionData
* @param options optional. A configuration object to generate a transaction by
* @returns The pending transaction hash (V1 output) | PendingTransactionResponse (V2 output)
*/
async signAndSubmitTransaction(
transactionInput: InputGenerateTransactionData,
transactionInput: InputTransactionData,
options?: InputGenerateTransactionOptions
): Promise<
{ hash: Types.HexEncodedBytes; output?: any } | PendingTransactionResponse
Expand All @@ -301,7 +301,10 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
// wallet supports sdk v2
if (this._wallet?.version === "v2") {
const response = await this._wallet.signAndSubmitTransaction(
transactionInput,
{
...transactionInput,
sender: transactionInput.sender ?? this._account!.address,
},
options
);
// response should be PendingTransactionResponse
Expand Down
7 changes: 7 additions & 0 deletions packages/wallet-adapter-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
InputGenerateTransactionOptions,
InputSubmitTransactionData,
PendingTransactionResponse,
AccountAddressInput,
} from "@aptos-labs/ts-sdk";
import { WalletReadyState } from "./constants";

Expand Down Expand Up @@ -126,3 +127,9 @@ export interface TransactionOptions {
max_gas_amount?: bigint;
gas_unit_price?: bigint;
}

// Omit the ts-sdk InputGenerateTransactionData type to make "sender" optional
export type InputTransactionData = Omit<
InputGenerateTransactionData,
"sender"
> & { sender?: AccountAddressInput };
4 changes: 2 additions & 2 deletions packages/wallet-adapter-react/src/WalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import type {
WalletInfo,
InputGenerateTransactionOptions,
AnyRawTransaction,
InputGenerateTransactionData,
InputSubmitTransactionData,
AccountAuthenticator,
PendingTransactionResponse,
SignMessageResponse,
WalletName,
Types,
InputTransactionData,
} from "@aptos-labs/wallet-adapter-core";
import { WalletCore } from "@aptos-labs/wallet-adapter-core";

Expand Down Expand Up @@ -131,7 +131,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
};

const signAndSubmitTransaction = async (
transaction: InputGenerateTransactionData,
transaction: InputTransactionData,
options?: InputGenerateTransactionOptions
) => {
try {
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet-adapter-react/src/useWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
isRedirectable,
isMobile,
InputGenerateTransactionOptions,
InputGenerateTransactionData,
AnyRawTransaction,
InputTransactionData,
InputSubmitTransactionData,
PendingTransactionResponse,
AccountAuthenticator,
Expand Down Expand Up @@ -40,7 +40,7 @@ export interface WalletContextState {
wallet: WalletInfo | null;
wallets: ReadonlyArray<Wallet>;
signAndSubmitTransaction(
transaction: InputGenerateTransactionData,
transaction: InputTransactionData,
options?: InputGenerateTransactionOptions
): Promise<any>;
signTransaction(
Expand Down

0 comments on commit ed8fcdc

Please sign in to comment.