@dynamic-labs/aptos 4.43.0 → 4.44.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +7 -6
  5. package/src/connectors/AptosWalletConnector/AptosWalletConnector.cjs +46 -5
  6. package/src/connectors/AptosWalletConnector/AptosWalletConnector.d.ts +13 -2
  7. package/src/connectors/AptosWalletConnector/AptosWalletConnector.js +46 -5
  8. package/src/index.cjs +4 -0
  9. package/src/index.d.ts +2 -0
  10. package/src/index.js +2 -0
  11. package/src/injected/InjectedWalletBase.cjs +3 -3
  12. package/src/injected/InjectedWalletBase.js +3 -3
  13. package/src/injected/fetchInjectedWalletConnectors.cjs +52 -34
  14. package/src/injected/fetchInjectedWalletConnectors.d.ts +8 -5
  15. package/src/injected/fetchInjectedWalletConnectors.js +52 -34
  16. package/src/types.d.ts +3 -0
  17. package/src/utils/AptosUiTransaction/AptosUiTransaction.cjs +189 -0
  18. package/src/utils/AptosUiTransaction/AptosUiTransaction.d.ts +110 -0
  19. package/src/utils/AptosUiTransaction/AptosUiTransaction.js +185 -0
  20. package/src/utils/AptosUiTransaction/index.d.ts +1 -0
  21. package/src/utils/constants/constants.cjs +8 -0
  22. package/src/utils/constants/constants.d.ts +1 -0
  23. package/src/utils/constants/constants.js +4 -0
  24. package/src/utils/constants/index.d.ts +1 -0
  25. package/src/wallet/AptosWallet.cjs +5 -8
  26. package/src/wallet/AptosWallet.d.ts +2 -2
  27. package/src/wallet/AptosWallet.js +5 -8
  28. package/src/wallet/isAptosWallet/index.d.ts +1 -0
  29. package/src/wallet/isAptosWallet/isAptosWallet.cjs +8 -0
  30. package/src/wallet/isAptosWallet/isAptosWallet.d.ts +3 -0
  31. package/src/wallet/isAptosWallet/isAptosWallet.js +4 -0
  32. package/src/walletStandard/createAptosSignerFromWalletStandard.cjs +1 -1
  33. package/src/walletStandard/createAptosSignerFromWalletStandard.js +1 -1
