@sodax/wallet-sdk-react 0.0.1-rc.2
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/LICENSE +21 -0
- package/README.md +233 -0
- package/dist/index.cjs +1589 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +15970 -0
- package/dist/index.d.ts +15970 -0
- package/dist/index.mjs +1513 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +74 -0
- package/src/SodaxWalletProvider.tsx +55 -0
- package/src/actions/getXChainType.ts +10 -0
- package/src/actions/getXService.ts +25 -0
- package/src/actions/index.ts +2 -0
- package/src/assets/wallets/hana.svg +6 -0
- package/src/assets/wallets/havah.svg +76 -0
- package/src/assets/wallets/keplr.svg +30 -0
- package/src/assets/wallets/metamask.svg +60 -0
- package/src/assets/wallets/phantom.svg +4 -0
- package/src/assets/wallets/sui.svg +20 -0
- package/src/constants/index.ts +1 -0
- package/src/constants/xChains.ts +164 -0
- package/src/core/XConnector.ts +54 -0
- package/src/core/XService.ts +91 -0
- package/src/core/index.ts +2 -0
- package/src/hooks/index.ts +11 -0
- package/src/hooks/useEthereumChainId.ts +36 -0
- package/src/hooks/useEvmSwitchChain.ts +92 -0
- package/src/hooks/useWalletProvider.ts +149 -0
- package/src/hooks/useWalletProviderOptions.ts +51 -0
- package/src/hooks/useXAccount.ts +51 -0
- package/src/hooks/useXAccounts.ts +56 -0
- package/src/hooks/useXBalances.ts +66 -0
- package/src/hooks/useXConnect.ts +119 -0
- package/src/hooks/useXConnection.ts +72 -0
- package/src/hooks/useXConnectors.ts +56 -0
- package/src/hooks/useXDisconnect.ts +65 -0
- package/src/hooks/useXService.ts +8 -0
- package/src/index.ts +18 -0
- package/src/types/index.ts +44 -0
- package/src/useXWagmiStore.tsx +164 -0
- package/src/utils/index.ts +33 -0
- package/src/xchains/evm/EvmXConnector.ts +27 -0
- package/src/xchains/evm/EvmXService.ts +189 -0
- package/src/xchains/evm/index.ts +2 -0
- package/src/xchains/icon/IconHanaXConnector.ts +39 -0
- package/src/xchains/icon/IconXService.ts +115 -0
- package/src/xchains/icon/iconex/index.tsx +46 -0
- package/src/xchains/icon/index.ts +2 -0
- package/src/xchains/injective/InjectiveKelprXConnector.ts +37 -0
- package/src/xchains/injective/InjectiveMetamaskXConnector.ts +40 -0
- package/src/xchains/injective/InjectiveXService.ts +71 -0
- package/src/xchains/injective/index.ts +4 -0
- package/src/xchains/injective/utils.ts +17 -0
- package/src/xchains/solana/SolanaXConnector.ts +26 -0
- package/src/xchains/solana/SolanaXService.ts +50 -0
- package/src/xchains/solana/hooks/useAnchorProvider.tsx +9 -0
- package/src/xchains/solana/index.ts +2 -0
- package/src/xchains/stellar/CustomSorobanServer.ts +93 -0
- package/src/xchains/stellar/StellarWalletsKitXConnector.ts +45 -0
- package/src/xchains/stellar/StellarXService.ts +61 -0
- package/src/xchains/stellar/index.tsx +2 -0
- package/src/xchains/stellar/useStellarXConnectors.ts +30 -0
- package/src/xchains/stellar/utils.ts +49 -0
- package/src/xchains/sui/SuiXConnector.ts +28 -0
- package/src/xchains/sui/SuiXService.ts +56 -0
- package/src/xchains/sui/index.ts +2 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Address,
|
|
3
|
+
Contract,
|
|
4
|
+
type Memo,
|
|
5
|
+
type MemoType,
|
|
6
|
+
type Operation,
|
|
7
|
+
TimeoutInfinite,
|
|
8
|
+
type Transaction,
|
|
9
|
+
type TransactionBuilder,
|
|
10
|
+
scValToBigInt,
|
|
11
|
+
xdr,
|
|
12
|
+
} from '@stellar/stellar-sdk';
|
|
13
|
+
import type CustomSorobanServer from './CustomSorobanServer';
|
|
14
|
+
|
|
15
|
+
export const STELLAR_RLP_MSG_TYPE = { type: 'symbol' };
|
|
16
|
+
|
|
17
|
+
// Can be used whenever you need an Address argument for a contract method
|
|
18
|
+
export const accountToScVal = (account: string) => new Address(account).toScVal();
|
|
19
|
+
|
|
20
|
+
export const simulateTx = async (
|
|
21
|
+
tx: Transaction<Memo<MemoType>, Operation[]>,
|
|
22
|
+
server: CustomSorobanServer,
|
|
23
|
+
): Promise<any> => {
|
|
24
|
+
const response = await server.simulateTransaction(tx);
|
|
25
|
+
|
|
26
|
+
if (response !== undefined) {
|
|
27
|
+
return response;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
throw new Error('cannot simulate transaction');
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const getTokenBalance = async (
|
|
34
|
+
address: string,
|
|
35
|
+
tokenId: string,
|
|
36
|
+
txBuilder: TransactionBuilder,
|
|
37
|
+
server: CustomSorobanServer,
|
|
38
|
+
) => {
|
|
39
|
+
const params = [accountToScVal(address)];
|
|
40
|
+
const contract = new Contract(tokenId);
|
|
41
|
+
const tx = txBuilder
|
|
42
|
+
.addOperation(contract.call('balance', ...params))
|
|
43
|
+
.setTimeout(TimeoutInfinite)
|
|
44
|
+
.build();
|
|
45
|
+
|
|
46
|
+
const result = await simulateTx(tx, server);
|
|
47
|
+
|
|
48
|
+
return result.results ? scValToBigInt(xdr.ScVal.fromXDR(result.results[0].xdr, 'base64')) : 0n;
|
|
49
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { XAccount } from '@/types';
|
|
2
|
+
|
|
3
|
+
import { XConnector } from '@/core';
|
|
4
|
+
import { SuiXService } from './SuiXService';
|
|
5
|
+
|
|
6
|
+
export class SuiXConnector extends XConnector {
|
|
7
|
+
wallet: any;
|
|
8
|
+
|
|
9
|
+
constructor(wallet: any) {
|
|
10
|
+
// super('SUI', wallet.name, wallet.id);
|
|
11
|
+
super('SUI', wallet?.name, wallet?.name);
|
|
12
|
+
this.wallet = wallet;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getXService(): SuiXService {
|
|
16
|
+
return SuiXService.getInstance();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async connect(): Promise<XAccount | undefined> {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async disconnect(): Promise<void> {}
|
|
24
|
+
|
|
25
|
+
public get icon() {
|
|
26
|
+
return this.wallet?.icon;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { XService } from '@/core/XService';
|
|
2
|
+
import type { XToken } from '@sodax/types';
|
|
3
|
+
import { isNativeToken } from '@/utils';
|
|
4
|
+
|
|
5
|
+
export class SuiXService extends XService {
|
|
6
|
+
private static instance: SuiXService;
|
|
7
|
+
|
|
8
|
+
public suiClient: any; // TODO: define suiClient type
|
|
9
|
+
public suiWallet: any; // TODO: define suiWallet type
|
|
10
|
+
public suiAccount: any; // TODO: define suiAccount type
|
|
11
|
+
|
|
12
|
+
private constructor() {
|
|
13
|
+
super('SUI');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public static getInstance(): SuiXService {
|
|
17
|
+
if (!SuiXService.instance) {
|
|
18
|
+
SuiXService.instance = new SuiXService();
|
|
19
|
+
}
|
|
20
|
+
return SuiXService.instance;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// getBalance is not used because getBalances uses getAllBalances which returns all balances
|
|
24
|
+
|
|
25
|
+
async getBalances(address: string | undefined, xTokens: XToken[]) {
|
|
26
|
+
if (!address) return {};
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const allBalances = await this.suiClient.getAllBalances({
|
|
30
|
+
owner: address,
|
|
31
|
+
});
|
|
32
|
+
const tokenMap = xTokens.reduce((map, xToken) => {
|
|
33
|
+
let coinType = isNativeToken(xToken) ? '0x2::sui::SUI' : xToken.address;
|
|
34
|
+
|
|
35
|
+
// TODO: hard coded for getting legacy bnUSD balance
|
|
36
|
+
if (
|
|
37
|
+
coinType ===
|
|
38
|
+
'0x03917a812fe4a6d6bc779c5ab53f8a80ba741f8af04121193fc44e0f662e2ceb::balanced_dollar::BALANCED_DOLLAR'
|
|
39
|
+
) {
|
|
40
|
+
coinType =
|
|
41
|
+
'0x3917a812fe4a6d6bc779c5ab53f8a80ba741f8af04121193fc44e0f662e2ceb::balanced_dollar::BALANCED_DOLLAR';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const balance = allBalances.find(b => b.coinType === coinType);
|
|
45
|
+
|
|
46
|
+
if (balance) map[xToken.address] = balance.totalBalance;
|
|
47
|
+
return map;
|
|
48
|
+
}, {});
|
|
49
|
+
|
|
50
|
+
return tokenMap;
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.log('error', e);
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|