@sodax/wallet-sdk-react 1.2.7-beta → 1.3.0-beta
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/dist/index.cjs +118 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.mjs +119 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -5
- package/src/actions/getXService.ts +3 -0
- package/src/hooks/useWalletProvider.ts +14 -1
- package/src/hooks/useXConnectors.ts +6 -3
- package/src/hooks/useXDisconnect.ts +8 -0
- package/src/useXWagmiStore.ts +6 -1
- package/src/xchains/near/NearXConnector.ts +42 -0
- package/src/xchains/near/NearXService.ts +46 -0
- package/src/xchains/near/useNearXConnectors.ts +23 -0
- package/src/xchains/stellar/StellarWalletsKitXConnector.ts +9 -1
- package/src/xchains/stellar/useStellarXConnectors.ts +1 -10
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sodax/wallet-sdk-react",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0-beta",
|
|
5
5
|
"description": "Wallet SDK of Sodax",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
@@ -25,16 +25,18 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@coral-xyz/anchor": "0.30.1",
|
|
27
27
|
"@creit.tech/stellar-wallets-kit": "^1.7.5",
|
|
28
|
+
"@hot-labs/near-connect": "0.10.0",
|
|
28
29
|
"@injectivelabs/networks": "1.16.10",
|
|
29
30
|
"@injectivelabs/sdk-ts": "1.16.10",
|
|
30
31
|
"@injectivelabs/ts-types": "1.16.10",
|
|
31
32
|
"@injectivelabs/wallet-base": "1.16.10",
|
|
32
33
|
"@injectivelabs/wallet-core": "1.16.10",
|
|
33
|
-
"@injectivelabs/wallet-strategy": "1.16.10",
|
|
34
|
-
"@injectivelabs/wallet-evm": "1.16.10",
|
|
35
34
|
"@injectivelabs/wallet-cosmos": "1.16.10",
|
|
35
|
+
"@injectivelabs/wallet-evm": "1.16.10",
|
|
36
|
+
"@injectivelabs/wallet-strategy": "1.16.10",
|
|
36
37
|
"@mysten/dapp-kit": "0.14.18",
|
|
37
38
|
"@mysten/sui": "1.21.2",
|
|
39
|
+
"near-api-js": "7.1.1",
|
|
38
40
|
"@solana/spl-token": "0.4.9",
|
|
39
41
|
"@solana/wallet-adapter-react": "0.15.35",
|
|
40
42
|
"@solana/wallet-adapter-wallets": "0.19.30",
|
|
@@ -46,8 +48,8 @@
|
|
|
46
48
|
"wagmi": "2.16.9",
|
|
47
49
|
"zustand": "4.5.2",
|
|
48
50
|
"bs58": "6.0.0",
|
|
49
|
-
"@sodax/
|
|
50
|
-
"@sodax/
|
|
51
|
+
"@sodax/types": "1.3.0-beta",
|
|
52
|
+
"@sodax/wallet-sdk-core": "1.3.0-beta"
|
|
51
53
|
},
|
|
52
54
|
"devDependencies": {
|
|
53
55
|
"@types/react": "^19.0.8",
|
|
@@ -4,6 +4,7 @@ import { IconXService, InjectiveXService, SolanaXService, StellarXService } from
|
|
|
4
4
|
import { SuiXService } from '..';
|
|
5
5
|
import { EvmXService } from '..';
|
|
6
6
|
import type { XService } from '../core';
|
|
7
|
+
import { NearXService } from '../xchains/near/NearXService';
|
|
7
8
|
|
|
8
9
|
export function getXService(xChainType: ChainType): XService {
|
|
9
10
|
switch (xChainType) {
|
|
@@ -19,6 +20,8 @@ export function getXService(xChainType: ChainType): XService {
|
|
|
19
20
|
return InjectiveXService.getInstance();
|
|
20
21
|
case 'STELLAR':
|
|
21
22
|
return StellarXService.getInstance();
|
|
23
|
+
case 'NEAR':
|
|
24
|
+
return NearXService.getInstance();
|
|
22
25
|
default:
|
|
23
26
|
throw new Error(`Unsupported chain type: ${xChainType}`);
|
|
24
27
|
}
|
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
IEvmWalletProvider,
|
|
4
4
|
IIconWalletProvider,
|
|
5
5
|
IInjectiveWalletProvider,
|
|
6
|
+
INearWalletProvider,
|
|
6
7
|
ISolanaWalletProvider,
|
|
7
8
|
IStellarWalletProvider,
|
|
8
9
|
ISuiWalletProvider,
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
InjectiveWalletProvider,
|
|
16
17
|
StellarWalletProvider,
|
|
17
18
|
SolanaWalletProvider,
|
|
19
|
+
NearWalletProvider,
|
|
18
20
|
} from '@sodax/wallet-sdk-core';
|
|
19
21
|
import { getXChainType } from '../actions';
|
|
20
22
|
import { usePublicClient, useWalletClient } from 'wagmi';
|
|
@@ -22,10 +24,11 @@ import { type SolanaXService, type StellarXService, useXAccount, useXService } f
|
|
|
22
24
|
import type { SuiXService } from '../xchains/sui/SuiXService';
|
|
23
25
|
import { CHAIN_INFO, SupportedChainId } from '../xchains/icon/IconXService';
|
|
24
26
|
import type { InjectiveXService } from '../xchains/injective/InjectiveXService';
|
|
27
|
+
import type { NearXService } from '../xchains/near/NearXService';
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
30
|
* Hook to get the appropriate wallet provider based on the chain type.
|
|
28
|
-
* Supports EVM, SUI, ICON and
|
|
31
|
+
* Supports EVM, SUI, ICON, INJECTIVE, STELLAR, SOLANA and NEAR chains.
|
|
29
32
|
*
|
|
30
33
|
* @param {ChainId | undefined} spokeChainId - The chain ID to get the wallet provider for. Can be any valid ChainId value.
|
|
31
34
|
* @returns {EvmWalletProvider | SuiWalletProvider | IconWalletProvider | InjectiveWalletProvider | undefined}
|
|
@@ -49,6 +52,7 @@ export function useWalletProvider(
|
|
|
49
52
|
| IInjectiveWalletProvider
|
|
50
53
|
| IStellarWalletProvider
|
|
51
54
|
| ISolanaWalletProvider
|
|
55
|
+
| INearWalletProvider
|
|
52
56
|
| undefined {
|
|
53
57
|
const xChainType = getXChainType(spokeChainId);
|
|
54
58
|
// EVM-specific hooks
|
|
@@ -141,6 +145,15 @@ export function useWalletProvider(
|
|
|
141
145
|
});
|
|
142
146
|
}
|
|
143
147
|
|
|
148
|
+
case 'NEAR': {
|
|
149
|
+
const nearXService = xService as NearXService;
|
|
150
|
+
if (!nearXService.walletSelector) {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return new NearWalletProvider({ wallet: nearXService.walletSelector });
|
|
155
|
+
}
|
|
156
|
+
|
|
144
157
|
default:
|
|
145
158
|
return undefined;
|
|
146
159
|
}
|
|
@@ -9,6 +9,7 @@ import { SolanaXConnector } from '../xchains/solana';
|
|
|
9
9
|
import { useStellarXConnectors } from '../xchains/stellar/useStellarXConnectors';
|
|
10
10
|
import { SuiXConnector } from '../xchains/sui';
|
|
11
11
|
import { useXService } from './useXService';
|
|
12
|
+
import { useNearXConnectors } from '../xchains/near/useNearXConnectors';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Hook to retrieve available wallet connectors for a specific blockchain type.
|
|
@@ -19,7 +20,7 @@ import { useXService } from './useXService';
|
|
|
19
20
|
* - Stellar: Uses custom Stellar connectors
|
|
20
21
|
* - Solana: Uses Solana wallet adapters (filtered to installed wallets only)
|
|
21
22
|
*
|
|
22
|
-
* @param xChainType - The blockchain type to get connectors for ('EVM' | 'SUI' | 'STELLAR' | 'SOLANA')
|
|
23
|
+
* @param xChainType - The blockchain type to get connectors for ('EVM' | 'SUI' | 'STELLAR' | 'SOLANA' | 'NEAR')
|
|
23
24
|
* @returns An array of XConnector instances compatible with the specified chain type
|
|
24
25
|
*/
|
|
25
26
|
|
|
@@ -28,7 +29,7 @@ export function useXConnectors(xChainType: ChainType | undefined): XConnector[]
|
|
|
28
29
|
const evmConnectors = useConnectors();
|
|
29
30
|
const suiWallets = useWallets();
|
|
30
31
|
const { data: stellarXConnectors } = useStellarXConnectors();
|
|
31
|
-
|
|
32
|
+
const { data: nearXConnectors } = useNearXConnectors();
|
|
32
33
|
const { wallets: solanaWallets } = useWallet();
|
|
33
34
|
|
|
34
35
|
const xConnectors = useMemo((): XConnector[] => {
|
|
@@ -47,10 +48,12 @@ export function useXConnectors(xChainType: ChainType | undefined): XConnector[]
|
|
|
47
48
|
return solanaWallets
|
|
48
49
|
.filter(wallet => wallet.readyState === 'Installed')
|
|
49
50
|
.map(wallet => new SolanaXConnector(wallet));
|
|
51
|
+
case 'NEAR':
|
|
52
|
+
return nearXConnectors || [];
|
|
50
53
|
default:
|
|
51
54
|
return xService.getXConnectors();
|
|
52
55
|
}
|
|
53
|
-
}, [xService, xChainType, evmConnectors, suiWallets, stellarXConnectors, solanaWallets]);
|
|
56
|
+
}, [xService, xChainType, evmConnectors, suiWallets, stellarXConnectors, solanaWallets, nearXConnectors]);
|
|
54
57
|
|
|
55
58
|
return xConnectors;
|
|
56
59
|
}
|
|
@@ -5,6 +5,7 @@ import { useCallback } from 'react';
|
|
|
5
5
|
import { useDisconnect } from 'wagmi';
|
|
6
6
|
import { getXService } from '../actions';
|
|
7
7
|
import { useXWagmiStore } from '../useXWagmiStore';
|
|
8
|
+
import type { NearXService } from '@/xchains/near/NearXService';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Hook for disconnecting from a specific blockchain wallet
|
|
@@ -47,6 +48,13 @@ export function useXDisconnect(): (xChainType: ChainType) => Promise<void> {
|
|
|
47
48
|
case 'SOLANA':
|
|
48
49
|
await solanaWallet.disconnect();
|
|
49
50
|
break;
|
|
51
|
+
|
|
52
|
+
case 'NEAR': {
|
|
53
|
+
const nearXService = getXService('NEAR') as NearXService;
|
|
54
|
+
nearXService.walletSelector.disconnect();
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
50
58
|
default: {
|
|
51
59
|
// Handle other chain types
|
|
52
60
|
const xService = getXService(xChainType);
|
package/src/useXWagmiStore.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { StellarXService } from './xchains/stellar';
|
|
|
13
13
|
import { SuiXService } from './xchains/sui';
|
|
14
14
|
import { IconXService } from './xchains/icon';
|
|
15
15
|
import { IconHanaXConnector } from './xchains/icon/IconHanaXConnector';
|
|
16
|
+
import { NearXService } from './xchains/near/NearXService';
|
|
16
17
|
|
|
17
18
|
type XWagmiStore = {
|
|
18
19
|
xServices: Partial<Record<ChainType, XService>>;
|
|
@@ -24,7 +25,7 @@ type XWagmiStore = {
|
|
|
24
25
|
|
|
25
26
|
const initXServices = () => {
|
|
26
27
|
const xServices = {};
|
|
27
|
-
['EVM', 'INJECTIVE', 'STELLAR', 'SUI', 'SOLANA', 'ICON'].forEach(key => {
|
|
28
|
+
['EVM', 'INJECTIVE', 'STELLAR', 'SUI', 'SOLANA', 'ICON', 'NEAR'].forEach(key => {
|
|
28
29
|
const xChainType = key as ChainType;
|
|
29
30
|
|
|
30
31
|
switch (xChainType) {
|
|
@@ -55,6 +56,10 @@ const initXServices = () => {
|
|
|
55
56
|
xServices[xChainType] = IconXService.getInstance();
|
|
56
57
|
xServices[xChainType].setXConnectors([new IconHanaXConnector()]);
|
|
57
58
|
break;
|
|
59
|
+
case 'NEAR':
|
|
60
|
+
xServices[xChainType] = NearXService.getInstance();
|
|
61
|
+
xServices[xChainType].setXConnectors([]);
|
|
62
|
+
break;
|
|
58
63
|
default:
|
|
59
64
|
break;
|
|
60
65
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { XAccount } from '@/types';
|
|
2
|
+
|
|
3
|
+
import { XConnector } from '@/core';
|
|
4
|
+
import type { NearWalletBase } from '@hot-labs/near-connect';
|
|
5
|
+
import { NearXService } from './NearXService';
|
|
6
|
+
|
|
7
|
+
export class NearXConnector extends XConnector {
|
|
8
|
+
_wallet: NearWalletBase;
|
|
9
|
+
|
|
10
|
+
constructor(wallet: NearWalletBase) {
|
|
11
|
+
super('NEAR', wallet.manifest.name, wallet.manifest.id);
|
|
12
|
+
this._wallet = wallet;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getXService(): NearXService {
|
|
16
|
+
return NearXService.getInstance();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async connect(): Promise<XAccount | undefined> {
|
|
20
|
+
const walletSelector = this.getXService().walletSelector;
|
|
21
|
+
const wallet = await walletSelector.connect({ walletId: this._wallet.manifest.id });
|
|
22
|
+
const accounts = await wallet.getAccounts();
|
|
23
|
+
|
|
24
|
+
if (accounts.length === 0 || accounts[0] === undefined) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
address: accounts[0].accountId,
|
|
30
|
+
xChainType: this.xChainType,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async disconnect(): Promise<void> {
|
|
35
|
+
const walletSelector = this.getXService().walletSelector;
|
|
36
|
+
await walletSelector.disconnect(this._wallet);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public get icon() {
|
|
40
|
+
return this._wallet.manifest.icon;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { XService } from '@/core/XService';
|
|
2
|
+
import type { XToken } from '@sodax/types';
|
|
3
|
+
import { NearConnector } from '@hot-labs/near-connect';
|
|
4
|
+
import { JsonRpcProvider } from 'near-api-js';
|
|
5
|
+
|
|
6
|
+
export class NearXService extends XService {
|
|
7
|
+
private static instance: NearXService;
|
|
8
|
+
|
|
9
|
+
public walletSelector: NearConnector;
|
|
10
|
+
|
|
11
|
+
private constructor() {
|
|
12
|
+
super('NEAR');
|
|
13
|
+
|
|
14
|
+
this.walletSelector = new NearConnector({
|
|
15
|
+
network: 'mainnet',
|
|
16
|
+
logger: console,
|
|
17
|
+
autoConnect: true,
|
|
18
|
+
excludedWallets: ['okx-wallet'],
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public static getInstance(): NearXService {
|
|
23
|
+
if (!NearXService.instance) {
|
|
24
|
+
NearXService.instance = new NearXService();
|
|
25
|
+
}
|
|
26
|
+
return NearXService.instance;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async getBalance(address: string | undefined, xToken: XToken): Promise<bigint> {
|
|
30
|
+
const url = 'https://1rpc.io/near';
|
|
31
|
+
// reference: https://near.github.io/near-api-js/classes/_near-js_providers.json-rpc-provider.JsonRpcProvider.html
|
|
32
|
+
const provider = new JsonRpcProvider({ url });
|
|
33
|
+
|
|
34
|
+
// get native balance
|
|
35
|
+
if (xToken.symbol === 'NEAR') {
|
|
36
|
+
const account = await provider.viewAccount({ accountId: address ?? '' });
|
|
37
|
+
return BigInt(account.amount);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Near Fungible Token Standard(https://github.com/near/NEPs/blob/master/neps/nep-0141.md)
|
|
41
|
+
// get balance of the token
|
|
42
|
+
|
|
43
|
+
const res = await provider.callFunction<number>({ contractId: xToken.address, method: 'ft_balance_of', args: { account_id: address } });
|
|
44
|
+
return BigInt(res ?? 0);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useXService } from '@/hooks';
|
|
2
|
+
import { type UseQueryResult, useQuery } from '@tanstack/react-query';
|
|
3
|
+
|
|
4
|
+
import { NearXConnector } from './NearXConnector';
|
|
5
|
+
import type { NearXService } from './NearXService';
|
|
6
|
+
|
|
7
|
+
export const useNearXConnectors = (): UseQueryResult<NearXConnector[] | undefined, Error | null> => {
|
|
8
|
+
const xService = useXService('NEAR') as NearXService;
|
|
9
|
+
|
|
10
|
+
return useQuery({
|
|
11
|
+
queryKey: ['near-wallets'],
|
|
12
|
+
queryFn: async () => {
|
|
13
|
+
if (!xService) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
await xService.walletSelector.whenManifestLoaded;
|
|
18
|
+
const wallets = xService.walletSelector.availableWallets;
|
|
19
|
+
|
|
20
|
+
return wallets.map(wallet => new NearXConnector(wallet));
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -2,7 +2,15 @@ import type { XAccount } from '@/types';
|
|
|
2
2
|
|
|
3
3
|
import { XConnector } from '@/core';
|
|
4
4
|
import { StellarXService } from './StellarXService';
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
export type StellarWalletType = {
|
|
7
|
+
icon: string;
|
|
8
|
+
id: string;
|
|
9
|
+
isAvailable: boolean;
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
url: string;
|
|
13
|
+
};
|
|
6
14
|
|
|
7
15
|
export class StellarWalletsKitXConnector extends XConnector {
|
|
8
16
|
_wallet: StellarWalletType;
|
|
@@ -3,15 +3,6 @@ import { type UseQueryResult, useQuery } from '@tanstack/react-query';
|
|
|
3
3
|
|
|
4
4
|
import { StellarWalletsKitXConnector, type StellarXService } from '.';
|
|
5
5
|
|
|
6
|
-
export type StellarWalletType = {
|
|
7
|
-
icon: string;
|
|
8
|
-
id: string;
|
|
9
|
-
isAvailable: boolean;
|
|
10
|
-
name: string;
|
|
11
|
-
type: string;
|
|
12
|
-
url: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
6
|
export const useStellarXConnectors = (): UseQueryResult<StellarWalletsKitXConnector[] | undefined, Error | null> => {
|
|
16
7
|
const xService = useXService('STELLAR') as StellarXService;
|
|
17
8
|
|
|
@@ -22,7 +13,7 @@ export const useStellarXConnectors = (): UseQueryResult<StellarWalletsKitXConnec
|
|
|
22
13
|
return [];
|
|
23
14
|
}
|
|
24
15
|
|
|
25
|
-
const wallets
|
|
16
|
+
const wallets = await xService.walletsKit.getSupportedWallets();
|
|
26
17
|
|
|
27
18
|
return wallets.filter(wallet => wallet.isAvailable).map(wallet => new StellarWalletsKitXConnector(wallet));
|
|
28
19
|
},
|