@@ -73,24 +73,27 @@ const shouldAddWalletStandardConnector = (wallet, walletBook) => {
73
73
  * Fetches all available injected Aptos wallet connectors.
74
74
  *
75
75
  * This function discovers and creates wallet connector constructors from two sources:
76
- * 1. Wallet book entries - Traditional wallets defined in the wallet book
77
- * 2. Wallet-standard wallets - AIP-62 compliant wallets discovered via wallet-standard
76
+ * 1. Wallet book entries - All Aptos wallets defined in the wallet book (including uninstalled wallet-standard wallets)
77
+ * 2. Wallet-standard wallets - AIP-62 compliant wallets discovered via wallet-standard (installed wallets only)
78
+ *
79
+ * The function creates connectors for:
80
+ * - Installed wallet-standard wallets (discovered via wallet-standard)
81
+ * - Uninstalled wallet-standard wallets (from wallet book, will use wallet-standard when installed)
82
+ * - Traditional wallets without wallet-standard support (from wallet book)
78
83
  *
79
84
  * The function automatically filters out wallets that:
80
85
  * - Have custom connector implementations
81
- * - Are already handled by wallet-standard connectors
86
+ * - Are already discovered via wallet-standard (to avoid duplicates)
82
87
  * - Don't support the required Aptos feature set
83
88
  *
84
89
  * @param options - Configuration options
85
90
  * @param options.walletBook - The wallet book schema containing wallet metadata
86
- * @param options.authMode - The authentication mode for filtering wallet features
87
91
  * @returns Array of wallet connector constructor classes
88
92
  *
89
93
  * @example
90
94
  * ```typescript
91
95
  * const connectors = fetchInjectedWalletConnectors({
92
96
  * walletBook,
93
- * authMode: 'connect-and-sign'
94
97
  * });
95
98
  *
96
99
  * // Instantiate connectors
@@ -101,40 +104,15 @@ const shouldAddWalletStandardConnector = (wallet, walletBook) => {
101
104
  */
102
105
  const fetchInjectedWalletConnectors = ({ walletBook, }) => {
103
106
  var _a;
104
- // Get wallet book connectors for traditional Aptos wallets
105
- const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
106
- .filter(([key, wallet]) => {
107
- var _a, _b, _c;
108
- const injectedConfig = (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'aptos');
109
- const isAptosWallet = Boolean(injectedConfig);
110
- // Filter out wallets that require a custom connector or wallets that support wallet-standard,
111
- // since they are already handled automatically with the wallet-standard connector
112
- const shouldBeFiltered = walletsWithCustomConnectors.includes(key) ||
113
- ((_c = (_b = injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig.walletStandard) === null || _b === void 0 ? void 0 : _b.features) === null || _c === void 0 ? void 0 : _c.length);
114
- return isAptosWallet && !shouldBeFiltered;
115
- })
116
- .map(([key, wallet]) => {
117
- const { shortName } = wallet;
118
- const name = shortName || wallet.name;
119
- return class extends InjectedWalletBase {
120
- constructor() {
121
- super(...arguments);
122
- this.name = name;
123
- // This is the key from the wallet book entry so that we don't purely rely on the normalized name
124
- this.overrideKey = key;
125
- }
126
- getProvider() {
127
- return this.findProvider();
128
- }
129
- };
130
- });
131
- // Get wallet-standard wallets
107
+ // Get wallet-standard wallets (only installed wallets are discovered)
132
108
  const { aptosWallets } = getWalletStandardWallets();
109
+ // Create a map of wallet-standard wallet names for quick lookup
110
+ const walletStandardWalletNames = new Set(aptosWallets.map((wallet) => wallet.name));
133
111
  logger.logVerboseTroubleshootingMessage('[APTOS fetchInjectedWalletConnectors] Found wallet-standard wallets:', aptosWallets.map((w) => ({
134
112
  features: Object.keys(w.features),
135
113
  name: w.name,
136
114
  })));
137
- // Create connectors for wallet-standard wallets
115
+ // Create connectors for installed wallet-standard wallets
138
116
  const walletStandardConnectors = aptosWallets
139
117
  .filter((wallet) =>
140
118
  // Type incompatibility between @wallet-standard versions, casting is safe here
@@ -156,6 +134,46 @@ const fetchInjectedWalletConnectors = ({ walletBook, }) => {
156
134
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
157
135
  wallet, walletBookMetadata);
158
136
  });
137
+ // Get wallet book connectors for ALL Aptos wallets
138
+ // This includes:
139
+ // 1. Traditional wallets (no wallet-standard support)
140
+ // 2. Wallet-standard wallets that are NOT yet installed (discovered via wallet book)
141
+ const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
142
+ .filter(([key, wallet]) => {
143
+ var _a, _b;
144
+ const injectedConfig = (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'aptos');
145
+ const isAptosWallet = Boolean(injectedConfig);
146
+ // Filter out wallets that require a custom connector
147
+ const needsCustomConnector = walletsWithCustomConnectors.includes(key);
148
+ // Filter out wallets that are already discovered via wallet-standard (installed)
149
+ // We want to show uninstalled wallet-standard wallets from wallet book
150
+ const walletStandardName = (_b = injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig.walletStandard) === null || _b === void 0 ? void 0 : _b.name;
151
+ const isAlreadyDiscoveredViaWalletStandard = walletStandardName && walletStandardWalletNames.has(walletStandardName);
152
+ return (isAptosWallet &&
153
+ !needsCustomConnector &&
154
+ !isAlreadyDiscoveredViaWalletStandard);
155
+ })
156
+ .map(([key, wallet]) => {
157
+ const { shortName } = wallet;
158
+ const name = shortName || wallet.name;
159
+ // Get wallet metadata from wallet book
160
+ const walletBookMetadata = getWalletMetadataFromWalletBook({
161
+ walletBook,
162
+ walletBookWallet: wallet,
163
+ walletKey: key,
164
+ });
165
+ return class extends InjectedWalletBase {
166
+ constructor(props) {
167
+ super(name, Object.assign(Object.assign({}, props), { aptosNetworks: props.aptosNetworks, metadata: walletBookMetadata, walletBook: props.walletBook }));
168
+ this.name = name;
169
+ // This is the key from the wallet book entry so that we don't purely rely on the normalized name
170
+ this.overrideKey = key;
171
+ }
172
+ getProvider() {
173
+ return this.findProvider();
174
+ }
175
+ };
176
+ });
159
177
  logger.logVerboseTroubleshootingMessage('[APTOS fetchInjectedWalletConnectors] Created wallet-standard connectors:', walletStandardConnectors.map((w) => w.name));
160
178
  logger.logVerboseTroubleshootingMessage('[APTOS fetchInjectedWalletConnectors] Created wallet-book connectors:', walletBookConnectors.map((w) => w.name));
161
179
  return [
package/src/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { AccountAuthenticator, AnyRawTransaction } from '@aptos-labs/ts-sdk';
2
2
  import type { AccountInfo, AptosSignMessageInput, AptosSignMessageOutput, NetworkInfo, UserResponse } from '@aptos-labs/wallet-standard';
3
+ import { GenericNetwork } from '@dynamic-labs/types';
3
4
  import { ProviderCondition } from '@dynamic-labs/wallet-connector-core';
4
5
  /**
5
6
  * Interface for AIP-62 compliant Aptos wallet providers.
@@ -123,6 +124,8 @@ export interface AptosWalletConnectorProps {
123
124
  walletBook: any;
124
125
  /** Wallet metadata */
125
126
  metadata?: any;
127
+ /** Aptos networks */
128
+ aptosNetworks?: GenericNetwork[];
126
129
  }
127
130
  export type AptosFeatureName = keyof NonNullable<IAptosProvider['features']>;
128
131
  export type AptosMethodName = 'connect' | 'disconnect' | 'signTransaction' | 'signMessage' | 'signAndSubmitTransaction' | 'submitTransaction' | 'getNetwork' | 'network' | 'account' | 'onAccountChange' | 'onNetworkChange';
@@ -0,0 +1,189 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../_virtual/_tslib.cjs');
7
+ var utils = require('@dynamic-labs/utils');
8
+ var constants = require('../constants/constants.cjs');
9
+
10
+ /**
11
+ * Aptos UI Transaction class for managing Aptos transactions in the UI.
12
+ *
13
+ * This class implements the IUITransaction interface and provides Aptos-specific
14
+ * functionality for creating, formatting, and submitting transactions.
15
+ */
16
+ class AptosUiTransaction {
17
+ constructor({ onSubmit, from, client }) {
18
+ this.chain = 'APTOS';
19
+ this.data = undefined;
20
+ this.fee = { gas: undefined };
21
+ /**
22
+ * Formats a non-native token value back to a string
23
+ *
24
+ * @param value - The value as bigint
25
+ * @param decimals - The number of decimals for the token
26
+ * @returns The formatted amount as string
27
+ */
28
+ this.formatNonNativeToken = (value, decimals) => (Number(value) / Number(Math.pow(10, decimals))).toString();
29
+ this.from = from;
30
+ this.onSubmit = onSubmit;
31
+ this.client = client;
32
+ }
33
+ /**
34
+ * Fetches the gas fee for the transaction.
35
+ *
36
+ * Note: Aptos gas fees are typically fixed or very low, so we set a default
37
+ * estimate. In the future, this could be enhanced with actual gas estimation.
38
+ *
39
+ * @returns The gas fee for the transaction
40
+ */
41
+ fetchFee() {
42
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
43
+ if (this.fee.gas)
44
+ return;
45
+ const transaction = yield this.createTransactionSafe();
46
+ if (!transaction) {
47
+ throw new Error('Could not create a valid Aptos transaction, check your address and value');
48
+ }
49
+ // Aptos has a simple gas model. For now, we'll use a default estimate.
50
+ // In the future, this could use the client to simulate the transaction.
51
+ // Typical Aptos transactions cost around 100-1000 octas (0.0000001 - 0.000001 APT)
52
+ // We'll use a conservative estimate of 1000 octas
53
+ this.fee.gas = BigInt(1000);
54
+ });
55
+ }
56
+ isGasSponsored() {
57
+ return false;
58
+ }
59
+ /**
60
+ * Parses a string amount into bigint octas (APT smallest unit, 1e8)
61
+ *
62
+ * @param input - The amount as a string (e.g., "1.5")
63
+ * @returns The amount in octas as bigint
64
+ */
65
+ parse(input) {
66
+ const floatValue = parseFloat(input);
67
+ const octas = Math.round(floatValue * constants.OCTAS_PER_APT);
68
+ return BigInt(octas);
69
+ }
70
+ /**
71
+ * Parses a non-native token amount with custom decimals
72
+ *
73
+ * @param input - The amount as a string
74
+ * @param decimals - The number of decimals for the token
75
+ * @returns The amount as bigint
76
+ */
77
+ parseNonNativeToken(input, decimals) {
78
+ return BigInt(Math.floor(Number(input) * Math.pow(10, decimals)));
79
+ }
80
+ /**
81
+ * Formats a bigint value (in octas) to a human-readable APT string
82
+ *
83
+ * @param value - The value in octas
84
+ * @param options - Formatting options including precision
85
+ * @returns The formatted amount as string
86
+ */
87
+ format(value, { precision } = {}) {
88
+ const aptValue = Number(value) / constants.OCTAS_PER_APT;
89
+ const decimalString = aptValue.toLocaleString('fullwide', {
90
+ maximumFractionDigits: 20,
91
+ minimumFractionDigits: 0,
92
+ useGrouping: false,
93
+ });
94
+ return utils.formatNumberText(decimalString, { precision });
95
+ }
96
+ /**
97
+ * Submits the transaction by creating it and calling onSubmit
98
+ *
99
+ * @returns The transaction hash from onSubmit
100
+ */
101
+ submit() {
102
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
103
+ const sendTransaction = (yield this.createTransaction());
104
+ return this.onSubmit(sendTransaction);
105
+ });
106
+ }
107
+ /**
108
+ * Gets the balance of the sender's account in octas
109
+ *
110
+ * @returns The balance as bigint in octas
111
+ */
112
+ getBalance() {
113
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
114
+ const balance = yield this.client.getBalance({
115
+ accountAddress: this.from,
116
+ // APT coin type
117
+ asset: '0x1::aptos_coin::AptosCoin',
118
+ });
119
+ // Balance comes back as a number in octas (1e8 octas = 1 APT)
120
+ return BigInt(Math.floor(balance));
121
+ });
122
+ }
123
+ /**
124
+ * Validates that an address is a valid Aptos address format
125
+ *
126
+ * Aptos addresses are 64-character hex strings prefixed with 0x (66 chars total)
127
+ *
128
+ * @param address - The address to validate
129
+ * @returns true if the address format is valid
130
+ */
131
+ validateAddressFormat(address) {
132
+ if (address === 'dyn_send_transaction.multiple_recipients') {
133
+ return true;
134
+ }
135
+ // Aptos addresses are 0x followed by 64 hex characters
136
+ return /^0x[0-9a-fA-F]{64}$/.test(address);
137
+ }
138
+ /**
139
+ * Creates a transaction payload for sending APT or tokens
140
+ *
141
+ * @returns The transaction payload or undefined if invalid
142
+ */
143
+ createTransaction() {
144
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
145
+ const { value, to, nonNativeAddress, nonNativeValue } = this;
146
+ if (!to) {
147
+ throw new Error('Destination is required');
148
+ }
149
+ if (!value && !nonNativeValue) {
150
+ return undefined;
151
+ }
152
+ // Create the transaction payload
153
+ if (nonNativeAddress && nonNativeValue) {
154
+ // Transfer non-native token
155
+ return {
156
+ function: '0x1::coin::transfer',
157
+ functionArguments: [to, nonNativeValue],
158
+ typeArguments: [nonNativeAddress],
159
+ };
160
+ }
161
+ if (value) {
162
+ // Transfer native APT
163
+ return {
164
+ function: '0x1::coin::transfer',
165
+ functionArguments: [to, value],
166
+ typeArguments: ['0x1::aptos_coin::AptosCoin'],
167
+ };
168
+ }
169
+ return undefined;
170
+ });
171
+ }
172
+ /**
173
+ * Safely creates a transaction, returning undefined on error
174
+ *
175
+ * @returns The transaction payload or undefined if creation fails
176
+ */
177
+ createTransactionSafe() {
178
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
179
+ try {
180
+ return yield this.createTransaction();
181
+ }
182
+ catch (error) {
183
+ return undefined;
184
+ }
185
+ });
186
+ }
187
+ }
188
+
189
+ exports.AptosUiTransaction = AptosUiTransaction;
@@ -0,0 +1,110 @@
1
+ import type { InputGenerateTransactionPayloadData } from '@aptos-labs/ts-sdk';
2
+ import { Aptos } from '@aptos-labs/ts-sdk';
3
+ import { IUITransaction, IUITransactionFormatOptions } from '@dynamic-labs/types';
4
+ type AptosUiTransactionProps = {
5
+ /** Aptos Address of the sender */
6
+ from: string;
7
+ /** The [Aptos] client instance, needed to estimate gas fees and get balance */
8
+ client: Aptos;
9
+ /** The function to call when the transaction is submitted */
10
+ onSubmit: (transaction?: InputGenerateTransactionPayloadData) => Promise<any>;
11
+ };
12
+ /**
13
+ * Aptos UI Transaction class for managing Aptos transactions in the UI.
14
+ *
15
+ * This class implements the IUITransaction interface and provides Aptos-specific
16
+ * functionality for creating, formatting, and submitting transactions.
17
+ */
18
+ export declare class AptosUiTransaction implements IUITransaction {
19
+ to: string | undefined;
20
+ from: string;
21
+ value: bigint | undefined;
22
+ chain: string;
23
+ receipt: string | undefined;
24
+ data: undefined;
25
+ fee: {
26
+ gas: bigint | undefined;
27
+ };
28
+ nonNativeAddress?: string;
29
+ nonNativeDecimal?: number;
30
+ nonNativeValue?: bigint;
31
+ nativePrice?: number;
32
+ private onSubmit;
33
+ private client;
34
+ constructor({ onSubmit, from, client }: AptosUiTransactionProps);
35
+ /**
36
+ * Fetches the gas fee for the transaction.
37
+ *
38
+ * Note: Aptos gas fees are typically fixed or very low, so we set a default
39
+ * estimate. In the future, this could be enhanced with actual gas estimation.
40
+ *
41
+ * @returns The gas fee for the transaction
42
+ */
43
+ fetchFee(): Promise<void>;
44
+ isGasSponsored(): boolean;
45
+ /**
46
+ * Parses a string amount into bigint octas (APT smallest unit, 1e8)
47
+ *
48
+ * @param input - The amount as a string (e.g., "1.5")
49
+ * @returns The amount in octas as bigint
50
+ */
51
+ parse(input: string): bigint;
52
+ /**
53
+ * Parses a non-native token amount with custom decimals
54
+ *
55
+ * @param input - The amount as a string
56
+ * @param decimals - The number of decimals for the token
57
+ * @returns The amount as bigint
58
+ */
59
+ parseNonNativeToken(input: string, decimals: number): bigint;
60
+ /**
61
+ * Formats a non-native token value back to a string
62
+ *
63
+ * @param value - The value as bigint
64
+ * @param decimals - The number of decimals for the token
65
+ * @returns The formatted amount as string
66
+ */
67
+ formatNonNativeToken: (value: bigint, decimals: number) => string;
68
+ /**
69
+ * Formats a bigint value (in octas) to a human-readable APT string
70
+ *
71
+ * @param value - The value in octas
72
+ * @param options - Formatting options including precision
73
+ * @returns The formatted amount as string
74
+ */
75
+ format(value: bigint, { precision }?: IUITransactionFormatOptions): string;
76
+ /**
77
+ * Submits the transaction by creating it and calling onSubmit
78
+ *
79
+ * @returns The transaction hash from onSubmit
80
+ */
81
+ submit(): Promise<any>;
82
+ /**
83
+ * Gets the balance of the sender's account in octas
84
+ *
85
+ * @returns The balance as bigint in octas
86
+ */
87
+ getBalance(): Promise<bigint>;
88
+ /**
89
+ * Validates that an address is a valid Aptos address format
90
+ *
91
+ * Aptos addresses are 64-character hex strings prefixed with 0x (66 chars total)
92
+ *
93
+ * @param address - The address to validate
94
+ * @returns true if the address format is valid
95
+ */
96
+ validateAddressFormat(address: string): boolean;
97
+ /**
98
+ * Creates a transaction payload for sending APT or tokens
99
+ *
100
+ * @returns The transaction payload or undefined if invalid
101
+ */
102
+ private createTransaction;
103
+ /**
104
+ * Safely creates a transaction, returning undefined on error
105
+ *
106
+ * @returns The transaction payload or undefined if creation fails
107
+ */
108
+ private createTransactionSafe;
109
+ }
110
+ export {};
@@ -0,0 +1,185 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../_virtual/_tslib.js';
3
+ import { formatNumberText } from '@dynamic-labs/utils';
4
+ import { OCTAS_PER_APT } from '../constants/constants.js';
5
+
6
+ /**
7
+ * Aptos UI Transaction class for managing Aptos transactions in the UI.
8
+ *
9
+ * This class implements the IUITransaction interface and provides Aptos-specific
10
+ * functionality for creating, formatting, and submitting transactions.
11
+ */
12
+ class AptosUiTransaction {
13
+ constructor({ onSubmit, from, client }) {
14
+ this.chain = 'APTOS';
15
+ this.data = undefined;
16
+ this.fee = { gas: undefined };
17
+ /**
18
+ * Formats a non-native token value back to a string
19
+ *
20
+ * @param value - The value as bigint
21
+ * @param decimals - The number of decimals for the token
22
+ * @returns The formatted amount as string
23
+ */
24
+ this.formatNonNativeToken = (value, decimals) => (Number(value) / Number(Math.pow(10, decimals))).toString();
25
+ this.from = from;
26
+ this.onSubmit = onSubmit;
27
+ this.client = client;
28
+ }
29
+ /**
30
+ * Fetches the gas fee for the transaction.
31
+ *
32
+ * Note: Aptos gas fees are typically fixed or very low, so we set a default
33
+ * estimate. In the future, this could be enhanced with actual gas estimation.
34
+ *
35
+ * @returns The gas fee for the transaction
36
+ */
37
+ fetchFee() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ if (this.fee.gas)
40
+ return;
41
+ const transaction = yield this.createTransactionSafe();
42
+ if (!transaction) {
43
+ throw new Error('Could not create a valid Aptos transaction, check your address and value');
44
+ }
45
+ // Aptos has a simple gas model. For now, we'll use a default estimate.
46
+ // In the future, this could use the client to simulate the transaction.
47
+ // Typical Aptos transactions cost around 100-1000 octas (0.0000001 - 0.000001 APT)
48
+ // We'll use a conservative estimate of 1000 octas
49
+ this.fee.gas = BigInt(1000);
50
+ });
51
+ }
52
+ isGasSponsored() {
53
+ return false;
54
+ }
55
+ /**
56
+ * Parses a string amount into bigint octas (APT smallest unit, 1e8)
57
+ *
58
+ * @param input - The amount as a string (e.g., "1.5")
59
+ * @returns The amount in octas as bigint
60
+ */
61
+ parse(input) {
62
+ const floatValue = parseFloat(input);
63
+ const octas = Math.round(floatValue * OCTAS_PER_APT);
64
+ return BigInt(octas);
65
+ }
66
+ /**
67
+ * Parses a non-native token amount with custom decimals
68
+ *
69
+ * @param input - The amount as a string
70
+ * @param decimals - The number of decimals for the token
71
+ * @returns The amount as bigint
72
+ */
73
+ parseNonNativeToken(input, decimals) {
74
+ return BigInt(Math.floor(Number(input) * Math.pow(10, decimals)));
75
+ }
76
+ /**
77
+ * Formats a bigint value (in octas) to a human-readable APT string
78
+ *
79
+ * @param value - The value in octas
80
+ * @param options - Formatting options including precision
81
+ * @returns The formatted amount as string
82
+ */
83
+ format(value, { precision } = {}) {
84
+ const aptValue = Number(value) / OCTAS_PER_APT;
85
+ const decimalString = aptValue.toLocaleString('fullwide', {
86
+ maximumFractionDigits: 20,
87
+ minimumFractionDigits: 0,
88
+ useGrouping: false,
89
+ });
90
+ return formatNumberText(decimalString, { precision });
91
+ }
92
+ /**
93
+ * Submits the transaction by creating it and calling onSubmit
94
+ *
95
+ * @returns The transaction hash from onSubmit
96
+ */
97
+ submit() {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ const sendTransaction = (yield this.createTransaction());
100
+ return this.onSubmit(sendTransaction);
101
+ });
102
+ }
103
+ /**
104
+ * Gets the balance of the sender's account in octas
105
+ *
106
+ * @returns The balance as bigint in octas
107
+ */
108
+ getBalance() {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const balance = yield this.client.getBalance({
111
+ accountAddress: this.from,
112
+ // APT coin type
113
+ asset: '0x1::aptos_coin::AptosCoin',
114
+ });
115
+ // Balance comes back as a number in octas (1e8 octas = 1 APT)
116
+ return BigInt(Math.floor(balance));
117
+ });
118
+ }
119
+ /**
120
+ * Validates that an address is a valid Aptos address format
121
+ *
122
+ * Aptos addresses are 64-character hex strings prefixed with 0x (66 chars total)
123
+ *
124
+ * @param address - The address to validate
125
+ * @returns true if the address format is valid
126
+ */
127
+ validateAddressFormat(address) {
128
+ if (address === 'dyn_send_transaction.multiple_recipients') {
129
+ return true;
130
+ }
131
+ // Aptos addresses are 0x followed by 64 hex characters
132
+ return /^0x[0-9a-fA-F]{64}$/.test(address);
133
+ }
134
+ /**
135
+ * Creates a transaction payload for sending APT or tokens
136
+ *
137
+ * @returns The transaction payload or undefined if invalid
138
+ */
139
+ createTransaction() {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ const { value, to, nonNativeAddress, nonNativeValue } = this;
142
+ if (!to) {
143
+ throw new Error('Destination is required');
144
+ }
145
+ if (!value && !nonNativeValue) {
146
+ return undefined;
147
+ }
148
+ // Create the transaction payload
149
+ if (nonNativeAddress && nonNativeValue) {
150
+ // Transfer non-native token
151
+ return {
152
+ function: '0x1::coin::transfer',
153
+ functionArguments: [to, nonNativeValue],
154
+ typeArguments: [nonNativeAddress],
155
+ };
156
+ }
157
+ if (value) {
158
+ // Transfer native APT
159
+ return {
160
+ function: '0x1::coin::transfer',
161
+ functionArguments: [to, value],
162
+ typeArguments: ['0x1::aptos_coin::AptosCoin'],
163
+ };
164
+ }
165
+ return undefined;
166
+ });
167
+ }
168
+ /**
169
+ * Safely creates a transaction, returning undefined on error
170
+ *
171
+ * @returns The transaction payload or undefined if creation fails
172
+ */
173
+ createTransactionSafe() {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ try {
176
+ return yield this.createTransaction();
177
+ }
178
+ catch (error) {
179
+ return undefined;
180
+ }
181
+ });
182
+ }
183
+ }
184
+
185
+ export { AptosUiTransaction };
@@ -0,0 +1 @@
1
+ export { AptosUiTransaction } from './AptosUiTransaction';
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const OCTAS_PER_APT = 1e8;
7
+
8
+ exports.OCTAS_PER_APT = OCTAS_PER_APT;
@@ -0,0 +1 @@
1
+ export declare const OCTAS_PER_APT = 100000000;
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ const OCTAS_PER_APT = 1e8;
3
+
4
+ export { OCTAS_PER_APT };
@@ -0,0 +1 @@
1
+ export { OCTAS_PER_APT } from './constants';
@@ -57,15 +57,12 @@ class AptosWallet extends walletConnectorCore.Wallet {
57
57
  // Calculate amount with proper decimals (APT has 8 decimals by default)
58
58
  const decimals = (token === null || token === void 0 ? void 0 : token.decimals) || 8;
59
59
  const transferAmount = parseFloat(amount) * Math.pow(10, decimals);
60
- // Create the transfer transaction
61
- const transaction = yield aptosClient.transferCoinTransaction({
62
- amount: transferAmount,
63
- coinType: token === null || token === void 0 ? void 0 : token.address,
64
- recipient: toAddress,
65
- sender: accountInfo.address, // If undefined, defaults to APT (0x1::aptos_coin::AptosCoin)
66
- });
67
60
  // Sign and submit the transaction using the wallet provider
68
- const txHash = yield this.signAndSubmitTransaction(transaction);
61
+ const txHash = yield this.signAndSubmitTransaction({
62
+ function: '0x1::coin::transfer',
63
+ functionArguments: [toAddress, transferAmount],
64
+ typeArguments: ['0x1::aptos_coin::AptosCoin'],
65
+ });
69
66
  return txHash;
70
67
  }
71
68
  catch (error) {