@dynamic-labs/stellar 4.60.0 → 4.61.0
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.
- package/CHANGELOG.md +30 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -8
- package/src/connectors/LobstrWalletConnector/LobstrWalletConnector.cjs +1 -0
- package/src/connectors/LobstrWalletConnector/LobstrWalletConnector.js +1 -0
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.cjs +31 -0
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.d.ts +8 -1
- package/src/connectors/StellarWalletConnector/StellarWalletConnector.js +32 -1
- package/src/consts/index.cjs +15 -0
- package/src/consts/index.d.ts +4 -0
- package/src/consts/index.js +11 -0
- package/src/index.cjs +2 -0
- package/src/index.js +2 -0
- package/src/types.d.ts +1 -1
- package/src/utils/StellarUiTransaction/StellarUiTransaction.cjs +208 -0
- package/src/utils/StellarUiTransaction/StellarUiTransaction.d.ts +112 -0
- package/src/utils/StellarUiTransaction/StellarUiTransaction.js +204 -0
- package/src/utils/StellarUiTransaction/index.d.ts +1 -0
- package/src/utils/index.d.ts +1 -0
- package/src/wallet/StellarWallet.cjs +10 -4
- package/src/wallet/StellarWallet.js +10 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
|
|
2
|
+
## [4.61.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.60.1...v4.61.0) (2026-02-10)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add unlockWallet and getWalletRecoveryState to WaaS ([#10407](https://github.com/dynamic-labs/dynamic-auth/issues/10407)) ([e0d1a28](https://github.com/dynamic-labs/dynamic-auth/commit/e0d1a2830f36eee6c6e84737011e8cf59966122d))
|
|
8
|
+
* add useWalletPassword hook for waas wallet password management ([#10399](https://github.com/dynamic-labs/dynamic-auth/issues/10399)) ([508835f](https://github.com/dynamic-labs/dynamic-auth/commit/508835fb0f4f17b7353a4378f4c254e02f0a46ff))
|
|
9
|
+
* add WaaS unlock and recovery UI to mobile demo ([#10408](https://github.com/dynamic-labs/dynamic-auth/issues/10408)) ([94cdb88](https://github.com/dynamic-labs/dynamic-auth/commit/94cdb882fca3c34d157b42d5208f56812008c43b))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* bump axios to fix high vulnerability ([#10406](https://github.com/dynamic-labs/dynamic-auth/issues/10406)) ([303e2dc](https://github.com/dynamic-labs/dynamic-auth/commit/303e2dcf1e7e8ecad4caf2d74e805ee427c1d00e))
|
|
15
|
+
* patch node-forge CVE-2025-12816 in global-wallet ([#10401](https://github.com/dynamic-labs/dynamic-auth/issues/10401)) ([46e6eb2](https://github.com/dynamic-labs/dynamic-auth/commit/46e6eb28a0add0052299eaa4ac2dcbe8b1faa98c))
|
|
16
|
+
|
|
17
|
+
### [4.60.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.60.0...v4.60.1) (2026-02-09)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* add WAAS password handlers to DynamicContextProvider settings ([#10360](https://github.com/dynamic-labs/dynamic-auth/issues/10360)) ([5fc3fa7](https://github.com/dynamic-labs/dynamic-auth/commit/5fc3fa7148c53b64d36672be2d1ae629cb9cdaf8))
|
|
23
|
+
* improve password handling and UI for wallet protection ([#10386](https://github.com/dynamic-labs/dynamic-auth/issues/10386)) ([d27936e](https://github.com/dynamic-labs/dynamic-auth/commit/d27936e5bea37facceefccc0f2507d25a775ad33))
|
|
24
|
+
* pass authToken to wallet recovery operations ([#10379](https://github.com/dynamic-labs/dynamic-auth/issues/10379)) ([294efc7](https://github.com/dynamic-labs/dynamic-auth/commit/294efc7ab5816f63b7e5cc49a150cf9d34d300af))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
* override fast-xml-parser to 5.3.4 for CVE-2026-25128 ([#10381](https://github.com/dynamic-labs/dynamic-auth/issues/10381)) ([7fb4c22](https://github.com/dynamic-labs/dynamic-auth/commit/7fb4c221252b84bf38bbdab0b37b8f9a981ebe1a))
|
|
30
|
+
* unlock wallet view error handling and password error UI ([#10388](https://github.com/dynamic-labs/dynamic-auth/issues/10388)) ([5ffc8e1](https://github.com/dynamic-labs/dynamic-auth/commit/5ffc8e1e6dd0d7f32bb94c37ce3674be949f010b))
|
|
31
|
+
|
|
2
32
|
## [4.60.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.59.2...v4.60.0) (2026-02-05)
|
|
3
33
|
|
|
4
34
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/stellar",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.61.0",
|
|
4
4
|
"description": "A React SDK for implementing Stellar wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
21
|
+
"@dynamic-labs/sdk-api-core": "0.0.864",
|
|
22
22
|
"@stellar/stellar-sdk": "14.4.3",
|
|
23
|
-
"@dynamic-labs/wallet-connector-core": "4.
|
|
24
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
23
|
+
"@dynamic-labs/wallet-connector-core": "4.61.0",
|
|
24
|
+
"@dynamic-labs/assert-package-version": "4.61.0",
|
|
25
25
|
"@lobstrco/signer-extension-api": "2.0.0",
|
|
26
26
|
"@stellar/freighter-api": "6.0.1",
|
|
27
|
-
"@dynamic-labs/logger": "4.
|
|
28
|
-
"@dynamic-labs/types": "4.
|
|
29
|
-
"@dynamic-labs/utils": "4.
|
|
30
|
-
"@dynamic-labs/wallet-book": "4.
|
|
27
|
+
"@dynamic-labs/logger": "4.61.0",
|
|
28
|
+
"@dynamic-labs/types": "4.61.0",
|
|
29
|
+
"@dynamic-labs/utils": "4.61.0",
|
|
30
|
+
"@dynamic-labs/wallet-book": "4.61.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {}
|
|
33
33
|
}
|
|
@@ -9,6 +9,7 @@ var StellarWalletConnector = require('../StellarWalletConnector/StellarWalletCon
|
|
|
9
9
|
var StellarWallet = require('../../wallet/StellarWallet.cjs');
|
|
10
10
|
require('@stellar/stellar-sdk');
|
|
11
11
|
var getNetworkFromAddress = require('../../utils/getNetworkFromAddress.cjs');
|
|
12
|
+
require('@dynamic-labs/utils');
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Lobstr Wallet provider adapter that implements IStellarProvider
|
|
@@ -5,6 +5,7 @@ import { StellarWalletConnector } from '../StellarWalletConnector/StellarWalletC
|
|
|
5
5
|
import { StellarWallet } from '../../wallet/StellarWallet.js';
|
|
6
6
|
import '@stellar/stellar-sdk';
|
|
7
7
|
import { getNetworkFromAddress } from '../../utils/getNetworkFromAddress.js';
|
|
8
|
+
import '@dynamic-labs/utils';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Lobstr Wallet provider adapter that implements IStellarProvider
|
|
@@ -10,6 +10,7 @@ var utils = require('@dynamic-labs/utils');
|
|
|
10
10
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
11
11
|
var StellarWallet = require('../../wallet/StellarWallet.cjs');
|
|
12
12
|
var getNetworkFromAddress = require('../../utils/getNetworkFromAddress.cjs');
|
|
13
|
+
var StellarUiTransaction = require('../../utils/StellarUiTransaction/StellarUiTransaction.cjs');
|
|
13
14
|
var StellarLocalStorageCache = require('../../StellarLocalStorageCache.cjs');
|
|
14
15
|
|
|
15
16
|
const HORIZON_MAINNET_URL = 'https://horizon.stellar.org';
|
|
@@ -422,6 +423,36 @@ class StellarWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
422
423
|
yield this.cache.clearConnectedAcccounts();
|
|
423
424
|
});
|
|
424
425
|
}
|
|
426
|
+
/**
|
|
427
|
+
* Function used to create transactions in the SDK interface
|
|
428
|
+
*
|
|
429
|
+
* @param from - The sender's address (Stellar public key)
|
|
430
|
+
* @returns A new StellarUiTransaction instance
|
|
431
|
+
*/
|
|
432
|
+
createUiTransaction(from) {
|
|
433
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
434
|
+
yield this.validateActiveWallet(from);
|
|
435
|
+
const horizonServer = yield this.getHorizonServer();
|
|
436
|
+
const networkPassphrase = yield this.getNetworkPassphrase();
|
|
437
|
+
if (!horizonServer) {
|
|
438
|
+
throw new utils.DynamicError('No Horizon server available');
|
|
439
|
+
}
|
|
440
|
+
return new StellarUiTransaction.StellarUiTransaction({
|
|
441
|
+
from,
|
|
442
|
+
horizonServer,
|
|
443
|
+
networkPassphrase,
|
|
444
|
+
onSubmit: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
445
|
+
if (!transaction) {
|
|
446
|
+
throw new utils.DynamicError('Transaction must be provided');
|
|
447
|
+
}
|
|
448
|
+
const signedXdr = yield this.signTransaction(transaction.toXDR());
|
|
449
|
+
const signedTransaction = stellarSdk.TransactionBuilder.fromXDR(signedXdr, networkPassphrase);
|
|
450
|
+
const result = yield horizonServer.submitTransaction(signedTransaction);
|
|
451
|
+
return result.hash;
|
|
452
|
+
}),
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
}
|
|
425
456
|
}
|
|
426
457
|
|
|
427
458
|
exports.StellarWalletConnector = StellarWalletConnector;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Horizon } from '@stellar/stellar-sdk';
|
|
2
2
|
import { Logger } from '@dynamic-labs/logger';
|
|
3
|
-
import type { GenericNetwork } from '@dynamic-labs/types';
|
|
3
|
+
import type { GenericNetwork, IUITransaction } from '@dynamic-labs/types';
|
|
4
4
|
import { type Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
5
5
|
import { WalletAdditionalAddress } from '@dynamic-labs/sdk-api-core';
|
|
6
6
|
import type { IStellarProvider, StellarWalletConnectorProps } from '../../types';
|
|
@@ -109,4 +109,11 @@ export declare abstract class StellarWalletConnector extends WalletConnectorBase
|
|
|
109
109
|
* Ends the session and clears connected accounts.
|
|
110
110
|
*/
|
|
111
111
|
endSession(): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Function used to create transactions in the SDK interface
|
|
114
|
+
*
|
|
115
|
+
* @param from - The sender's address (Stellar public key)
|
|
116
|
+
* @returns A new StellarUiTransaction instance
|
|
117
|
+
*/
|
|
118
|
+
createUiTransaction(from: string): Promise<IUITransaction>;
|
|
112
119
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
-
import { Horizon, Networks } from '@stellar/stellar-sdk';
|
|
3
|
+
import { Horizon, Networks, TransactionBuilder } from '@stellar/stellar-sdk';
|
|
4
4
|
import { Logger } from '@dynamic-labs/logger';
|
|
5
5
|
import { DynamicError } from '@dynamic-labs/utils';
|
|
6
6
|
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
7
7
|
import { StellarWallet } from '../../wallet/StellarWallet.js';
|
|
8
8
|
import { getNetworkFromAddress } from '../../utils/getNetworkFromAddress.js';
|
|
9
|
+
import { StellarUiTransaction } from '../../utils/StellarUiTransaction/StellarUiTransaction.js';
|
|
9
10
|
import { StellarLocalStorageCache } from '../../StellarLocalStorageCache.js';
|
|
10
11
|
|
|
11
12
|
const HORIZON_MAINNET_URL = 'https://horizon.stellar.org';
|
|
@@ -418,6 +419,36 @@ class StellarWalletConnector extends WalletConnectorBase {
|
|
|
418
419
|
yield this.cache.clearConnectedAcccounts();
|
|
419
420
|
});
|
|
420
421
|
}
|
|
422
|
+
/**
|
|
423
|
+
* Function used to create transactions in the SDK interface
|
|
424
|
+
*
|
|
425
|
+
* @param from - The sender's address (Stellar public key)
|
|
426
|
+
* @returns A new StellarUiTransaction instance
|
|
427
|
+
*/
|
|
428
|
+
createUiTransaction(from) {
|
|
429
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
430
|
+
yield this.validateActiveWallet(from);
|
|
431
|
+
const horizonServer = yield this.getHorizonServer();
|
|
432
|
+
const networkPassphrase = yield this.getNetworkPassphrase();
|
|
433
|
+
if (!horizonServer) {
|
|
434
|
+
throw new DynamicError('No Horizon server available');
|
|
435
|
+
}
|
|
436
|
+
return new StellarUiTransaction({
|
|
437
|
+
from,
|
|
438
|
+
horizonServer,
|
|
439
|
+
networkPassphrase,
|
|
440
|
+
onSubmit: (transaction) => __awaiter(this, void 0, void 0, function* () {
|
|
441
|
+
if (!transaction) {
|
|
442
|
+
throw new DynamicError('Transaction must be provided');
|
|
443
|
+
}
|
|
444
|
+
const signedXdr = yield this.signTransaction(transaction.toXDR());
|
|
445
|
+
const signedTransaction = TransactionBuilder.fromXDR(signedXdr, networkPassphrase);
|
|
446
|
+
const result = yield horizonServer.submitTransaction(signedTransaction);
|
|
447
|
+
return result.hash;
|
|
448
|
+
}),
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
}
|
|
421
452
|
}
|
|
422
453
|
|
|
423
454
|
export { StellarWalletConnector };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Required features for Stellar wallets to function properly.
|
|
8
|
+
* These are the minimum capabilities a wallet must support.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Number of stroops per XLM (1 XLM = 10,000,000 stroops)
|
|
12
|
+
*/
|
|
13
|
+
const STROOPS_PER_XLM = 1e7;
|
|
14
|
+
|
|
15
|
+
exports.STROOPS_PER_XLM = STROOPS_PER_XLM;
|
package/src/consts/index.d.ts
CHANGED
|
@@ -15,3 +15,7 @@ export declare const STELLAR_TESTNET_NETWORK_PASSPHRASE = "Test SDF Network ; Se
|
|
|
15
15
|
* Stellar network passphrase for futurenet
|
|
16
16
|
*/
|
|
17
17
|
export declare const STELLAR_FUTURENET_NETWORK_PASSPHRASE = "Test SDF Future Network ; October 2022";
|
|
18
|
+
/**
|
|
19
|
+
* Number of stroops per XLM (1 XLM = 10,000,000 stroops)
|
|
20
|
+
*/
|
|
21
|
+
export declare const STROOPS_PER_XLM = 10000000;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/**
|
|
3
|
+
* Required features for Stellar wallets to function properly.
|
|
4
|
+
* These are the minimum capabilities a wallet must support.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Number of stroops per XLM (1 XLM = 10,000,000 stroops)
|
|
8
|
+
*/
|
|
9
|
+
const STROOPS_PER_XLM = 1e7;
|
|
10
|
+
|
|
11
|
+
export { STROOPS_PER_XLM };
|
package/src/index.cjs
CHANGED
|
@@ -12,6 +12,8 @@ var StellarWalletConnector = require('./connectors/StellarWalletConnector/Stella
|
|
|
12
12
|
var StellarLocalStorageCache = require('./StellarLocalStorageCache.cjs');
|
|
13
13
|
require('@stellar/stellar-sdk');
|
|
14
14
|
var getNetworkFromAddress = require('./utils/getNetworkFromAddress.cjs');
|
|
15
|
+
require('../_virtual/_tslib.cjs');
|
|
16
|
+
require('@dynamic-labs/utils');
|
|
15
17
|
|
|
16
18
|
assertPackageVersion.assertPackageVersion('@dynamic-labs/stellar', _package.version);
|
|
17
19
|
// Wallet connector factory (to be implemented by specific wallet connectors)
|
package/src/index.js
CHANGED
|
@@ -8,6 +8,8 @@ export { StellarWalletConnector } from './connectors/StellarWalletConnector/Stel
|
|
|
8
8
|
export { StellarLocalStorageCache } from './StellarLocalStorageCache.js';
|
|
9
9
|
import '@stellar/stellar-sdk';
|
|
10
10
|
export { getNetworkFromAddress } from './utils/getNetworkFromAddress.js';
|
|
11
|
+
import '../_virtual/_tslib.js';
|
|
12
|
+
import '@dynamic-labs/utils';
|
|
11
13
|
|
|
12
14
|
assertPackageVersion('@dynamic-labs/stellar', version);
|
|
13
15
|
// Wallet connector factory (to be implemented by specific wallet connectors)
|
package/src/types.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ export type StellarSendBalanceProps = {
|
|
|
77
77
|
toAddress: string;
|
|
78
78
|
/** Optional token information for non-XLM transfers */
|
|
79
79
|
token?: {
|
|
80
|
-
/** Token address in format "CODE:ISSUER" (e.g., "USDC:GXXXXXXX...") */
|
|
80
|
+
/** Token address in format "CODE:ISSUER" or "CODE-ISSUER" (e.g., "USDC:GXXXXXXX..." or "USDC-GXXXXXXX...") */
|
|
81
81
|
address: string;
|
|
82
82
|
/** Token decimals (optional, Stellar uses 7 decimals by default) */
|
|
83
83
|
decimals?: number;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var stellarSdk = require('@stellar/stellar-sdk');
|
|
8
|
+
var utils = require('@dynamic-labs/utils');
|
|
9
|
+
var index = require('../../consts/index.cjs');
|
|
10
|
+
var buildPaymentTransaction = require('../buildPaymentTransaction.cjs');
|
|
11
|
+
var createPaymentAsset = require('../createPaymentAsset.cjs');
|
|
12
|
+
var getAccountBalance = require('../getAccountBalance.cjs');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Stellar UI Transaction class for managing Stellar transactions in the UI.
|
|
16
|
+
*
|
|
17
|
+
* This class implements the IUITransaction interface and provides Stellar-specific
|
|
18
|
+
* functionality for creating, formatting, and submitting transactions.
|
|
19
|
+
*/
|
|
20
|
+
class StellarUiTransaction {
|
|
21
|
+
constructor({ onSubmit, from, horizonServer, networkPassphrase, }) {
|
|
22
|
+
this.chain = 'STELLAR';
|
|
23
|
+
this.data = undefined;
|
|
24
|
+
this.fee = { gas: undefined };
|
|
25
|
+
/**
|
|
26
|
+
* Formats a non-native token value back to a string
|
|
27
|
+
*
|
|
28
|
+
* @param value - The value as bigint
|
|
29
|
+
* @param decimals - The number of decimals for the token
|
|
30
|
+
* @returns The formatted amount as string
|
|
31
|
+
*/
|
|
32
|
+
this.formatNonNativeToken = (value, decimals) => (Number(value) / Number(Math.pow(10, decimals))).toString();
|
|
33
|
+
this.from = from;
|
|
34
|
+
this.onSubmit = onSubmit;
|
|
35
|
+
this.horizonServer = horizonServer;
|
|
36
|
+
this.networkPassphrase = networkPassphrase;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Fetches the gas fee for the transaction.
|
|
40
|
+
*
|
|
41
|
+
* Stellar uses a fixed base fee per operation. The minimum fee is 100 stroops
|
|
42
|
+
* (0.00001 XLM) per operation. We'll use this as our default estimate.
|
|
43
|
+
*
|
|
44
|
+
* @returns The gas fee for the transaction
|
|
45
|
+
*/
|
|
46
|
+
fetchFee() {
|
|
47
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
if (this.fee.gas)
|
|
49
|
+
return;
|
|
50
|
+
const transaction = yield this.createTransactionSafe();
|
|
51
|
+
if (!transaction) {
|
|
52
|
+
throw new Error('Could not create a valid Stellar transaction, check your address and value');
|
|
53
|
+
}
|
|
54
|
+
// Stellar has a fixed base fee per operation (100 stroops = 0.00001 XLM)
|
|
55
|
+
// Payment transactions have 1 operation, so the base fee is 100 stroops
|
|
56
|
+
this.fee.gas = BigInt(100);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
isGasSponsored() {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Parses a string amount into bigint stroops (XLM smallest unit, 1e7)
|
|
64
|
+
*
|
|
65
|
+
* @param input - The amount as a string (e.g., "1.5")
|
|
66
|
+
* @returns The amount in stroops as bigint
|
|
67
|
+
*/
|
|
68
|
+
parse(input) {
|
|
69
|
+
const floatValue = parseFloat(input);
|
|
70
|
+
const stroops = Math.round(floatValue * index.STROOPS_PER_XLM);
|
|
71
|
+
return BigInt(stroops);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Parses a non-native token amount with custom decimals
|
|
75
|
+
*
|
|
76
|
+
* @param input - The amount as a string
|
|
77
|
+
* @param decimals - The number of decimals for the token
|
|
78
|
+
* @returns The amount as bigint
|
|
79
|
+
*/
|
|
80
|
+
parseNonNativeToken(input, decimals) {
|
|
81
|
+
return BigInt(Math.floor(Number(input) * Math.pow(10, decimals)));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Formats a bigint value (in stroops) to a human-readable XLM string
|
|
85
|
+
*
|
|
86
|
+
* @param value - The value in stroops
|
|
87
|
+
* @param options - Formatting options including precision
|
|
88
|
+
* @returns The formatted amount as string
|
|
89
|
+
*/
|
|
90
|
+
format(value, { precision } = {}) {
|
|
91
|
+
const xlmValue = Number(value) / index.STROOPS_PER_XLM;
|
|
92
|
+
const decimalString = xlmValue.toLocaleString('fullwide', {
|
|
93
|
+
maximumFractionDigits: 20,
|
|
94
|
+
minimumFractionDigits: 0,
|
|
95
|
+
useGrouping: false,
|
|
96
|
+
});
|
|
97
|
+
return utils.formatNumberText(decimalString, { precision });
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Submits the transaction by creating it and calling onSubmit
|
|
101
|
+
*
|
|
102
|
+
* @returns The transaction hash from onSubmit
|
|
103
|
+
*/
|
|
104
|
+
submit() {
|
|
105
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
const transaction = (yield this.createTransaction());
|
|
107
|
+
return this.onSubmit(transaction);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Gets the balance of the sender's account in stroops
|
|
112
|
+
*
|
|
113
|
+
* @returns The balance as bigint in stroops
|
|
114
|
+
*/
|
|
115
|
+
getBalance() {
|
|
116
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
try {
|
|
118
|
+
const account = yield this.horizonServer.loadAccount(this.from);
|
|
119
|
+
const balanceString = getAccountBalance.getAccountBalance(account);
|
|
120
|
+
// Balance comes back as a string with decimals (e.g., "100.5000000")
|
|
121
|
+
// We need to convert it to stroops
|
|
122
|
+
const xlmAmount = parseFloat(balanceString);
|
|
123
|
+
const stroops = Math.floor(xlmAmount * index.STROOPS_PER_XLM);
|
|
124
|
+
return BigInt(stroops);
|
|
125
|
+
}
|
|
126
|
+
catch (_a) {
|
|
127
|
+
return BigInt(0);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Validates that an address is a valid Stellar address format
|
|
133
|
+
*
|
|
134
|
+
* Stellar addresses are 56-character base32-encoded strings starting with 'G'
|
|
135
|
+
*
|
|
136
|
+
* @param address - The address to validate
|
|
137
|
+
* @returns true if the address format is valid
|
|
138
|
+
*/
|
|
139
|
+
validateAddressFormat(address) {
|
|
140
|
+
if (address === 'dyn_send_transaction.multiple_recipients') {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
// Use Stellar SDK's built-in validation
|
|
144
|
+
return stellarSdk.StrKey.isValidEd25519PublicKey(address);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Creates a transaction for sending XLM or tokens
|
|
148
|
+
*
|
|
149
|
+
* @returns The transaction or undefined if invalid
|
|
150
|
+
*/
|
|
151
|
+
createTransaction() {
|
|
152
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
var _a;
|
|
154
|
+
const { value, to, nonNativeAddress, nonNativeValue } = this;
|
|
155
|
+
if (!to) {
|
|
156
|
+
throw new Error('Destination is required');
|
|
157
|
+
}
|
|
158
|
+
if (!value && !nonNativeValue) {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
// Load the source account
|
|
162
|
+
const sourceAccount = yield this.horizonServer.loadAccount(this.from);
|
|
163
|
+
// Determine the asset to send
|
|
164
|
+
let asset;
|
|
165
|
+
let amount;
|
|
166
|
+
if (nonNativeAddress && nonNativeValue !== undefined) {
|
|
167
|
+
// Transfer non-native token
|
|
168
|
+
// nonNativeAddress format: "CODE:ISSUER" or "CODE-ISSUER" (e.g., "USDC:GXXXXXXX..." or "USDC-GXXXXXXX...")
|
|
169
|
+
const [code, issuer] = nonNativeAddress.split(/[:-]/);
|
|
170
|
+
asset = createPaymentAsset.createPaymentAsset({ code, issuer });
|
|
171
|
+
amount = this.formatNonNativeToken(nonNativeValue, (_a = this.nonNativeDecimal) !== null && _a !== void 0 ? _a : 7);
|
|
172
|
+
}
|
|
173
|
+
else if (value) {
|
|
174
|
+
// Transfer native XLM
|
|
175
|
+
asset = stellarSdk.Asset.native();
|
|
176
|
+
amount = (Number(value) / index.STROOPS_PER_XLM).toString();
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
// Build the transaction
|
|
182
|
+
return buildPaymentTransaction.buildPaymentTransaction({
|
|
183
|
+
amount,
|
|
184
|
+
asset,
|
|
185
|
+
networkPassphrase: this.networkPassphrase,
|
|
186
|
+
sourceAccount,
|
|
187
|
+
toAddress: to,
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Safely creates a transaction, returning undefined on error
|
|
193
|
+
*
|
|
194
|
+
* @returns The transaction or undefined if creation fails
|
|
195
|
+
*/
|
|
196
|
+
createTransactionSafe() {
|
|
197
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
try {
|
|
199
|
+
return yield this.createTransaction();
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
exports.StellarUiTransaction = StellarUiTransaction;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { Horizon, Transaction } from '@stellar/stellar-sdk';
|
|
2
|
+
import { IUITransaction, IUITransactionFormatOptions } from '@dynamic-labs/types';
|
|
3
|
+
type StellarUiTransactionProps = {
|
|
4
|
+
/** Stellar public key of the sender */
|
|
5
|
+
from: string;
|
|
6
|
+
/** The Horizon server instance, needed to fetch account info and estimate fees */
|
|
7
|
+
horizonServer: Horizon.Server;
|
|
8
|
+
/** Network passphrase (PUBLIC, TESTNET, or FUTURENET) */
|
|
9
|
+
networkPassphrase: string;
|
|
10
|
+
/** The function to call when the transaction is submitted */
|
|
11
|
+
onSubmit: (transaction?: Transaction) => Promise<any>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Stellar UI Transaction class for managing Stellar transactions in the UI.
|
|
15
|
+
*
|
|
16
|
+
* This class implements the IUITransaction interface and provides Stellar-specific
|
|
17
|
+
* functionality for creating, formatting, and submitting transactions.
|
|
18
|
+
*/
|
|
19
|
+
export declare class StellarUiTransaction implements IUITransaction {
|
|
20
|
+
to: string | undefined;
|
|
21
|
+
from: string;
|
|
22
|
+
value: bigint | undefined;
|
|
23
|
+
chain: string;
|
|
24
|
+
receipt: string | undefined;
|
|
25
|
+
data: undefined;
|
|
26
|
+
fee: {
|
|
27
|
+
gas: bigint | undefined;
|
|
28
|
+
};
|
|
29
|
+
nonNativeAddress?: string;
|
|
30
|
+
nonNativeDecimal?: number;
|
|
31
|
+
nonNativeValue?: bigint;
|
|
32
|
+
nativePrice?: number;
|
|
33
|
+
private onSubmit;
|
|
34
|
+
private horizonServer;
|
|
35
|
+
private networkPassphrase;
|
|
36
|
+
constructor({ onSubmit, from, horizonServer, networkPassphrase, }: StellarUiTransactionProps);
|
|
37
|
+
/**
|
|
38
|
+
* Fetches the gas fee for the transaction.
|
|
39
|
+
*
|
|
40
|
+
* Stellar uses a fixed base fee per operation. The minimum fee is 100 stroops
|
|
41
|
+
* (0.00001 XLM) per operation. We'll use this as our default estimate.
|
|
42
|
+
*
|
|
43
|
+
* @returns The gas fee for the transaction
|
|
44
|
+
*/
|
|
45
|
+
fetchFee(): Promise<void>;
|
|
46
|
+
isGasSponsored(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Parses a string amount into bigint stroops (XLM smallest unit, 1e7)
|
|
49
|
+
*
|
|
50
|
+
* @param input - The amount as a string (e.g., "1.5")
|
|
51
|
+
* @returns The amount in stroops as bigint
|
|
52
|
+
*/
|
|
53
|
+
parse(input: string): bigint;
|
|
54
|
+
/**
|
|
55
|
+
* Parses a non-native token amount with custom decimals
|
|
56
|
+
*
|
|
57
|
+
* @param input - The amount as a string
|
|
58
|
+
* @param decimals - The number of decimals for the token
|
|
59
|
+
* @returns The amount as bigint
|
|
60
|
+
*/
|
|
61
|
+
parseNonNativeToken(input: string, decimals: number): bigint;
|
|
62
|
+
/**
|
|
63
|
+
* Formats a non-native token value back to a string
|
|
64
|
+
*
|
|
65
|
+
* @param value - The value as bigint
|
|
66
|
+
* @param decimals - The number of decimals for the token
|
|
67
|
+
* @returns The formatted amount as string
|
|
68
|
+
*/
|
|
69
|
+
formatNonNativeToken: (value: bigint, decimals: number) => string;
|
|
70
|
+
/**
|
|
71
|
+
* Formats a bigint value (in stroops) to a human-readable XLM string
|
|
72
|
+
*
|
|
73
|
+
* @param value - The value in stroops
|
|
74
|
+
* @param options - Formatting options including precision
|
|
75
|
+
* @returns The formatted amount as string
|
|
76
|
+
*/
|
|
77
|
+
format(value: bigint, { precision }?: IUITransactionFormatOptions): string;
|
|
78
|
+
/**
|
|
79
|
+
* Submits the transaction by creating it and calling onSubmit
|
|
80
|
+
*
|
|
81
|
+
* @returns The transaction hash from onSubmit
|
|
82
|
+
*/
|
|
83
|
+
submit(): Promise<any>;
|
|
84
|
+
/**
|
|
85
|
+
* Gets the balance of the sender's account in stroops
|
|
86
|
+
*
|
|
87
|
+
* @returns The balance as bigint in stroops
|
|
88
|
+
*/
|
|
89
|
+
getBalance(): Promise<bigint>;
|
|
90
|
+
/**
|
|
91
|
+
* Validates that an address is a valid Stellar address format
|
|
92
|
+
*
|
|
93
|
+
* Stellar addresses are 56-character base32-encoded strings starting with 'G'
|
|
94
|
+
*
|
|
95
|
+
* @param address - The address to validate
|
|
96
|
+
* @returns true if the address format is valid
|
|
97
|
+
*/
|
|
98
|
+
validateAddressFormat(address: string): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a transaction for sending XLM or tokens
|
|
101
|
+
*
|
|
102
|
+
* @returns The transaction or undefined if invalid
|
|
103
|
+
*/
|
|
104
|
+
private createTransaction;
|
|
105
|
+
/**
|
|
106
|
+
* Safely creates a transaction, returning undefined on error
|
|
107
|
+
*
|
|
108
|
+
* @returns The transaction or undefined if creation fails
|
|
109
|
+
*/
|
|
110
|
+
private createTransactionSafe;
|
|
111
|
+
}
|
|
112
|
+
export {};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { StrKey, Asset } from '@stellar/stellar-sdk';
|
|
4
|
+
import { formatNumberText } from '@dynamic-labs/utils';
|
|
5
|
+
import { STROOPS_PER_XLM } from '../../consts/index.js';
|
|
6
|
+
import { buildPaymentTransaction } from '../buildPaymentTransaction.js';
|
|
7
|
+
import { createPaymentAsset } from '../createPaymentAsset.js';
|
|
8
|
+
import { getAccountBalance } from '../getAccountBalance.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Stellar UI Transaction class for managing Stellar transactions in the UI.
|
|
12
|
+
*
|
|
13
|
+
* This class implements the IUITransaction interface and provides Stellar-specific
|
|
14
|
+
* functionality for creating, formatting, and submitting transactions.
|
|
15
|
+
*/
|
|
16
|
+
class StellarUiTransaction {
|
|
17
|
+
constructor({ onSubmit, from, horizonServer, networkPassphrase, }) {
|
|
18
|
+
this.chain = 'STELLAR';
|
|
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.horizonServer = horizonServer;
|
|
32
|
+
this.networkPassphrase = networkPassphrase;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Fetches the gas fee for the transaction.
|
|
36
|
+
*
|
|
37
|
+
* Stellar uses a fixed base fee per operation. The minimum fee is 100 stroops
|
|
38
|
+
* (0.00001 XLM) per operation. We'll use this as our default estimate.
|
|
39
|
+
*
|
|
40
|
+
* @returns The gas fee for the transaction
|
|
41
|
+
*/
|
|
42
|
+
fetchFee() {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
if (this.fee.gas)
|
|
45
|
+
return;
|
|
46
|
+
const transaction = yield this.createTransactionSafe();
|
|
47
|
+
if (!transaction) {
|
|
48
|
+
throw new Error('Could not create a valid Stellar transaction, check your address and value');
|
|
49
|
+
}
|
|
50
|
+
// Stellar has a fixed base fee per operation (100 stroops = 0.00001 XLM)
|
|
51
|
+
// Payment transactions have 1 operation, so the base fee is 100 stroops
|
|
52
|
+
this.fee.gas = BigInt(100);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
isGasSponsored() {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Parses a string amount into bigint stroops (XLM smallest unit, 1e7)
|
|
60
|
+
*
|
|
61
|
+
* @param input - The amount as a string (e.g., "1.5")
|
|
62
|
+
* @returns The amount in stroops as bigint
|
|
63
|
+
*/
|
|
64
|
+
parse(input) {
|
|
65
|
+
const floatValue = parseFloat(input);
|
|
66
|
+
const stroops = Math.round(floatValue * STROOPS_PER_XLM);
|
|
67
|
+
return BigInt(stroops);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Parses a non-native token amount with custom decimals
|
|
71
|
+
*
|
|
72
|
+
* @param input - The amount as a string
|
|
73
|
+
* @param decimals - The number of decimals for the token
|
|
74
|
+
* @returns The amount as bigint
|
|
75
|
+
*/
|
|
76
|
+
parseNonNativeToken(input, decimals) {
|
|
77
|
+
return BigInt(Math.floor(Number(input) * Math.pow(10, decimals)));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Formats a bigint value (in stroops) to a human-readable XLM string
|
|
81
|
+
*
|
|
82
|
+
* @param value - The value in stroops
|
|
83
|
+
* @param options - Formatting options including precision
|
|
84
|
+
* @returns The formatted amount as string
|
|
85
|
+
*/
|
|
86
|
+
format(value, { precision } = {}) {
|
|
87
|
+
const xlmValue = Number(value) / STROOPS_PER_XLM;
|
|
88
|
+
const decimalString = xlmValue.toLocaleString('fullwide', {
|
|
89
|
+
maximumFractionDigits: 20,
|
|
90
|
+
minimumFractionDigits: 0,
|
|
91
|
+
useGrouping: false,
|
|
92
|
+
});
|
|
93
|
+
return formatNumberText(decimalString, { precision });
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Submits the transaction by creating it and calling onSubmit
|
|
97
|
+
*
|
|
98
|
+
* @returns The transaction hash from onSubmit
|
|
99
|
+
*/
|
|
100
|
+
submit() {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const transaction = (yield this.createTransaction());
|
|
103
|
+
return this.onSubmit(transaction);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Gets the balance of the sender's account in stroops
|
|
108
|
+
*
|
|
109
|
+
* @returns The balance as bigint in stroops
|
|
110
|
+
*/
|
|
111
|
+
getBalance() {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
try {
|
|
114
|
+
const account = yield this.horizonServer.loadAccount(this.from);
|
|
115
|
+
const balanceString = getAccountBalance(account);
|
|
116
|
+
// Balance comes back as a string with decimals (e.g., "100.5000000")
|
|
117
|
+
// We need to convert it to stroops
|
|
118
|
+
const xlmAmount = parseFloat(balanceString);
|
|
119
|
+
const stroops = Math.floor(xlmAmount * STROOPS_PER_XLM);
|
|
120
|
+
return BigInt(stroops);
|
|
121
|
+
}
|
|
122
|
+
catch (_a) {
|
|
123
|
+
return BigInt(0);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Validates that an address is a valid Stellar address format
|
|
129
|
+
*
|
|
130
|
+
* Stellar addresses are 56-character base32-encoded strings starting with 'G'
|
|
131
|
+
*
|
|
132
|
+
* @param address - The address to validate
|
|
133
|
+
* @returns true if the address format is valid
|
|
134
|
+
*/
|
|
135
|
+
validateAddressFormat(address) {
|
|
136
|
+
if (address === 'dyn_send_transaction.multiple_recipients') {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
// Use Stellar SDK's built-in validation
|
|
140
|
+
return StrKey.isValidEd25519PublicKey(address);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Creates a transaction for sending XLM or tokens
|
|
144
|
+
*
|
|
145
|
+
* @returns The transaction or undefined if invalid
|
|
146
|
+
*/
|
|
147
|
+
createTransaction() {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
var _a;
|
|
150
|
+
const { value, to, nonNativeAddress, nonNativeValue } = this;
|
|
151
|
+
if (!to) {
|
|
152
|
+
throw new Error('Destination is required');
|
|
153
|
+
}
|
|
154
|
+
if (!value && !nonNativeValue) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
// Load the source account
|
|
158
|
+
const sourceAccount = yield this.horizonServer.loadAccount(this.from);
|
|
159
|
+
// Determine the asset to send
|
|
160
|
+
let asset;
|
|
161
|
+
let amount;
|
|
162
|
+
if (nonNativeAddress && nonNativeValue !== undefined) {
|
|
163
|
+
// Transfer non-native token
|
|
164
|
+
// nonNativeAddress format: "CODE:ISSUER" or "CODE-ISSUER" (e.g., "USDC:GXXXXXXX..." or "USDC-GXXXXXXX...")
|
|
165
|
+
const [code, issuer] = nonNativeAddress.split(/[:-]/);
|
|
166
|
+
asset = createPaymentAsset({ code, issuer });
|
|
167
|
+
amount = this.formatNonNativeToken(nonNativeValue, (_a = this.nonNativeDecimal) !== null && _a !== void 0 ? _a : 7);
|
|
168
|
+
}
|
|
169
|
+
else if (value) {
|
|
170
|
+
// Transfer native XLM
|
|
171
|
+
asset = Asset.native();
|
|
172
|
+
amount = (Number(value) / STROOPS_PER_XLM).toString();
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
// Build the transaction
|
|
178
|
+
return buildPaymentTransaction({
|
|
179
|
+
amount,
|
|
180
|
+
asset,
|
|
181
|
+
networkPassphrase: this.networkPassphrase,
|
|
182
|
+
sourceAccount,
|
|
183
|
+
toAddress: to,
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Safely creates a transaction, returning undefined on error
|
|
189
|
+
*
|
|
190
|
+
* @returns The transaction or undefined if creation fails
|
|
191
|
+
*/
|
|
192
|
+
createTransactionSafe() {
|
|
193
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
try {
|
|
195
|
+
return yield this.createTransaction();
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export { StellarUiTransaction };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { StellarUiTransaction } from './StellarUiTransaction';
|
package/src/utils/index.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export { getAccountBalance } from './getAccountBalance';
|
|
|
6
6
|
export { getNetworkFromAddress } from './getNetworkFromAddress';
|
|
7
7
|
export { getNetworkPassphrase } from './getNetworkPassphrase';
|
|
8
8
|
export { normalizeNetworkName } from './normalizeNetworkName';
|
|
9
|
+
export { StellarUiTransaction } from './StellarUiTransaction';
|
|
@@ -10,6 +10,7 @@ var buildPaymentTransaction = require('../utils/buildPaymentTransaction.cjs');
|
|
|
10
10
|
var checkTrustline = require('../utils/checkTrustline.cjs');
|
|
11
11
|
var createPaymentAsset = require('../utils/createPaymentAsset.cjs');
|
|
12
12
|
var getAccountBalance = require('../utils/getAccountBalance.cjs');
|
|
13
|
+
require('@dynamic-labs/utils');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Stellar wallet implementation that provides chain-specific functionality
|
|
@@ -29,8 +30,13 @@ class StellarWallet extends walletConnectorCore.Wallet {
|
|
|
29
30
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
30
31
|
yield this._connector.connect();
|
|
31
32
|
const horizonServer = yield this.getHorizonServer();
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
try {
|
|
34
|
+
const account = yield horizonServer.loadAccount(this.address);
|
|
35
|
+
return getAccountBalance.getAccountBalance(account, assetCode, assetIssuer);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return '0';
|
|
39
|
+
}
|
|
34
40
|
});
|
|
35
41
|
}
|
|
36
42
|
/**
|
|
@@ -54,9 +60,9 @@ class StellarWallet extends walletConnectorCore.Wallet {
|
|
|
54
60
|
const networkPassphrase = yield this._connector.getNetworkPassphrase();
|
|
55
61
|
let asset;
|
|
56
62
|
if (token === null || token === void 0 ? void 0 : token.address) {
|
|
57
|
-
const [code, issuer] = token.address.split(
|
|
63
|
+
const [code, issuer] = token.address.split(/[:-]/);
|
|
58
64
|
if (!code || !issuer) {
|
|
59
|
-
throw new Error('Invalid token address format. Expected "CODE:ISSUER" (e.g., "USDC:GXXXXXXX...")');
|
|
65
|
+
throw new Error('Invalid token address format. Expected "CODE:ISSUER" or "CODE-ISSUER" (e.g., "USDC:GXXXXXXX..." or "USDC-GXXXXXXX...")');
|
|
60
66
|
}
|
|
61
67
|
asset = { code, issuer };
|
|
62
68
|
}
|
|
@@ -6,6 +6,7 @@ import { buildPaymentTransaction } from '../utils/buildPaymentTransaction.js';
|
|
|
6
6
|
import { checkTrustline } from '../utils/checkTrustline.js';
|
|
7
7
|
import { createPaymentAsset } from '../utils/createPaymentAsset.js';
|
|
8
8
|
import { getAccountBalance } from '../utils/getAccountBalance.js';
|
|
9
|
+
import '@dynamic-labs/utils';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Stellar wallet implementation that provides chain-specific functionality
|
|
@@ -25,8 +26,13 @@ class StellarWallet extends Wallet {
|
|
|
25
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
27
|
yield this._connector.connect();
|
|
27
28
|
const horizonServer = yield this.getHorizonServer();
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
try {
|
|
30
|
+
const account = yield horizonServer.loadAccount(this.address);
|
|
31
|
+
return getAccountBalance(account, assetCode, assetIssuer);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
return '0';
|
|
35
|
+
}
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
38
|
/**
|
|
@@ -50,9 +56,9 @@ class StellarWallet extends Wallet {
|
|
|
50
56
|
const networkPassphrase = yield this._connector.getNetworkPassphrase();
|
|
51
57
|
let asset;
|
|
52
58
|
if (token === null || token === void 0 ? void 0 : token.address) {
|
|
53
|
-
const [code, issuer] = token.address.split(
|
|
59
|
+
const [code, issuer] = token.address.split(/[:-]/);
|
|
54
60
|
if (!code || !issuer) {
|
|
55
|
-
throw new Error('Invalid token address format. Expected "CODE:ISSUER" (e.g., "USDC:GXXXXXXX...")');
|
|
61
|
+
throw new Error('Invalid token address format. Expected "CODE:ISSUER" or "CODE-ISSUER" (e.g., "USDC:GXXXXXXX..." or "USDC-GXXXXXXX...")');
|
|
56
62
|
}
|
|
57
63
|
asset = { code, issuer };
|
|
58
64
|
}
|