@sodax/wallet-sdk-react 2.0.0-rc.2 → 2.0.0-rc.21
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/README.md +14 -7
- package/dist/{XConnector-B9YQTVJ4.d.ts → XConnector-12q0OVe5.d.ts} +1 -1
- package/dist/{chunk-NY7U7OJW.mjs → chunk-7V7O3Q7Y.mjs} +0 -2
- package/dist/{chunk-BXJLBR4G.mjs → chunk-C6M34IVL.mjs} +2 -4
- package/dist/{chunk-PLCA4ZDJ.mjs → chunk-HEY7NRFG.mjs} +254 -52
- package/dist/{chunk-X2MHIWXO.mjs → chunk-IFXZQW4C.mjs} +0 -2
- package/dist/{chunk-7ULB6DW4.mjs → chunk-JQ4H4GJ5.mjs} +3 -5
- package/dist/{chunk-E5IAZ7E6.mjs → chunk-LM7R5APS.mjs} +22 -11
- package/dist/{chunk-BKJB527E.mjs → chunk-MWWVB7TD.mjs} +2 -4
- package/dist/{chunk-MXZVF5HR.mjs → chunk-NAKCAL2M.mjs} +0 -2
- package/dist/{chunk-PJLEJVAU.mjs → chunk-OPX55MQO.mjs} +11 -6
- package/dist/chunk-QMXBY3UI.mjs +1 -0
- package/dist/{chunk-MAQ47Q52.mjs → chunk-TACW7Z4D.mjs} +0 -2
- package/dist/chunk-VPNYFVP6.mjs +53 -0
- package/dist/{chunk-2BOUGCJ7.mjs → chunk-WPZOLGVB.mjs} +4 -6
- package/dist/{chunk-66BAUK56.mjs → chunk-X7BHR7WS.mjs} +4 -6
- package/dist/{chunk-N5A2TMF6.mjs → chunk-XJA2MJMG.mjs} +2 -4
- package/dist/{config-OlnzyEUE.d.ts → config-DEsqgrG1.d.ts} +10 -5
- package/dist/index.d.ts +6 -6
- package/dist/index.mjs +20 -31
- package/dist/xchains/bitcoin/index.d.ts +20 -3
- package/dist/xchains/bitcoin/index.mjs +14 -16
- package/dist/xchains/evm/index.d.ts +3 -3
- package/dist/xchains/evm/index.mjs +3 -5
- package/dist/xchains/icon/index.d.ts +1 -1
- package/dist/xchains/icon/index.mjs +5 -7
- package/dist/xchains/injective/index.d.ts +2 -2
- package/dist/xchains/injective/index.mjs +3 -5
- package/dist/xchains/near/index.d.ts +1 -1
- package/dist/xchains/near/index.mjs +4 -6
- package/dist/xchains/solana/index.d.ts +1 -1
- package/dist/xchains/solana/index.mjs +5 -7
- package/dist/xchains/stacks/index.d.ts +10 -4
- package/dist/xchains/stacks/index.mjs +3 -5
- package/dist/xchains/stellar/index.d.ts +1 -1
- package/dist/xchains/stellar/index.mjs +4 -6
- package/dist/xchains/sui/index.d.ts +1 -1
- package/dist/xchains/sui/index.mjs +5 -7
- package/package.json +37 -29
- package/ai-exported/AGENTS.md +0 -122
- package/ai-exported/integration/README.md +0 -102
- package/ai-exported/integration/ai-rules.md +0 -136
- package/ai-exported/integration/architecture.md +0 -181
- package/ai-exported/integration/examples/01-minimal-evm.tsx +0 -75
- package/ai-exported/integration/examples/02-multi-chain-modal.tsx +0 -169
- package/ai-exported/integration/examples/03-nextjs-app-router.tsx +0 -99
- package/ai-exported/integration/examples/04-walletconnect-setup.tsx +0 -89
- package/ai-exported/integration/examples/README.md +0 -29
- package/ai-exported/integration/recipes/batch-operations.md +0 -223
- package/ai-exported/integration/recipes/bridge-to-sdk.md +0 -164
- package/ai-exported/integration/recipes/chain-detection.md +0 -254
- package/ai-exported/integration/recipes/connect-button.md +0 -156
- package/ai-exported/integration/recipes/multi-chain-modal.md +0 -199
- package/ai-exported/integration/recipes/setup.md +0 -158
- package/ai-exported/integration/recipes/sign-message.md +0 -137
- package/ai-exported/integration/recipes/sub-path-imports.md +0 -95
- package/ai-exported/integration/recipes/switch-chain.md +0 -141
- package/ai-exported/integration/recipes/walletconnect-setup.md +0 -139
- package/ai-exported/integration/reference/api-surface.md +0 -175
- package/ai-exported/integration/reference/chain-support.md +0 -78
- package/ai-exported/integration/reference/connectors.md +0 -74
- package/ai-exported/integration/reference/hooks.md +0 -204
- package/ai-exported/integration/reference/wallet-brands.md +0 -106
- package/ai-exported/migration/README.md +0 -49
- package/ai-exported/migration/ai-rules.md +0 -144
- package/ai-exported/migration/breaking-changes.md +0 -305
- package/ai-exported/migration/checklist.md +0 -159
- package/ai-exported/migration/recipes/connect-button.md +0 -166
- package/ai-exported/migration/recipes/multi-chain-modal.md +0 -244
- package/ai-exported/migration/recipes/ssr-setup.md +0 -162
- package/ai-exported/migration/recipes/walletconnect-migration.md +0 -168
- package/ai-exported/migration/reference/components.md +0 -73
- package/ai-exported/migration/reference/config.md +0 -307
- package/ai-exported/migration/reference/hooks.md +0 -278
- package/ai-exported/migration/reference/imports.md +0 -157
- package/dist/chunk-2BOUGCJ7.mjs.map +0 -1
- package/dist/chunk-66BAUK56.mjs.map +0 -1
- package/dist/chunk-7ULB6DW4.mjs.map +0 -1
- package/dist/chunk-BKJB527E.mjs.map +0 -1
- package/dist/chunk-BXJLBR4G.mjs.map +0 -1
- package/dist/chunk-E5IAZ7E6.mjs.map +0 -1
- package/dist/chunk-MAQ47Q52.mjs.map +0 -1
- package/dist/chunk-MXZVF5HR.mjs.map +0 -1
- package/dist/chunk-N5A2TMF6.mjs.map +0 -1
- package/dist/chunk-NY7U7OJW.mjs.map +0 -1
- package/dist/chunk-PJLEJVAU.mjs.map +0 -1
- package/dist/chunk-PLCA4ZDJ.mjs.map +0 -1
- package/dist/chunk-TZMKDXFA.mjs +0 -3
- package/dist/chunk-TZMKDXFA.mjs.map +0 -1
- package/dist/chunk-X2MHIWXO.mjs.map +0 -1
- package/dist/chunk-XZ7CHO2S.mjs +0 -41
- package/dist/chunk-XZ7CHO2S.mjs.map +0 -1
- package/dist/index.cjs +0 -3337
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/xchains/bitcoin/index.cjs +0 -1927
- package/dist/xchains/bitcoin/index.cjs.map +0 -1
- package/dist/xchains/bitcoin/index.mjs.map +0 -1
- package/dist/xchains/evm/index.cjs +0 -316
- package/dist/xchains/evm/index.cjs.map +0 -1
- package/dist/xchains/evm/index.mjs.map +0 -1
- package/dist/xchains/icon/index.cjs +0 -311
- package/dist/xchains/icon/index.cjs.map +0 -1
- package/dist/xchains/icon/index.mjs.map +0 -1
- package/dist/xchains/injective/index.cjs +0 -223
- package/dist/xchains/injective/index.cjs.map +0 -1
- package/dist/xchains/injective/index.mjs.map +0 -1
- package/dist/xchains/near/index.cjs +0 -190
- package/dist/xchains/near/index.cjs.map +0 -1
- package/dist/xchains/near/index.mjs.map +0 -1
- package/dist/xchains/solana/index.cjs +0 -186
- package/dist/xchains/solana/index.cjs.map +0 -1
- package/dist/xchains/solana/index.mjs.map +0 -1
- package/dist/xchains/stacks/index.cjs +0 -240
- package/dist/xchains/stacks/index.cjs.map +0 -1
- package/dist/xchains/stacks/index.mjs.map +0 -1
- package/dist/xchains/stellar/index.cjs +0 -322
- package/dist/xchains/stellar/index.cjs.map +0 -1
- package/dist/xchains/stellar/index.mjs.map +0 -1
- package/dist/xchains/sui/index.cjs +0 -248
- package/dist/xchains/sui/index.cjs.map +0 -1
- package/dist/xchains/sui/index.mjs.map +0 -1
- package/docs/ADDING_A_NEW_CHAIN.md +0 -440
- package/docs/ARCHITECTURE.md +0 -291
- package/docs/BATCH_OPERATIONS.md +0 -267
- package/docs/CHAIN_DETECTION.md +0 -216
- package/docs/CONFIGURE_PROVIDER.md +0 -360
- package/docs/CONNECTORS.md +0 -247
- package/docs/CONNECT_FLOW.md +0 -276
- package/docs/EVM_SWITCH_CHAIN.md +0 -161
- package/docs/SIGN_MESSAGE.md +0 -213
- package/docs/SUB_PATH_EXPORTS.md +0 -246
- package/docs/WALLETCONNECT.md +0 -154
- package/docs/WALLET_MODAL.md +0 -331
- package/docs/WALLET_PROVIDER_BRIDGE.md +0 -226
- package/skills/SKILLS.md +0 -84
- package/skills/bridge-to-sdk.md +0 -148
- package/skills/connect-button.md +0 -116
- package/skills/evm-only-walletconnect.md +0 -111
- package/skills/multi-chain-modal.md +0 -178
- package/skills/setup.md +0 -107
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@ React layer over [`@sodax/wallet-sdk-core`](https://github.com/icon-project/soda
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **Unified wallet connectivity** for 9 chain families across
|
|
8
|
-
- EVM (Sonic hub, Ethereum, Arbitrum, Base, BSC, Optimism, Polygon, Avalanche, HyperEVM, Lightlink, Redbelly, Kaia) — EIP-6963 + WalletConnect
|
|
7
|
+
- **Unified wallet connectivity** for 9 chain families across 21 chains
|
|
8
|
+
- EVM (Sonic hub, Ethereum, Arbitrum, Base, BSC, Optimism, Polygon, Avalanche, HyperEVM, Lightlink, Redbelly, Kaia, Hedera) — EIP-6963 + WalletConnect
|
|
9
9
|
- Solana, Sui, Stellar, ICON, Injective, Bitcoin, NEAR, Stacks
|
|
10
10
|
- **Single-store state** — `useXAccount`, `useXConnection`, `useXAccounts` all read the same Zustand slice; persisted to `localStorage`
|
|
11
11
|
- **Bridge to `@sodax/sdk`** — `useWalletProvider` returns a typed `IXxxWalletProvider` ready to plug into any SDK call
|
|
@@ -117,14 +117,21 @@ The full guide lives in [`docs/`](docs/). Start with the topic that matches what
|
|
|
117
117
|
|
|
118
118
|
## AI agent docs
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
AI-readable docs for `@sodax/wallet-sdk-react` (and the other `@sodax/*` packages) are shipped via [`@sodax/skills`](https://github.com/icon-project/sodax-sdks/tree/main/packages/skills) — a separate npm package bundling Claude-Code SKILL.md files and a long-form knowledge tree.
|
|
121
121
|
|
|
122
|
+
**Recommended: [`skills` CLI](https://github.com/vercel-labs/skills)** — from your project root:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
npx skills@latest add icon-project/sodax-sdks/packages/skills
|
|
122
126
|
```
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
|
|
128
|
+
**npm + `AGENTS.md` pointer** (fallback for web chats, or when you prefer a devDependency over the CLI):
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
pnpm add -D @sodax/skills
|
|
125
132
|
```
|
|
126
133
|
|
|
127
|
-
|
|
134
|
+
Then point your agent at `node_modules/@sodax/skills/AGENTS.md`. See [docs/ai-integration-guide.md](https://github.com/icon-project/sodax-sdks/blob/main/docs/ai-integration-guide.md) for all install modes and per-tool wiring.
|
|
128
135
|
|
|
129
136
|
---
|
|
130
137
|
|
|
@@ -147,7 +154,7 @@ See [Connectors](docs/CONNECTORS.md) for the full list of deep-import sub-paths.
|
|
|
147
154
|
|
|
148
155
|
## Requirements
|
|
149
156
|
|
|
150
|
-
- Node.js >=
|
|
157
|
+
- Node.js >= 20.12.0
|
|
151
158
|
- React >= 19
|
|
152
159
|
- TypeScript
|
|
153
160
|
|
|
@@ -143,4 +143,4 @@ declare abstract class XConnector implements IXConnector {
|
|
|
143
143
|
get installUrl(): string | undefined;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
export { type IXConnector as I, type XAccount as X, type
|
|
146
|
+
export { type IXConnector as I, type XAccount as X, type IXService as a, type XConnection as b, XConnector as c, XService as d };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NEAR_DEFAULT_RPC_URL } from './chunk-
|
|
2
|
-
import { XService, XConnector } from './chunk-
|
|
1
|
+
import { NEAR_DEFAULT_RPC_URL } from './chunk-NAKCAL2M.mjs';
|
|
2
|
+
import { XService, XConnector } from './chunk-IFXZQW4C.mjs';
|
|
3
3
|
import { NearConnector } from '@hot-labs/near-connect';
|
|
4
4
|
import { JsonRpcProvider } from 'near-api-js';
|
|
5
5
|
|
|
@@ -84,5 +84,3 @@ var NearXConnector = class extends XConnector {
|
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
export { NearXConnector, NearXService };
|
|
87
|
-
//# sourceMappingURL=chunk-BXJLBR4G.mjs.map
|
|
88
|
-
//# sourceMappingURL=chunk-BXJLBR4G.mjs.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { EvmXService } from './chunk-
|
|
4
|
-
import { IconHanaXConnector,
|
|
5
|
-
import { assert, isRecord, hasFunctionProperty } from './chunk-
|
|
6
|
-
import { InjectiveXConnector, InjectiveXService } from './chunk-
|
|
7
|
-
import {
|
|
8
|
-
import { BITCOIN_DEFAULT_RPC_URL, WALLET_METADATA } from './chunk-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { XConnector, XService } from './chunk-
|
|
13
|
-
import { ChainTypeArr, baseChainInfo, ChainKeys, detectBitcoinAddressType, CHAIN_KEYS } from '@sodax/types';
|
|
1
|
+
import { SuiXService } from './chunk-JQ4H4GJ5.mjs';
|
|
2
|
+
import { StellarWalletsKitXConnector, StellarXService } from './chunk-X7BHR7WS.mjs';
|
|
3
|
+
import { EvmXService } from './chunk-LM7R5APS.mjs';
|
|
4
|
+
import { IconHanaXConnector, CHAIN_INFO, IconXService } from './chunk-WPZOLGVB.mjs';
|
|
5
|
+
import { assert, isRecord, hasFunctionProperty } from './chunk-TACW7Z4D.mjs';
|
|
6
|
+
import { InjectiveXConnector, InjectiveXService } from './chunk-MWWVB7TD.mjs';
|
|
7
|
+
import { NearXConnector, NearXService } from './chunk-C6M34IVL.mjs';
|
|
8
|
+
import { BITCOIN_DEFAULT_RPC_URL, WALLET_METADATA } from './chunk-NAKCAL2M.mjs';
|
|
9
|
+
import { StacksXConnector, STACKS_PROVIDERS, StacksXService } from './chunk-OPX55MQO.mjs';
|
|
10
|
+
import { SolanaXService } from './chunk-VPNYFVP6.mjs';
|
|
11
|
+
import { isNativeToken, getEntryDefaults, getRpcUrl } from './chunk-7V7O3Q7Y.mjs';
|
|
12
|
+
import { XConnector, XService } from './chunk-IFXZQW4C.mjs';
|
|
13
|
+
import { ChainTypeArr, baseChainInfo, ChainKeys, usesBip322MessageSigning, detectBitcoinAddressType, CHAIN_KEYS } from '@sodax/types';
|
|
14
14
|
import { AddressPurpose, MessageSigningProtocols } from 'sats-connect';
|
|
15
15
|
import { createContext, useMemo, useSyncExternalStore, useCallback, useState, useRef, useContext, useEffect } from 'react';
|
|
16
16
|
import { create } from 'zustand';
|
|
@@ -262,7 +262,7 @@ var XverseWalletProvider = class {
|
|
|
262
262
|
var XVERSE_ADDRESS_TYPE_KEY = "xverse-address-type";
|
|
263
263
|
var XverseXConnector = class _XverseXConnector extends BitcoinXConnector {
|
|
264
264
|
walletProvider;
|
|
265
|
-
/** Address purpose used when connecting. Taproot (Ordinals) by default to match
|
|
265
|
+
/** Address purpose used when connecting. Taproot (Ordinals) by default to match Bound Exchange. */
|
|
266
266
|
addressPurpose;
|
|
267
267
|
constructor(defaults) {
|
|
268
268
|
super("Xverse", "xverse", defaults);
|
|
@@ -416,6 +416,190 @@ var OKXXConnector = class _OKXXConnector extends BitcoinXConnector {
|
|
|
416
416
|
return new OKXWalletProvider(xAccount.address, this.defaults);
|
|
417
417
|
}
|
|
418
418
|
};
|
|
419
|
+
var HANA_PROVIDER_ID = "hanaWallet.bitcoin";
|
|
420
|
+
var BitcoinHanaWalletProvider = class {
|
|
421
|
+
chainType = "BITCOIN";
|
|
422
|
+
address;
|
|
423
|
+
publicKey;
|
|
424
|
+
defaults;
|
|
425
|
+
constructor(address, publicKey, defaults) {
|
|
426
|
+
this.address = address;
|
|
427
|
+
this.publicKey = publicKey;
|
|
428
|
+
this.defaults = defaults;
|
|
429
|
+
}
|
|
430
|
+
async getWalletAddress() {
|
|
431
|
+
return this.address;
|
|
432
|
+
}
|
|
433
|
+
async getPublicKey() {
|
|
434
|
+
return this.publicKey;
|
|
435
|
+
}
|
|
436
|
+
async getAddressType(_address) {
|
|
437
|
+
return detectBitcoinAddressType(this.address);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Parse a base64-encoded PSBT to count the number of inputs.
|
|
441
|
+
* Reads the unsigned transaction from the PSBT global section.
|
|
442
|
+
*/
|
|
443
|
+
countPsbtInputs(psbtBase64) {
|
|
444
|
+
const data = Buffer.from(psbtBase64, "base64");
|
|
445
|
+
let offset = 5;
|
|
446
|
+
const keyLen = data[offset++] ?? 0;
|
|
447
|
+
if (keyLen !== 1 || data[offset++] !== 0) {
|
|
448
|
+
return 1;
|
|
449
|
+
}
|
|
450
|
+
const firstByte = data[offset++] ?? 0;
|
|
451
|
+
if (firstByte === 253) offset += 2;
|
|
452
|
+
else if (firstByte === 254) offset += 4;
|
|
453
|
+
else if (firstByte === 255) offset += 8;
|
|
454
|
+
offset += 4;
|
|
455
|
+
const inputByte = data[offset] ?? 0;
|
|
456
|
+
if (inputByte < 253) return inputByte;
|
|
457
|
+
return 1;
|
|
458
|
+
}
|
|
459
|
+
async signTransaction(psbtBase64, finalize) {
|
|
460
|
+
const effectiveFinalize = finalize ?? this.defaults?.defaultFinalize ?? false;
|
|
461
|
+
const { request } = await import('sats-connect');
|
|
462
|
+
const inputCount = this.countPsbtInputs(psbtBase64);
|
|
463
|
+
const signingIndexes = Array.from({ length: inputCount }, (_, i) => i);
|
|
464
|
+
const response = await request(
|
|
465
|
+
"signPsbt",
|
|
466
|
+
{
|
|
467
|
+
psbt: psbtBase64,
|
|
468
|
+
broadcast: false,
|
|
469
|
+
signInputs: {
|
|
470
|
+
[this.address]: signingIndexes
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
HANA_PROVIDER_ID
|
|
474
|
+
);
|
|
475
|
+
if (response.status === "error") {
|
|
476
|
+
throw new Error(response.error?.message || "Hana PSBT signing failed");
|
|
477
|
+
}
|
|
478
|
+
const result = response.result;
|
|
479
|
+
if (effectiveFinalize) {
|
|
480
|
+
return Buffer.from(result.psbt, "base64").toString("hex");
|
|
481
|
+
}
|
|
482
|
+
return result.psbt;
|
|
483
|
+
}
|
|
484
|
+
async signEcdsaMessage(message) {
|
|
485
|
+
const { request } = await import('sats-connect');
|
|
486
|
+
const response = await request(
|
|
487
|
+
"signMessage",
|
|
488
|
+
{
|
|
489
|
+
address: this.address,
|
|
490
|
+
message,
|
|
491
|
+
protocol: MessageSigningProtocols.ECDSA
|
|
492
|
+
},
|
|
493
|
+
HANA_PROVIDER_ID
|
|
494
|
+
);
|
|
495
|
+
if (response.status === "error") {
|
|
496
|
+
throw new Error(response.error?.message || "Hana ECDSA signing failed");
|
|
497
|
+
}
|
|
498
|
+
return response.result.signature;
|
|
499
|
+
}
|
|
500
|
+
async signBip322Message(message) {
|
|
501
|
+
const { request } = await import('sats-connect');
|
|
502
|
+
const response = await request(
|
|
503
|
+
"signMessage",
|
|
504
|
+
{
|
|
505
|
+
address: this.address,
|
|
506
|
+
message,
|
|
507
|
+
protocol: MessageSigningProtocols.BIP322
|
|
508
|
+
},
|
|
509
|
+
HANA_PROVIDER_ID
|
|
510
|
+
);
|
|
511
|
+
if (response.status === "error") {
|
|
512
|
+
throw new Error(response.error?.message || "Hana BIP322 signing failed");
|
|
513
|
+
}
|
|
514
|
+
return response.result.signature;
|
|
515
|
+
}
|
|
516
|
+
async sendBitcoin(toAddress, satoshis) {
|
|
517
|
+
const { request } = await import('sats-connect');
|
|
518
|
+
const response = await request(
|
|
519
|
+
"sendTransfer",
|
|
520
|
+
{
|
|
521
|
+
recipients: [
|
|
522
|
+
{
|
|
523
|
+
address: toAddress,
|
|
524
|
+
amount: Number(satoshis)
|
|
525
|
+
}
|
|
526
|
+
]
|
|
527
|
+
},
|
|
528
|
+
HANA_PROVIDER_ID
|
|
529
|
+
);
|
|
530
|
+
if (response.status === "error") {
|
|
531
|
+
throw new Error(response.error?.message || "Hana sendTransfer failed");
|
|
532
|
+
}
|
|
533
|
+
return response.result.txid;
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
var HANA_ADDRESS_TYPE_KEY = "hana-address-type";
|
|
537
|
+
var BitcoinHanaXConnector = class _BitcoinHanaXConnector extends BitcoinXConnector {
|
|
538
|
+
walletProvider;
|
|
539
|
+
/** Address purpose used when connecting. Taproot (Ordinals) by default to match Bound Exchange. */
|
|
540
|
+
addressPurpose;
|
|
541
|
+
constructor(defaults) {
|
|
542
|
+
super("Hana Wallet", "hana-bitcoin", defaults);
|
|
543
|
+
const saved = typeof window !== "undefined" ? localStorage.getItem(HANA_ADDRESS_TYPE_KEY) : null;
|
|
544
|
+
this.addressPurpose = saved === "segwit" ? AddressPurpose.Payment : AddressPurpose.Ordinals;
|
|
545
|
+
}
|
|
546
|
+
/** Set address purpose and persist to localStorage. */
|
|
547
|
+
setAddressPurpose(type) {
|
|
548
|
+
this.addressPurpose = type === "taproot" ? AddressPurpose.Ordinals : AddressPurpose.Payment;
|
|
549
|
+
if (typeof window !== "undefined") {
|
|
550
|
+
localStorage.setItem(HANA_ADDRESS_TYPE_KEY, type);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
static isAvailable() {
|
|
554
|
+
if (typeof window === "undefined") return false;
|
|
555
|
+
return !!window.hanaWallet?.bitcoin;
|
|
556
|
+
}
|
|
557
|
+
get isInstalled() {
|
|
558
|
+
return _BitcoinHanaXConnector.isAvailable();
|
|
559
|
+
}
|
|
560
|
+
get installUrl() {
|
|
561
|
+
return WALLET_METADATA.hana.installUrl;
|
|
562
|
+
}
|
|
563
|
+
get icon() {
|
|
564
|
+
return WALLET_METADATA.hana.icon;
|
|
565
|
+
}
|
|
566
|
+
async connect() {
|
|
567
|
+
if (!_BitcoinHanaXConnector.isAvailable()) {
|
|
568
|
+
throw new Error("Hana wallet is not installed");
|
|
569
|
+
}
|
|
570
|
+
const { request } = await import('sats-connect');
|
|
571
|
+
const response = await request(
|
|
572
|
+
"getAccounts",
|
|
573
|
+
{
|
|
574
|
+
purposes: [this.addressPurpose],
|
|
575
|
+
message: "Connect to Sodax"
|
|
576
|
+
},
|
|
577
|
+
HANA_PROVIDER_ID
|
|
578
|
+
);
|
|
579
|
+
if (response.status === "error") {
|
|
580
|
+
throw new Error(response.error?.message || "Hana connection failed");
|
|
581
|
+
}
|
|
582
|
+
const accounts = response.result;
|
|
583
|
+
const paymentAccount = accounts.find((a) => a.purpose === this.addressPurpose) || accounts[0];
|
|
584
|
+
if (!paymentAccount) return void 0;
|
|
585
|
+
this.walletProvider = new BitcoinHanaWalletProvider(paymentAccount.address, paymentAccount.publicKey, this.defaults);
|
|
586
|
+
return {
|
|
587
|
+
address: paymentAccount.address,
|
|
588
|
+
publicKey: paymentAccount.publicKey,
|
|
589
|
+
xChainType: "BITCOIN"
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
async disconnect() {
|
|
593
|
+
this.walletProvider = void 0;
|
|
594
|
+
}
|
|
595
|
+
getWalletProvider() {
|
|
596
|
+
return this.walletProvider;
|
|
597
|
+
}
|
|
598
|
+
recreateWalletProvider(xAccount) {
|
|
599
|
+
if (!xAccount.address || !xAccount.publicKey) return void 0;
|
|
600
|
+
return new BitcoinHanaWalletProvider(xAccount.address, xAccount.publicKey, this.defaults);
|
|
601
|
+
}
|
|
602
|
+
};
|
|
419
603
|
function getXChainType(xChainId) {
|
|
420
604
|
if (!xChainId) {
|
|
421
605
|
return void 0;
|
|
@@ -496,7 +680,12 @@ var chainRegistry = {
|
|
|
496
680
|
const defaults = getEntryDefaults(
|
|
497
681
|
walletConfig?.BITCOIN?.chains?.[ChainKeys.BITCOIN_MAINNET]
|
|
498
682
|
);
|
|
499
|
-
return [
|
|
683
|
+
return [
|
|
684
|
+
new UnisatXConnector(defaults),
|
|
685
|
+
new XverseXConnector(defaults),
|
|
686
|
+
new OKXXConnector(defaults),
|
|
687
|
+
new BitcoinHanaXConnector(defaults)
|
|
688
|
+
];
|
|
500
689
|
},
|
|
501
690
|
providerManaged: false,
|
|
502
691
|
createActions: (service, getStore) => ({
|
|
@@ -510,27 +699,16 @@ var chainRegistry = {
|
|
|
510
699
|
}
|
|
511
700
|
const address = connection?.xAccount.address;
|
|
512
701
|
if (!address) throw new Error("Bitcoin address not found");
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
case "P2TR": {
|
|
517
|
-
if (!hasSignBip322(connector)) {
|
|
518
|
-
throw new Error(`${connector.id} does not support BIP-322 signing`);
|
|
519
|
-
}
|
|
520
|
-
return connector.signBip322Message(message);
|
|
521
|
-
}
|
|
522
|
-
case "P2SH":
|
|
523
|
-
case "P2PKH": {
|
|
524
|
-
if (!hasSignEcdsa(connector)) {
|
|
525
|
-
throw new Error(`${connector.id} does not support ECDSA signing`);
|
|
526
|
-
}
|
|
527
|
-
return connector.signEcdsaMessage(message);
|
|
528
|
-
}
|
|
529
|
-
default: {
|
|
530
|
-
const _exhaustiveCheck = addressType;
|
|
531
|
-
throw new Error(`Unhandled Bitcoin address type: ${_exhaustiveCheck}`);
|
|
702
|
+
if (usesBip322MessageSigning(detectBitcoinAddressType(address))) {
|
|
703
|
+
if (!hasSignBip322(connector)) {
|
|
704
|
+
throw new Error(`${connector.id} does not support BIP-322 signing`);
|
|
532
705
|
}
|
|
706
|
+
return connector.signBip322Message(message);
|
|
707
|
+
}
|
|
708
|
+
if (!hasSignEcdsa(connector)) {
|
|
709
|
+
throw new Error(`${connector.id} does not support ECDSA signing`);
|
|
533
710
|
}
|
|
711
|
+
return connector.signEcdsaMessage(message);
|
|
534
712
|
}
|
|
535
713
|
}),
|
|
536
714
|
createWalletProvider: (service, getStore) => {
|
|
@@ -803,9 +981,20 @@ var useXWalletStore = create()(
|
|
|
803
981
|
}
|
|
804
982
|
})),
|
|
805
983
|
{
|
|
806
|
-
// key kept as 'xwagmi-store' for backward compat
|
|
984
|
+
// key kept as 'xwagmi-store' for backward compat, existing users won't lose persisted connections on upgrade
|
|
807
985
|
name: "xwagmi-store",
|
|
808
|
-
|
|
986
|
+
// Throw on SSR or when localStorage rejects writes (Safari strict
|
|
987
|
+
// private mode, disabled storage). `createJSONStorage` catches the
|
|
988
|
+
// throw, zustand short-circuits `.persist`, and downstream falls back
|
|
989
|
+
// via `usePersistHydrated`. `setItem` probe is required because modern
|
|
990
|
+
// Safari only throws on writes, not reads.
|
|
991
|
+
storage: createJSONStorage(() => {
|
|
992
|
+
if (typeof window === "undefined") throw new Error("no window");
|
|
993
|
+
const probe = "__sodax_probe__";
|
|
994
|
+
window.localStorage.setItem(probe, "1");
|
|
995
|
+
window.localStorage.removeItem(probe);
|
|
996
|
+
return window.localStorage;
|
|
997
|
+
}),
|
|
809
998
|
partialize: (state) => ({
|
|
810
999
|
xConnections: state.xConnections,
|
|
811
1000
|
userDisconnected: state.userDisconnected
|
|
@@ -988,6 +1177,33 @@ function useChainGroups({ order } = {}) {
|
|
|
988
1177
|
[enabledChains, xConnections, order]
|
|
989
1178
|
);
|
|
990
1179
|
}
|
|
1180
|
+
var NOOP = () => {
|
|
1181
|
+
};
|
|
1182
|
+
function subscribe(onChange) {
|
|
1183
|
+
const api = useXWalletStore.persist;
|
|
1184
|
+
if (!api) return NOOP;
|
|
1185
|
+
const unsubHydrate = api.onHydrate(onChange);
|
|
1186
|
+
const unsubFinish = api.onFinishHydration(onChange);
|
|
1187
|
+
return () => {
|
|
1188
|
+
unsubHydrate();
|
|
1189
|
+
unsubFinish();
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
var getSnapshot = () => useXWalletStore.persist?.hasHydrated() ?? true;
|
|
1193
|
+
var getServerSnapshot = () => false;
|
|
1194
|
+
function usePersistHydrated() {
|
|
1195
|
+
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
1196
|
+
}
|
|
1197
|
+
function whenPersistReady(cb) {
|
|
1198
|
+
const api = useXWalletStore.persist;
|
|
1199
|
+
if (!api || api.hasHydrated()) {
|
|
1200
|
+
cb();
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
api.onFinishHydration(cb);
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
// src/hooks/useConnectedChains.ts
|
|
991
1207
|
function buildConnectedChains(xConnections, xConnectorsByChain, isReady = true, order) {
|
|
992
1208
|
const chains = [];
|
|
993
1209
|
for (const chainType of ChainTypeArr) {
|
|
@@ -1012,22 +1228,10 @@ function buildConnectedChains(xConnections, xConnectorsByChain, isReady = true,
|
|
|
1012
1228
|
status: isReady ? "ready" : "loading"
|
|
1013
1229
|
};
|
|
1014
1230
|
}
|
|
1015
|
-
function subscribeHydration(onChange) {
|
|
1016
|
-
const unsubHydrate = useXWalletStore.persist.onHydrate(onChange);
|
|
1017
|
-
const unsubFinish = useXWalletStore.persist.onFinishHydration(onChange);
|
|
1018
|
-
return () => {
|
|
1019
|
-
unsubHydrate();
|
|
1020
|
-
unsubFinish();
|
|
1021
|
-
};
|
|
1022
|
-
}
|
|
1023
1231
|
function useConnectedChains({ order } = {}) {
|
|
1024
1232
|
const xConnections = useXConnections();
|
|
1025
1233
|
const xConnectorsByChain = useXConnectorsByChain();
|
|
1026
|
-
const isReady =
|
|
1027
|
-
subscribeHydration,
|
|
1028
|
-
() => useXWalletStore.persist.hasHydrated(),
|
|
1029
|
-
() => false
|
|
1030
|
-
);
|
|
1234
|
+
const isReady = usePersistHydrated();
|
|
1031
1235
|
return useMemo(
|
|
1032
1236
|
() => buildConnectedChains(xConnections, xConnectorsByChain, isReady, order),
|
|
1033
1237
|
[xConnections, xConnectorsByChain, isReady, order]
|
|
@@ -1580,6 +1784,4 @@ function useBitcoinXConnectors() {
|
|
|
1580
1784
|
}, [xService]);
|
|
1581
1785
|
}
|
|
1582
1786
|
|
|
1583
|
-
export { BitcoinXConnector, BitcoinXService, OKXXConnector, UnisatXConnector, WalletConfigProvider, XverseXConnector, chainRegistry, getXChainType, getXService, useBatchConnect, useBatchDisconnect, useBitcoinXConnectors, useChainGroups, useConnectedChains, useConnectionFlow, useEnabledChainTypes, useEnabledChains, useEvmSwitchChain, useIsChainEnabled, useIsWalletInstalled, useWalletConfig, useWalletModal, useWalletProvider, useXAccount, useXAccounts, useXConnect, useXConnection, useXConnections, useXConnectors, useXConnectorsByChain, useXDisconnect, useXService, useXServices, useXSignMessage, useXWalletStore };
|
|
1584
|
-
//# sourceMappingURL=chunk-PLCA4ZDJ.mjs.map
|
|
1585
|
-
//# sourceMappingURL=chunk-PLCA4ZDJ.mjs.map
|
|
1787
|
+
export { BitcoinHanaXConnector, BitcoinXConnector, BitcoinXService, OKXXConnector, UnisatXConnector, WalletConfigProvider, XverseXConnector, chainRegistry, getXChainType, getXService, useBatchConnect, useBatchDisconnect, useBitcoinXConnectors, useChainGroups, useConnectedChains, useConnectionFlow, useEnabledChainTypes, useEnabledChains, useEvmSwitchChain, useIsChainEnabled, useIsWalletInstalled, usePersistHydrated, useWalletConfig, useWalletModal, useWalletProvider, useXAccount, useXAccounts, useXConnect, useXConnection, useXConnections, useXConnectors, useXConnectorsByChain, useXDisconnect, useXService, useXServices, useXSignMessage, useXWalletStore, whenPersistReady };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { assertSuiProviderShape, assert, isRecord, hasStringProperty, hasOptionalStringProperty } from './chunk-
|
|
2
|
-
import { isNativeToken } from './chunk-
|
|
3
|
-
import { XService, XConnector } from './chunk-
|
|
1
|
+
import { assertSuiProviderShape, assert, isRecord, hasStringProperty, hasOptionalStringProperty } from './chunk-TACW7Z4D.mjs';
|
|
2
|
+
import { isNativeToken } from './chunk-7V7O3Q7Y.mjs';
|
|
3
|
+
import { XService, XConnector } from './chunk-IFXZQW4C.mjs';
|
|
4
4
|
import { SuiWalletProvider } from '@sodax/wallet-sdk-core';
|
|
5
5
|
|
|
6
6
|
var SuiXService = class _SuiXService extends XService {
|
|
@@ -98,5 +98,3 @@ var SuiXConnector = class extends XConnector {
|
|
|
98
98
|
};
|
|
99
99
|
|
|
100
100
|
export { SuiXConnector, SuiXService };
|
|
101
|
-
//# sourceMappingURL=chunk-7ULB6DW4.mjs.map
|
|
102
|
-
//# sourceMappingURL=chunk-7ULB6DW4.mjs.map
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { getRpcUrl, getWagmiChainId, isNativeToken } from './chunk-
|
|
2
|
-
import { XService, XConnector } from './chunk-
|
|
1
|
+
import { getRpcUrl, getWagmiChainId, isNativeToken } from './chunk-7V7O3Q7Y.mjs';
|
|
2
|
+
import { XService, XConnector } from './chunk-IFXZQW4C.mjs';
|
|
3
3
|
import { ChainKeys } from '@sodax/types';
|
|
4
|
-
import {
|
|
4
|
+
import { erc20Abi, defineChain } from 'viem';
|
|
5
5
|
import { getPublicClient } from 'wagmi/actions';
|
|
6
|
-
import { createConfig, createStorage,
|
|
7
|
-
import { mainnet, avalanche, arbitrum, base, bsc, sonic, optimism, polygon, lightlinkPhoenix, kaia, redbellyMainnet } from 'wagmi/chains';
|
|
6
|
+
import { createConfig, createStorage, cookieStorage, http } from 'wagmi';
|
|
7
|
+
import { mainnet, avalanche, arbitrum, base, bsc, sonic, optimism, polygon, lightlinkPhoenix, kaia, redbellyMainnet, hedera } from 'wagmi/chains';
|
|
8
8
|
|
|
9
|
+
var HEDERA_NATIVE_BALANCE_SCALE = 10n ** 10n;
|
|
9
10
|
var hyper = /* @__PURE__ */ defineChain({
|
|
10
11
|
id: 999,
|
|
11
12
|
name: "HyperEVM",
|
|
@@ -44,10 +45,17 @@ var createWagmiConfig = (evmChains, options) => {
|
|
|
44
45
|
hyper,
|
|
45
46
|
lightlinkPhoenix,
|
|
46
47
|
kaia,
|
|
47
|
-
redbellyMainnet
|
|
48
|
+
redbellyMainnet,
|
|
49
|
+
hedera
|
|
48
50
|
],
|
|
49
51
|
connectors: options?.connectors ?? [],
|
|
50
|
-
|
|
52
|
+
// NOTE: wagmi's `ssr` is a hydration-timing flag, not an "is host app SSR"
|
|
53
|
+
// flag. `true` defers `Hydrate.onMount()` into `useEffect` (safe for both
|
|
54
|
+
// CSR and SSR); `false` runs it in render and trips React's "setState
|
|
55
|
+
// during render" warning on subscribers like `EvmHydrator`. Default to
|
|
56
|
+
// `true` so direct callers of `createWagmiConfig` stay safe — only pass
|
|
57
|
+
// `false` if you have a specific reason. See issue #129.
|
|
58
|
+
ssr: options?.ssr ?? true,
|
|
51
59
|
transports: {
|
|
52
60
|
[mainnet.id]: http(getRpcUrl(evmChains?.[ChainKeys.ETHEREUM_MAINNET])),
|
|
53
61
|
[avalanche.id]: http(getRpcUrl(evmChains?.[ChainKeys.AVALANCHE_MAINNET])),
|
|
@@ -60,7 +68,8 @@ var createWagmiConfig = (evmChains, options) => {
|
|
|
60
68
|
[hyper.id]: http(getRpcUrl(evmChains?.[ChainKeys.HYPEREVM_MAINNET])),
|
|
61
69
|
[lightlinkPhoenix.id]: http(getRpcUrl(evmChains?.[ChainKeys.LIGHTLINK_MAINNET])),
|
|
62
70
|
[redbellyMainnet.id]: http(getRpcUrl(evmChains?.[ChainKeys.REDBELLY_MAINNET])),
|
|
63
|
-
[kaia.id]: http(getRpcUrl(evmChains?.[ChainKeys.KAIA_MAINNET]))
|
|
71
|
+
[kaia.id]: http(getRpcUrl(evmChains?.[ChainKeys.KAIA_MAINNET])),
|
|
72
|
+
[hedera.id]: http(getRpcUrl(evmChains?.[ChainKeys.HEDERA_MAINNET]))
|
|
64
73
|
},
|
|
65
74
|
storage: createStorage({
|
|
66
75
|
storage: cookieStorage,
|
|
@@ -104,7 +113,11 @@ var EvmXService = class _EvmXService extends XService {
|
|
|
104
113
|
if (!this.wagmiConfig) return 0n;
|
|
105
114
|
const chainId = getWagmiChainId(xToken.chainKey);
|
|
106
115
|
if (isNativeToken(xToken)) {
|
|
107
|
-
|
|
116
|
+
const balance = await this._getChainBalance(address, chainId);
|
|
117
|
+
if (xToken.chainKey === ChainKeys.HEDERA_MAINNET) {
|
|
118
|
+
return balance / HEDERA_NATIVE_BALANCE_SCALE;
|
|
119
|
+
}
|
|
120
|
+
return balance;
|
|
108
121
|
}
|
|
109
122
|
throw new Error(`Unsupported token: ${xToken.symbol}`);
|
|
110
123
|
}
|
|
@@ -182,5 +195,3 @@ var EvmXConnector = class extends XConnector {
|
|
|
182
195
|
};
|
|
183
196
|
|
|
184
197
|
export { EvmXConnector, EvmXService, createWagmiConfig };
|
|
185
|
-
//# sourceMappingURL=chunk-E5IAZ7E6.mjs.map
|
|
186
|
-
//# sourceMappingURL=chunk-E5IAZ7E6.mjs.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { XService, XConnector } from './chunk-
|
|
1
|
+
import { XService, XConnector } from './chunk-IFXZQW4C.mjs';
|
|
2
2
|
import { getNetworkEndpoints, Network } from '@injectivelabs/networks';
|
|
3
3
|
import { IndexerGrpcAccountPortfolioApi, ChainGrpcWasmApi, getInjectiveAddress } from '@injectivelabs/sdk-ts';
|
|
4
4
|
import { ChainId } from '@injectivelabs/ts-types';
|
|
5
5
|
import { MsgBroadcaster } from '@injectivelabs/wallet-core';
|
|
6
6
|
import { mainnet } from 'wagmi/chains';
|
|
7
|
-
import { WalletStrategy } from '@
|
|
7
|
+
import { WalletStrategy } from '@sodax/libs/injective/wallet-strategy';
|
|
8
8
|
import { isCosmosBrowserWallet, isEvmBrowserWallet } from '@injectivelabs/wallet-base';
|
|
9
9
|
import { isCosmosWalletInstalled } from '@injectivelabs/wallet-cosmos';
|
|
10
10
|
|
|
@@ -121,5 +121,3 @@ var InjectiveXConnector = class extends XConnector {
|
|
|
121
121
|
};
|
|
122
122
|
|
|
123
123
|
export { InjectiveXConnector, InjectiveXService };
|
|
124
|
-
//# sourceMappingURL=chunk-BKJB527E.mjs.map
|
|
125
|
-
//# sourceMappingURL=chunk-BKJB527E.mjs.map
|
|
@@ -30,5 +30,3 @@ var WALLET_METADATA = {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
export { BITCOIN_DEFAULT_RPC_URL, EVM_DEFAULT_RECONNECT_ON_MOUNT, EVM_DEFAULT_SSR, NEAR_DEFAULT_RPC_URL, SOLANA_DEFAULT_AUTO_CONNECT, SOLANA_DEFAULT_RPC_URL, SOLANA_METAMASK_CONNECT_TIMEOUT_MS, STELLAR_DEFAULT_HORIZON_RPC_URL, STELLAR_DEFAULT_SOROBAN_RPC_URL, SUI_DEFAULT_AUTO_CONNECT, SUI_DEFAULT_NETWORK, WALLET_METADATA };
|
|
33
|
-
//# sourceMappingURL=chunk-MXZVF5HR.mjs.map
|
|
34
|
-
//# sourceMappingURL=chunk-MXZVF5HR.mjs.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { XService, XConnector } from './chunk-
|
|
2
|
-
import { fetchCallReadOnlyFunction, Cl } from '@stacks/
|
|
3
|
-
import {
|
|
4
|
-
import { request, disconnect } from '@stacks/connect';
|
|
1
|
+
import { XService, XConnector } from './chunk-IFXZQW4C.mjs';
|
|
2
|
+
import { networkFrom, fetchCallReadOnlyFunction, Cl } from '@sodax/libs/stacks/core';
|
|
3
|
+
import { request, disconnect } from '@sodax/libs/stacks/connect';
|
|
5
4
|
import { useMemo } from 'react';
|
|
6
5
|
|
|
7
6
|
var StacksXService = class _StacksXService extends XService {
|
|
@@ -19,6 +18,12 @@ var StacksXService = class _StacksXService extends XService {
|
|
|
19
18
|
}
|
|
20
19
|
return _StacksXService.instance;
|
|
21
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @warning Network / fetch / contract-read failures are silently swallowed —
|
|
23
|
+
* `0n` is returned on any error. Callers cannot distinguish "zero balance"
|
|
24
|
+
* from "fetch failed"; UI that needs to surface the failure must wrap this
|
|
25
|
+
* call externally and re-fetch on its own error path.
|
|
26
|
+
*/
|
|
22
27
|
async getBalance(address, xToken) {
|
|
23
28
|
if (!address) return 0n;
|
|
24
29
|
if (xToken.symbol === "STX") {
|
|
@@ -55,6 +60,7 @@ var StacksXService = class _StacksXService extends XService {
|
|
|
55
60
|
}
|
|
56
61
|
};
|
|
57
62
|
function getProviderFromId(id) {
|
|
63
|
+
if (typeof window === "undefined") return void 0;
|
|
58
64
|
return id.split(".").reduce((acc, part) => acc?.[part], window);
|
|
59
65
|
}
|
|
60
66
|
var StacksXConnector = class extends XConnector {
|
|
@@ -79,6 +85,7 @@ var StacksXConnector = class extends XConnector {
|
|
|
79
85
|
}
|
|
80
86
|
return {
|
|
81
87
|
address: stxAddress.address,
|
|
88
|
+
publicKey: stxAddress.publicKey,
|
|
82
89
|
xChainType: this.xChainType
|
|
83
90
|
};
|
|
84
91
|
}
|
|
@@ -136,5 +143,3 @@ function useStacksXConnectors() {
|
|
|
136
143
|
}
|
|
137
144
|
|
|
138
145
|
export { STACKS_PROVIDERS, StacksXConnector, StacksXService, useStacksXConnectors };
|
|
139
|
-
//# sourceMappingURL=chunk-PJLEJVAU.mjs.map
|
|
140
|
-
//# sourceMappingURL=chunk-PJLEJVAU.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -29,5 +29,3 @@ function assertSuiProviderShape(caller, client, wallet, account) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export { assert, assertSuiProviderShape, hasBooleanProperty, hasFunctionProperty, hasOptionalStringProperty, hasStringProperty, isRecord };
|
|
32
|
-
//# sourceMappingURL=chunk-MAQ47Q52.mjs.map
|
|
33
|
-
//# sourceMappingURL=chunk-MAQ47Q52.mjs.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { isNativeToken } from './chunk-7V7O3Q7Y.mjs';
|
|
2
|
+
import { XService } from './chunk-IFXZQW4C.mjs';
|
|
3
|
+
import { PublicKey } from '@solana/web3.js';
|
|
4
|
+
import { TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, unpackAccount } from '@solana/spl-token';
|
|
5
|
+
|
|
6
|
+
var SolanaXService = class _SolanaXService extends XService {
|
|
7
|
+
static instance;
|
|
8
|
+
connection;
|
|
9
|
+
wallet;
|
|
10
|
+
constructor() {
|
|
11
|
+
super("SOLANA");
|
|
12
|
+
}
|
|
13
|
+
static getInstance() {
|
|
14
|
+
if (!_SolanaXService.instance) {
|
|
15
|
+
_SolanaXService.instance = new _SolanaXService();
|
|
16
|
+
}
|
|
17
|
+
return _SolanaXService.instance;
|
|
18
|
+
}
|
|
19
|
+
async getBalance(address, xToken) {
|
|
20
|
+
if (!address) return BigInt(0);
|
|
21
|
+
const connection = this.connection;
|
|
22
|
+
if (!connection) {
|
|
23
|
+
return BigInt(0);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
if (isNativeToken(xToken)) {
|
|
27
|
+
const newBalance = await connection.getBalance(new PublicKey(address));
|
|
28
|
+
return BigInt(newBalance);
|
|
29
|
+
}
|
|
30
|
+
const owner = new PublicKey(address);
|
|
31
|
+
const mint = new PublicKey(xToken.address);
|
|
32
|
+
const candidates = [TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID].map((programId) => ({
|
|
33
|
+
programId,
|
|
34
|
+
ata: getAssociatedTokenAddressSync(mint, owner, true, programId)
|
|
35
|
+
}));
|
|
36
|
+
const accounts = await connection.getMultipleAccountsInfo(candidates.map((c) => c.ata));
|
|
37
|
+
let balance = BigInt(0);
|
|
38
|
+
for (const [i, candidate] of candidates.entries()) {
|
|
39
|
+
const info = accounts[i];
|
|
40
|
+
if (!info) continue;
|
|
41
|
+
try {
|
|
42
|
+
balance += unpackAccount(candidate.ata, info, candidate.programId).amount;
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return balance;
|
|
47
|
+
} catch {
|
|
48
|
+
return BigInt(0);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { SolanaXService };
|