@hot-labs/kit 1.0.57 → 1.1.0-beta.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/README.md +2 -9
- package/build/HotConnector.d.ts +6 -6
- package/build/HotConnector.js +18 -23
- package/build/HotConnector.js.map +1 -1
- package/build/OmniConnector.d.ts +4 -0
- package/build/OmniConnector.js +5 -5
- package/build/OmniConnector.js.map +1 -1
- package/build/OmniWallet.d.ts +10 -17
- package/build/OmniWallet.js +14 -19
- package/build/OmniWallet.js.map +1 -1
- package/build/core/Intents.d.ts +23 -39
- package/build/core/Intents.js +104 -115
- package/build/core/Intents.js.map +1 -1
- package/build/core/api.d.ts +1 -0
- package/build/core/api.js +10 -2
- package/build/core/api.js.map +1 -1
- package/build/core/bridge.js +1 -1
- package/build/core/bridge.js.map +1 -1
- package/build/core/index.d.ts +1 -1
- package/build/core/index.js +1 -1
- package/build/core/index.js.map +1 -1
- package/build/core/types.d.ts +17 -0
- package/build/core/utils.d.ts +1 -0
- package/build/core/utils.js +10 -0
- package/build/core/utils.js.map +1 -1
- package/build/cosmos/connector.js +2 -2
- package/build/cosmos/connector.js.map +1 -1
- package/build/cosmos/wallet.d.ts +2 -4
- package/build/cosmos/wallet.js +3 -8
- package/build/cosmos/wallet.js.map +1 -1
- package/build/evm/connector.d.ts +1 -0
- package/build/evm/connector.js +4 -0
- package/build/evm/connector.js.map +1 -1
- package/build/evm/wallet.d.ts +2 -1
- package/build/evm/wallet.js +7 -5
- package/build/evm/wallet.js.map +1 -1
- package/build/exchange.d.ts +4 -1
- package/build/exchange.js +21 -20
- package/build/exchange.js.map +1 -1
- package/build/hot-wallet/google.js +10 -5
- package/build/hot-wallet/google.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/near/connector.js +2 -2
- package/build/near/connector.js.map +1 -1
- package/build/{core/nearRpc.d.ts → near/rpc.d.ts} +0 -1
- package/build/{core/nearRpc.js → near/rpc.js} +5 -11
- package/build/near/rpc.js.map +1 -0
- package/build/near/wallet.d.ts +2 -4
- package/build/near/wallet.js +4 -9
- package/build/near/wallet.js.map +1 -1
- package/build/solana/{protocol.d.ts → WalletStandard.d.ts} +1 -1
- package/build/solana/{protocol.js → WalletStandard.js} +1 -1
- package/build/solana/WalletStandard.js.map +1 -0
- package/build/solana/connector.d.ts +1 -1
- package/build/solana/connector.js +9 -8
- package/build/solana/connector.js.map +1 -1
- package/build/solana/injected/solana-wallet.js.map +1 -1
- package/build/solana/wallet.d.ts +3 -5
- package/build/solana/wallet.js +3 -8
- package/build/solana/wallet.js.map +1 -1
- package/build/solana/{wallets.js → walletStandartList.js} +1 -1
- package/build/solana/walletStandartList.js.map +1 -0
- package/build/stellar/connector.d.ts +0 -2
- package/build/stellar/connector.js +1 -4
- package/build/stellar/connector.js.map +1 -1
- package/build/stellar/wallet.d.ts +10 -8
- package/build/stellar/wallet.js +12 -16
- package/build/stellar/wallet.js.map +1 -1
- package/build/ton/connector.d.ts +0 -1
- package/build/ton/connector.js +1 -4
- package/build/ton/connector.js.map +1 -1
- package/build/ton/wallet.d.ts +2 -3
- package/build/ton/wallet.js +3 -4
- package/build/ton/wallet.js.map +1 -1
- package/build/tron/connector.d.ts +51 -0
- package/build/tron/connector.js +65 -0
- package/build/tron/connector.js.map +1 -0
- package/build/tron/index.d.ts +6 -0
- package/build/tron/index.js +5 -0
- package/build/tron/index.js.map +1 -0
- package/build/tron/wallet.d.ts +52 -0
- package/build/tron/wallet.js +122 -0
- package/build/tron/wallet.js.map +1 -0
- package/build/ui/connect/AuthPopup.js +1 -1
- package/build/ui/connect/AuthPopup.js.map +1 -1
- package/build/ui/connect/ConnectWallet.d.ts +2 -1
- package/build/ui/connect/ConnectWallet.js +2 -2
- package/build/ui/connect/ConnectWallet.js.map +1 -1
- package/build/ui/icons/arrow-right.js +1 -1
- package/build/ui/icons/arrow-right.js.map +1 -1
- package/build/ui/icons/close.js +1 -1
- package/build/ui/icons/close.js.map +1 -1
- package/build/ui/icons/exchange.js +1 -1
- package/build/ui/icons/exchange.js.map +1 -1
- package/build/ui/icons/logout.js +1 -1
- package/build/ui/icons/logout.js.map +1 -1
- package/build/ui/icons/pending.js +1 -1
- package/build/ui/icons/pending.js.map +1 -1
- package/build/ui/icons/qr.js +1 -1
- package/build/ui/icons/qr.js.map +1 -1
- package/build/ui/icons/search.js +1 -1
- package/build/ui/icons/search.js.map +1 -1
- package/build/ui/icons/switch.js +1 -1
- package/build/ui/icons/switch.js.map +1 -1
- package/build/ui/icons/wallet.js +1 -1
- package/build/ui/icons/wallet.js.map +1 -1
- package/build/ui/payment/Bridge.js +7 -2
- package/build/ui/payment/Bridge.js.map +1 -1
- package/build/ui/payment/Payment.d.ts +16 -8
- package/build/ui/payment/Payment.js +117 -21
- package/build/ui/payment/Payment.js.map +1 -1
- package/build/ui/payment/Profile.js +1 -1
- package/build/ui/payment/Profile.js.map +1 -1
- package/build/ui/payment/SelectToken.js +1 -1
- package/build/ui/payment/SelectToken.js.map +1 -1
- package/build/ui/payment/TokenCard.js +1 -1
- package/build/ui/payment/TokenCard.js.map +1 -1
- package/build/ui/router.d.ts +2 -1
- package/build/ui/router.js +2 -2
- package/build/ui/router.js.map +1 -1
- package/package.json +8 -4
- package/src/HotConnector.ts +21 -29
- package/src/OmniConnector.ts +9 -9
- package/src/OmniWallet.ts +24 -25
- package/src/core/Intents.ts +123 -139
- package/src/core/api.ts +13 -2
- package/src/core/bridge.ts +3 -2
- package/src/core/index.ts +1 -1
- package/src/core/types.ts +21 -0
- package/src/core/utils.ts +11 -0
- package/src/cosmos/connector.ts +2 -2
- package/src/cosmos/wallet.ts +3 -7
- package/src/evm/connector.ts +5 -0
- package/src/evm/wallet.ts +9 -6
- package/src/exchange.ts +20 -20
- package/src/hot-wallet/google.ts +12 -5
- package/src/index.ts +2 -0
- package/src/near/connector.ts +2 -2
- package/src/{core/nearRpc.ts → near/rpc.ts} +4 -11
- package/src/near/wallet.ts +4 -9
- package/src/solana/{protocol.ts → WalletStandard.ts} +2 -4
- package/src/solana/connector.ts +9 -8
- package/src/solana/injected/solana-wallet.ts +6 -6
- package/src/solana/wallet.ts +4 -8
- package/src/stellar/connector.ts +1 -6
- package/src/stellar/wallet.ts +17 -17
- package/src/ton/connector.ts +1 -5
- package/src/ton/wallet.ts +3 -3
- package/src/tron/connector.ts +89 -0
- package/src/tron/index.ts +7 -0
- package/src/tron/wallet.ts +146 -0
- package/src/ui/connect/AuthPopup.tsx +2 -1
- package/src/ui/connect/ConnectWallet.tsx +3 -2
- package/src/ui/icons/arrow-right.tsx +2 -2
- package/src/ui/icons/close.tsx +1 -1
- package/src/ui/icons/exchange.tsx +4 -4
- package/src/ui/icons/logout.tsx +6 -6
- package/src/ui/icons/pending.tsx +2 -4
- package/src/ui/icons/qr.tsx +1 -2
- package/src/ui/icons/search.tsx +4 -4
- package/src/ui/icons/switch.tsx +4 -4
- package/src/ui/icons/wallet.tsx +2 -4
- package/src/ui/payment/Bridge.tsx +9 -2
- package/src/ui/payment/Payment.tsx +258 -30
- package/src/ui/payment/Profile.tsx +10 -8
- package/src/ui/payment/SelectToken.tsx +1 -1
- package/src/ui/payment/TokenCard.tsx +1 -1
- package/src/ui/router.tsx +5 -6
- package/build/core/nearRpc.js.map +0 -1
- package/build/solana/protocol.js.map +0 -1
- package/build/solana/wallets.js.map +0 -1
- /package/build/solana/{wallets.d.ts → walletStandartList.d.ts} +0 -0
- /package/src/solana/{wallets.ts → walletStandartList.ts} +0 -0
package/src/exchange.ts
CHANGED
|
@@ -300,7 +300,7 @@ export class Exchange {
|
|
|
300
300
|
};
|
|
301
301
|
}
|
|
302
302
|
|
|
303
|
-
async makeSwap(review: BridgeReview, pending: { log: (message: string) => void }) {
|
|
303
|
+
async makeSwap(review: BridgeReview, pending: { log: (message: string) => void }): Promise<{ review: BridgeReview; processing?: () => Promise<BridgeReview> }> {
|
|
304
304
|
const { sender, recipient } = review;
|
|
305
305
|
|
|
306
306
|
if (review.qoute === "withdraw") {
|
|
@@ -309,7 +309,7 @@ export class Exchange {
|
|
|
309
309
|
const recipientWallet = this.wibe3.wallets.find((w) => w.address === recipient.address);
|
|
310
310
|
if (recipientWallet) this.wibe3.fetchToken(review.to, recipientWallet);
|
|
311
311
|
this.wibe3.fetchToken(review.from, sender);
|
|
312
|
-
return review;
|
|
312
|
+
return { review };
|
|
313
313
|
}
|
|
314
314
|
|
|
315
315
|
if (review.qoute === "deposit") {
|
|
@@ -319,7 +319,7 @@ export class Exchange {
|
|
|
319
319
|
|
|
320
320
|
const recipientWallet = this.wibe3.wallets.find((w) => w.address === recipient.address);
|
|
321
321
|
if (recipientWallet) this.wibe3.fetchToken(review.to, recipientWallet);
|
|
322
|
-
return review;
|
|
322
|
+
return { review };
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
if (sender !== "qr") {
|
|
@@ -335,7 +335,8 @@ export class Exchange {
|
|
|
335
335
|
const depositAddress = review.qoute.depositAddress!;
|
|
336
336
|
let hash = "";
|
|
337
337
|
if (review.from.chain === Network.Hot) {
|
|
338
|
-
hash = await
|
|
338
|
+
hash = await this.wibe3
|
|
339
|
+
.intentsBuilder(sender)
|
|
339
340
|
.transfer({
|
|
340
341
|
amount: review.amountIn,
|
|
341
342
|
token: review.from.address as OmniToken,
|
|
@@ -347,31 +348,30 @@ export class Exchange {
|
|
|
347
348
|
receiver: depositAddress,
|
|
348
349
|
amount: review.amountIn,
|
|
349
350
|
comment: review.qoute.depositMemo,
|
|
350
|
-
token: review.from,
|
|
351
351
|
gasFee: review.fee ?? undefined,
|
|
352
|
+
token: review.from,
|
|
352
353
|
});
|
|
353
354
|
}
|
|
354
355
|
|
|
355
|
-
pending.log("Submitting tx");
|
|
356
356
|
this.wibe3.fetchToken(review.from, sender);
|
|
357
|
-
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (sender !== "qr") {
|
|
361
|
-
wait(1000).then(() => this.wibe3.fetchToken(review.to, sender));
|
|
357
|
+
OneClickService.submitDepositTx({ txHash: hash, depositAddress }).catch(() => {});
|
|
362
358
|
}
|
|
363
359
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
360
|
+
return {
|
|
361
|
+
review,
|
|
362
|
+
processing: async () => {
|
|
363
|
+
const recipientWallet = this.wibe3.wallets.find((w) => w.address === recipient.address);
|
|
364
|
+
if (!recipientWallet) return await this.processing(review);
|
|
367
365
|
|
|
368
|
-
|
|
369
|
-
|
|
366
|
+
const beforeBalance = await this.wibe3.fetchToken(review.to, recipientWallet).catch(() => null);
|
|
367
|
+
if (!beforeBalance) return await this.processing(review);
|
|
370
368
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
369
|
+
return await Promise.race([
|
|
370
|
+
this.waitBalance(review.to, recipientWallet, beforeBalance, review),
|
|
371
|
+
this.processing(review), //
|
|
372
|
+
]);
|
|
373
|
+
},
|
|
374
|
+
};
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
async waitBalance(to: Token, wallet: OmniWallet, beforeBalance: bigint, review: BridgeReview): Promise<BridgeReview> {
|
package/src/hot-wallet/google.ts
CHANGED
|
@@ -50,12 +50,19 @@ class GoogleConnector extends OmniConnector<OmniWallet> {
|
|
|
50
50
|
if (account.type === WalletType.STELLAR) {
|
|
51
51
|
const signMessage = async (message: string) => request("stellar:signMessage", { message });
|
|
52
52
|
const signTransaction = async (transaction: Transaction) => request("stellar:signTransaction", { transaction: transaction.toXDR() });
|
|
53
|
-
this.wallets.push(
|
|
53
|
+
this.wallets.push(
|
|
54
|
+
new StellarWallet({
|
|
55
|
+
rpc: this.wibe3.hotBridge.stellar,
|
|
56
|
+
address: account.address,
|
|
57
|
+
signMessage,
|
|
58
|
+
signTransaction,
|
|
59
|
+
})
|
|
60
|
+
);
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
if (account.type === WalletType.TON) {
|
|
57
64
|
this.setWallet(
|
|
58
|
-
new TonWallet(
|
|
65
|
+
new TonWallet({
|
|
59
66
|
sendTransaction: (params) => request("ton:sendTransaction", params),
|
|
60
67
|
signData: (params) => request("ton:signData", params),
|
|
61
68
|
account: { address: account.address, publicKey: account.publicKey },
|
|
@@ -65,21 +72,21 @@ class GoogleConnector extends OmniConnector<OmniWallet> {
|
|
|
65
72
|
|
|
66
73
|
if (account.type === WalletType.NEAR) {
|
|
67
74
|
this.setWallet(
|
|
68
|
-
new NearWallet(
|
|
75
|
+
new NearWallet(account.address, account.publicKey, {
|
|
69
76
|
signAndSendTransaction: (params: SignAndSendTransactionParams) => request("near:signAndSendTransaction", params),
|
|
70
77
|
signAndSendTransactions: (params: SignAndSendTransactionsParams) => request("near:signAndSendTransactions", params),
|
|
71
78
|
signMessage: (params: SignMessageParams) => request("near:signMessage", params),
|
|
72
79
|
getAccounts: async () => [{ accountId: account.address, publicKey: account.publicKey }],
|
|
73
80
|
signIn: () => request("near:signIn", {}),
|
|
74
|
-
signOut: async () => {},
|
|
75
81
|
manifest: {} as unknown as WalletManifest,
|
|
82
|
+
signOut: async () => {},
|
|
76
83
|
}) as NearWallet
|
|
77
84
|
);
|
|
78
85
|
}
|
|
79
86
|
|
|
80
87
|
if (account.type === WalletType.SOLANA) {
|
|
81
88
|
this.setWallet(
|
|
82
|
-
new SolanaWallet(
|
|
89
|
+
new SolanaWallet({
|
|
83
90
|
sendTransaction: async (transaction: unknown, _: unknown, options?: unknown) => await request("solana:sendTransaction", { transaction, options }),
|
|
84
91
|
signMessage: async (message: string) => await request("solana:signMessage", { message }),
|
|
85
92
|
disconnect: async () => {},
|
package/src/index.ts
CHANGED
package/src/near/connector.ts
CHANGED
|
@@ -28,7 +28,7 @@ class Connector extends OmniConnector<NearWallet> {
|
|
|
28
28
|
this.connector.on("wallet:signOut", () => this.removeWallet());
|
|
29
29
|
this.connector.getConnectedWallet().then(async ({ wallet }) => {
|
|
30
30
|
const [account] = await wallet.getAccounts();
|
|
31
|
-
if (account) this.setWallet(new NearWallet(
|
|
31
|
+
if (account) this.setWallet(new NearWallet(account.accountId, account.publicKey, wallet));
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
this.connector.whenManifestLoaded.then(() => {
|
|
@@ -49,7 +49,7 @@ class Connector extends OmniConnector<NearWallet> {
|
|
|
49
49
|
if (!wallet) throw new Error("Wallet not found");
|
|
50
50
|
const [account] = await wallet.getAccounts();
|
|
51
51
|
if (!account) throw new Error("No account found");
|
|
52
|
-
return this.setWallet(new NearWallet(
|
|
52
|
+
return this.setWallet(new NearWallet(account.accountId, account.publicKey, wallet));
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
async disconnect() {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { JsonRpcProvider } from "@near-js/providers";
|
|
2
2
|
import { getErrorTypeFromErrorMessage, parseRpcError } from "@near-js/utils";
|
|
3
3
|
import { TypedError, FinalExecutionOutcome } from "@near-js/types";
|
|
4
|
+
import { api } from "../core/api";
|
|
5
|
+
import { Network } from "../core";
|
|
4
6
|
|
|
5
7
|
let _nextId = 123;
|
|
6
8
|
|
|
@@ -22,22 +24,13 @@ const wait = (timeout: number) => {
|
|
|
22
24
|
return new Promise<void>((resolve) => setTimeout(resolve, timeout));
|
|
23
25
|
};
|
|
24
26
|
|
|
25
|
-
const c1 = Math.random() > 0.5;
|
|
26
|
-
export const rpcProviders = [
|
|
27
|
-
c1 ? "https://c1.rpc.fastnear.com" : "https://c2.rpc.fastnear.com",
|
|
28
|
-
c1 ? "https://c2.rpc.fastnear.com" : "https://c1.rpc.fastnear.com",
|
|
29
|
-
"https://relmn.aurora.dev",
|
|
30
|
-
"https://nearrpc.aurora.dev",
|
|
31
|
-
"https://archival-rpc.mainnet.near.org",
|
|
32
|
-
];
|
|
33
|
-
|
|
34
27
|
export class NearRpc extends JsonRpcProvider {
|
|
35
28
|
public providers: string[];
|
|
36
29
|
public currentProviderIndex = 0;
|
|
37
30
|
public startTimeout;
|
|
38
31
|
|
|
39
|
-
constructor(providers =
|
|
40
|
-
super({ url:
|
|
32
|
+
constructor(providers = [api.getRpcUrl(Network.Near)], private timeout = 30_000, private triesCountForEveryProvider = 3, private incrementTimout = true) {
|
|
33
|
+
super({ url: api.getRpcUrl(Network.Near) });
|
|
41
34
|
this.currentProviderIndex = 0;
|
|
42
35
|
this.providers = providers;
|
|
43
36
|
this.startTimeout = timeout;
|
package/src/near/wallet.ts
CHANGED
|
@@ -1,30 +1,25 @@
|
|
|
1
1
|
import { NearWalletBase, SignMessageParams, SignedMessage, SignAndSendTransactionParams } from "@hot-labs/near-connect";
|
|
2
2
|
import { base64, base58 } from "@scure/base";
|
|
3
3
|
|
|
4
|
-
import { OmniConnector } from "../OmniConnector";
|
|
5
4
|
import { OmniWallet } from "../OmniWallet";
|
|
6
5
|
import { WalletType } from "../core/chains";
|
|
7
6
|
import { ReviewFee } from "../core/bridge";
|
|
8
|
-
import { rpc, TGAS } from "
|
|
7
|
+
import { rpc, TGAS } from "./rpc";
|
|
9
8
|
import { Token } from "../core/token";
|
|
10
9
|
import { Commitment } from "../core";
|
|
11
10
|
|
|
12
11
|
export default class NearWallet extends OmniWallet {
|
|
12
|
+
readonly icon = "https://storage.herewallet.app/upload/73a44e583769f11112b0eff1f2dd2a560c05eed5f6d92f0c03484fa047c31668.png";
|
|
13
13
|
readonly type = WalletType.NEAR;
|
|
14
14
|
|
|
15
|
-
constructor(readonly
|
|
16
|
-
super(
|
|
15
|
+
constructor(readonly address: string, readonly publicKey?: string, readonly wallet?: NearWalletBase) {
|
|
16
|
+
super();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
get omniAddress() {
|
|
20
20
|
return this.address;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
async disconnect() {
|
|
24
|
-
await this.wallet?.signOut();
|
|
25
|
-
super.disconnect();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
23
|
async fetchBalances(_: number, whitelist: string[]): Promise<Record<string, bigint>> {
|
|
29
24
|
const balances = await Promise.all(
|
|
30
25
|
whitelist.map(async (token) => {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { Connection, Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
-
import { SolanaSignAndSendTransactionMethod, SolanaSignMessageMethod, SolanaSignTransactionMethod } from "@solana/wallet-standard-features";
|
|
3
2
|
import type { Wallet } from "@wallet-standard/base";
|
|
4
|
-
import { base58 } from "@scure/base";
|
|
5
3
|
|
|
6
4
|
export interface ISolanaProtocolWallet {
|
|
7
5
|
address: string;
|
|
@@ -41,7 +39,7 @@ class SolanaProtocolWallet implements ISolanaProtocolWallet {
|
|
|
41
39
|
async sendTransaction(transaction: Transaction | VersionedTransaction, connection: Connection, options?: any): Promise<string> {
|
|
42
40
|
const account = await this.getAccount();
|
|
43
41
|
const features = this.wallet.features as any;
|
|
44
|
-
const signTx = features["solana:signTransaction"]?.signTransaction
|
|
42
|
+
const signTx = features["solana:signTransaction"]?.signTransaction;
|
|
45
43
|
const [signed] = await signTx({ account, chain: account.chains[0], transaction: transaction.serialize() });
|
|
46
44
|
const signedTx = signed.signedTransaction as Transaction | VersionedTransaction | Uint8Array;
|
|
47
45
|
const raw = signedTx instanceof Uint8Array ? signedTx : (signedTx as any).serialize();
|
|
@@ -52,7 +50,7 @@ class SolanaProtocolWallet implements ISolanaProtocolWallet {
|
|
|
52
50
|
async signMessage(message: string) {
|
|
53
51
|
const account = await this.getAccount();
|
|
54
52
|
const features = this.wallet.features as any;
|
|
55
|
-
const signMessageFeature = features["solana:signMessage"]?.signMessage
|
|
53
|
+
const signMessageFeature = features["solana:signMessage"]?.signMessage;
|
|
56
54
|
|
|
57
55
|
if (!signMessageFeature) throw new Error("Wallet does not support solana:signMessage");
|
|
58
56
|
const [result] = await signMessageFeature({ account, message: new TextEncoder().encode(message) });
|
package/src/solana/connector.ts
CHANGED
|
@@ -9,8 +9,8 @@ import { OmniWallet } from "../OmniWallet";
|
|
|
9
9
|
import { WalletType } from "../core/chains";
|
|
10
10
|
import HOT from "../hot-wallet/iframe";
|
|
11
11
|
|
|
12
|
-
import SolanaProtocolWallet from "./
|
|
13
|
-
import { getWallets } from "./
|
|
12
|
+
import SolanaProtocolWallet from "./WalletStandard";
|
|
13
|
+
import { getWallets } from "./walletStandartList";
|
|
14
14
|
import SolanaWallet from "./wallet";
|
|
15
15
|
|
|
16
16
|
const wallets = getWallets();
|
|
@@ -36,7 +36,7 @@ class SolanaConnector extends OmniConnector<SolanaWallet, { wallet: Wallet }> {
|
|
|
36
36
|
const wallet = this.options.find((w) => w.id === id);
|
|
37
37
|
if (!wallet) return;
|
|
38
38
|
const protocolWallet = await SolanaProtocolWallet.connect(wallet.wallet, { silent: true });
|
|
39
|
-
this.setWallet(new SolanaWallet(
|
|
39
|
+
this.setWallet(new SolanaWallet(protocolWallet));
|
|
40
40
|
} catch {
|
|
41
41
|
this.removeStorage();
|
|
42
42
|
}
|
|
@@ -59,7 +59,7 @@ class SolanaConnector extends OmniConnector<SolanaWallet, { wallet: Wallet }> {
|
|
|
59
59
|
const connected = await this.getConnectedWallet();
|
|
60
60
|
if (connected !== wallet.name) return;
|
|
61
61
|
const protocolWallet = await SolanaProtocolWallet.connect(wallet, { silent: true });
|
|
62
|
-
this.setWallet(new SolanaWallet(
|
|
62
|
+
this.setWallet(new SolanaWallet(protocolWallet));
|
|
63
63
|
} catch {
|
|
64
64
|
this.removeStorage();
|
|
65
65
|
}
|
|
@@ -88,7 +88,7 @@ class SolanaConnector extends OmniConnector<SolanaWallet, { wallet: Wallet }> {
|
|
|
88
88
|
|
|
89
89
|
this.setStorage({ type: "walletconnect" });
|
|
90
90
|
return this.setWallet(
|
|
91
|
-
new SolanaWallet(
|
|
91
|
+
new SolanaWallet({
|
|
92
92
|
address: account,
|
|
93
93
|
sendTransaction: async (tx: Transaction | VersionedTransaction, connection: Connection, options?: any) => {
|
|
94
94
|
const transaction = Buffer.from(tx.serialize()).toString("base64");
|
|
@@ -112,8 +112,9 @@ class SolanaConnector extends OmniConnector<SolanaWallet, { wallet: Wallet }> {
|
|
|
112
112
|
);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
async
|
|
116
|
-
|
|
115
|
+
async disconnect() {
|
|
116
|
+
this.wallets.forEach((w) => w.wallet.disconnect?.());
|
|
117
|
+
super.disconnect();
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
async getConnectedWallet() {
|
|
@@ -142,7 +143,7 @@ class SolanaConnector extends OmniConnector<SolanaWallet, { wallet: Wallet }> {
|
|
|
142
143
|
try {
|
|
143
144
|
this.setStorage({ type: "wallet", id });
|
|
144
145
|
const protocolWallet = await SolanaProtocolWallet.connect(wallet.wallet, { silent: false });
|
|
145
|
-
return this.setWallet(new SolanaWallet(
|
|
146
|
+
return this.setWallet(new SolanaWallet(protocolWallet));
|
|
146
147
|
} catch (e) {
|
|
147
148
|
this.removeStorage();
|
|
148
149
|
throw e;
|
|
@@ -110,7 +110,7 @@ export class GhostWallet implements Wallet {
|
|
|
110
110
|
this._connected();
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
_on: StandardEventsOnMethod = (event, listener) => {
|
|
113
|
+
_on: StandardEventsOnMethod = (event: StandardEventsNames, listener: StandardEventsListeners[StandardEventsNames]) => {
|
|
114
114
|
this._listeners[event]?.push(listener) || (this._listeners[event] = [listener]);
|
|
115
115
|
return (): void => this._off(event, listener);
|
|
116
116
|
};
|
|
@@ -152,7 +152,7 @@ export class GhostWallet implements Wallet {
|
|
|
152
152
|
}
|
|
153
153
|
};
|
|
154
154
|
|
|
155
|
-
_connect: StandardConnectMethod = async ({ silent } = {}) => {
|
|
155
|
+
_connect: StandardConnectMethod = async ({ silent }: { silent?: boolean } = {}) => {
|
|
156
156
|
if (!this._account) await this._ghost.connect(silent ? { onlyIfTrusted: true } : undefined);
|
|
157
157
|
this._connected();
|
|
158
158
|
return { accounts: this.accounts };
|
|
@@ -162,7 +162,7 @@ export class GhostWallet implements Wallet {
|
|
|
162
162
|
await this._ghost.disconnect();
|
|
163
163
|
};
|
|
164
164
|
|
|
165
|
-
_signAndSendTransaction: SolanaSignAndSendTransactionMethod = async (...inputs) => {
|
|
165
|
+
_signAndSendTransaction: SolanaSignAndSendTransactionMethod = async (...inputs: any[]) => {
|
|
166
166
|
if (!this._account) throw new Error("not connected");
|
|
167
167
|
|
|
168
168
|
const outputs: SolanaSignAndSendTransactionOutput[] = [];
|
|
@@ -189,7 +189,7 @@ export class GhostWallet implements Wallet {
|
|
|
189
189
|
return outputs;
|
|
190
190
|
};
|
|
191
191
|
|
|
192
|
-
_signTransaction: SolanaSignTransactionMethod = async (...inputs) => {
|
|
192
|
+
_signTransaction: SolanaSignTransactionMethod = async (...inputs: any[]) => {
|
|
193
193
|
if (!this._account) throw new Error("not connected");
|
|
194
194
|
|
|
195
195
|
const outputs: SolanaSignTransactionOutput[] = [];
|
|
@@ -243,7 +243,7 @@ export class GhostWallet implements Wallet {
|
|
|
243
243
|
return outputs;
|
|
244
244
|
};
|
|
245
245
|
|
|
246
|
-
_signMessage: SolanaSignMessageMethod = async (...inputs) => {
|
|
246
|
+
_signMessage: SolanaSignMessageMethod = async (...inputs: any[]) => {
|
|
247
247
|
if (!this._account) throw new Error("not connected");
|
|
248
248
|
|
|
249
249
|
const outputs: SolanaSignMessageOutput[] = [];
|
|
@@ -264,7 +264,7 @@ export class GhostWallet implements Wallet {
|
|
|
264
264
|
return outputs;
|
|
265
265
|
};
|
|
266
266
|
|
|
267
|
-
_signIn: SolanaSignInMethod = async (...inputs) => {
|
|
267
|
+
_signIn: SolanaSignInMethod = async (...inputs: any[]) => {
|
|
268
268
|
const outputs: SolanaSignInOutput[] = [];
|
|
269
269
|
|
|
270
270
|
if (inputs.length > 1) {
|
package/src/solana/wallet.ts
CHANGED
|
@@ -23,13 +23,14 @@ import { ReviewFee } from "../core/bridge";
|
|
|
23
23
|
import { Commitment } from "../core";
|
|
24
24
|
import { api } from "../core/api";
|
|
25
25
|
|
|
26
|
-
import { ISolanaProtocolWallet } from "./
|
|
26
|
+
import { ISolanaProtocolWallet } from "./WalletStandard";
|
|
27
27
|
|
|
28
28
|
class SolanaWallet extends OmniWallet {
|
|
29
|
+
readonly icon = "https://storage.herewallet.app/upload/8700f33153ad813e133e5bf9b791b5ecbeea66edca6b8d17aeccb8048eb29ef7.png";
|
|
29
30
|
readonly type = WalletType.SOLANA;
|
|
30
31
|
|
|
31
|
-
constructor(readonly
|
|
32
|
-
super(
|
|
32
|
+
constructor(readonly wallet: ISolanaProtocolWallet) {
|
|
33
|
+
super();
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
getConnection() {
|
|
@@ -63,11 +64,6 @@ class SolanaWallet extends OmniWallet {
|
|
|
63
64
|
return BigInt(meta.value.amount);
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
async disconnect() {
|
|
67
|
-
await this.wallet.disconnect?.();
|
|
68
|
-
super.disconnect();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
67
|
async buildTranferInstructions(token: Token, amount: bigint, receiver: string, fee: ReviewFee) {
|
|
72
68
|
const destination = new PublicKey(receiver);
|
|
73
69
|
const owner = new PublicKey(this.address);
|
package/src/stellar/connector.ts
CHANGED
|
@@ -4,7 +4,6 @@ import HOT from "../hot-wallet/iframe";
|
|
|
4
4
|
import { WalletType } from "../core/chains";
|
|
5
5
|
import { HotConnector } from "../HotConnector";
|
|
6
6
|
import { ConnectorType, OmniConnector } from "../OmniConnector";
|
|
7
|
-
import { OmniWallet } from "../OmniWallet";
|
|
8
7
|
|
|
9
8
|
import { FreighterModule } from "./freigher";
|
|
10
9
|
import { HotWalletModule } from "./hotWallet";
|
|
@@ -45,10 +44,6 @@ class StellarConnector extends OmniConnector<StellarWallet> {
|
|
|
45
44
|
return Object.values(this.modules).find((module) => module.productId === id) || null;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
async createWallet(address: string): Promise<OmniWallet> {
|
|
49
|
-
return new StellarWallet(this, { address });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
47
|
async getConnectedWallet() {
|
|
53
48
|
if (HOT.isInjected) {
|
|
54
49
|
const { address } = await this.modules.hotWallet.getAddress();
|
|
@@ -61,7 +56,7 @@ class StellarConnector extends OmniConnector<StellarWallet> {
|
|
|
61
56
|
async selectWallet(address: string, wallet: HotWalletModule | FreighterModule) {
|
|
62
57
|
const signMessage = async (message: string) => wallet.signMessage(message);
|
|
63
58
|
const signTransaction = async (transaction: Transaction) => wallet.signTransaction(transaction.toXDR());
|
|
64
|
-
return this.setWallet(new StellarWallet(
|
|
59
|
+
return this.setWallet(new StellarWallet({ address, rpc: this.wibe3.hotBridge.stellar, signMessage, signTransaction }));
|
|
65
60
|
}
|
|
66
61
|
|
|
67
62
|
async connect(id: string) {
|
package/src/stellar/wallet.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { rpc } from "@stellar/stellar-sdk";
|
|
|
4
4
|
|
|
5
5
|
import { WalletType } from "../core/chains";
|
|
6
6
|
import { OmniWallet } from "../OmniWallet";
|
|
7
|
-
import { OmniConnector } from "../OmniConnector";
|
|
8
7
|
import { ReviewFee } from "../core/bridge";
|
|
9
8
|
import { formatter } from "../core/utils";
|
|
10
9
|
import { Network } from "../core/chains";
|
|
@@ -12,9 +11,13 @@ import { Token } from "../core/token";
|
|
|
12
11
|
import { Commitment } from "../core";
|
|
13
12
|
|
|
14
13
|
interface ProtocolWallet {
|
|
14
|
+
address: string;
|
|
15
15
|
signTransaction?: (transaction: Transaction) => Promise<{ signedTxXdr: string }>;
|
|
16
16
|
signMessage?: (message: string) => Promise<{ signedMessage: string }>;
|
|
17
|
-
|
|
17
|
+
rpc: {
|
|
18
|
+
callSoroban: (callback: (s: any) => Promise<any>) => Promise<any>;
|
|
19
|
+
callHorizon: (callback: (h: any) => Promise<any>) => Promise<any>;
|
|
20
|
+
};
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
export const ACCOUNT_FOR_SIMULATE = "GAAZI4TCR3TY5OJHCTJC2A4QSY6CJWJH5IAJTGKIN2ER7LBNVKOCCWN7";
|
|
@@ -28,14 +31,11 @@ export enum ASSET_CONTRACT_METHOD {
|
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
class StellarWallet extends OmniWallet {
|
|
34
|
+
readonly icon = "https://storage.herewallet.app/upload/1469894e53ca248ac6adceb2194e6950a13a52d972beb378a20bce7815ba01a4.png";
|
|
31
35
|
readonly type = WalletType.STELLAR;
|
|
32
36
|
|
|
33
|
-
constructor(readonly
|
|
34
|
-
super(
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get rpc() {
|
|
38
|
-
return this.connector.wibe3.hotBridge.stellar;
|
|
37
|
+
constructor(readonly wallet: ProtocolWallet) {
|
|
38
|
+
super();
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
get address() {
|
|
@@ -86,8 +86,8 @@ class StellarWallet extends OmniWallet {
|
|
|
86
86
|
const asset = await this.getAssetFromContractId(token);
|
|
87
87
|
const sendAmount = formatter.formatAmount(amount, 7);
|
|
88
88
|
|
|
89
|
-
const account = await this.
|
|
90
|
-
const baseFee = await this.
|
|
89
|
+
const account = await this.wallet.rpc.callSoroban((s) => s.getAccount(this.address));
|
|
90
|
+
const baseFee = await this.wallet.rpc.callHorizon((h) => h.fetchBaseFee()).catch(() => +BASE_FEE);
|
|
91
91
|
const builder = new TransactionBuilder(account, {
|
|
92
92
|
memo: memo ? Memo.text(memo) : undefined,
|
|
93
93
|
networkPassphrase: Networks.PUBLIC,
|
|
@@ -106,13 +106,13 @@ class StellarWallet extends OmniWallet {
|
|
|
106
106
|
)
|
|
107
107
|
);
|
|
108
108
|
|
|
109
|
-
const tx = await this.rpc.callSoroban((s) => s.prepareTransaction(builder.build() as any));
|
|
109
|
+
const tx = await this.wallet.rpc.callSoroban((s) => s.prepareTransaction(builder.build() as any));
|
|
110
110
|
const fee = BigInt(Math.floor(baseFee * tx.operations.length));
|
|
111
111
|
return { fee: new ReviewFee({ baseFee: fee, priorityFee: 0n, gasLimit: 1n, chain: Network.Stellar }), tx: tx as unknown as Transaction };
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
let needXlm = 0;
|
|
115
|
-
const receiverAccount = await this.rpc.callHorizon((h) => h.loadAccount(receiver)).catch(() => null);
|
|
115
|
+
const receiverAccount = await this.wallet.rpc.callHorizon((h) => h.loadAccount(receiver)).catch(() => null);
|
|
116
116
|
const claimableBalance = Operation.createClaimableBalance({ amount: amount.toString(), claimants: [new Claimant(receiver)], asset });
|
|
117
117
|
|
|
118
118
|
if (receiverAccount == null) {
|
|
@@ -154,7 +154,7 @@ class StellarWallet extends OmniWallet {
|
|
|
154
154
|
if (!this.wallet.signTransaction) throw "not impl";
|
|
155
155
|
const result = await this.wallet.signTransaction(transaction);
|
|
156
156
|
const txObject = new Transaction(result.signedTxXdr, Networks.PUBLIC);
|
|
157
|
-
const { hash } = await this.rpc.callHorizon((t) => t.submitTransaction(txObject as any));
|
|
157
|
+
const { hash } = await this.wallet.rpc.callHorizon((t) => t.submitTransaction(txObject as any));
|
|
158
158
|
return hash;
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -197,7 +197,7 @@ class StellarWallet extends OmniWallet {
|
|
|
197
197
|
async changeTrustline(address: string) {
|
|
198
198
|
if (address === "native") return;
|
|
199
199
|
const asset = await this.getAssetFromContractId(address);
|
|
200
|
-
const account = await this.rpc.callHorizon((h) => h.loadAccount(this.address));
|
|
200
|
+
const account = await this.wallet.rpc.callHorizon((h) => h.loadAccount(this.address));
|
|
201
201
|
const trustlineOp = Operation.changeTrust({ asset: asset, source: this.address });
|
|
202
202
|
const trustlineTx = new TransactionBuilder(account, { fee: BASE_FEE, networkPassphrase: Networks.PUBLIC }) //
|
|
203
203
|
.addOperation(trustlineOp)
|
|
@@ -215,7 +215,7 @@ class StellarWallet extends OmniWallet {
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
const tx = await this.buildSmartContactTx(ACCOUNT_FOR_SIMULATE, id, ASSET_CONTRACT_METHOD.NAME);
|
|
218
|
-
const result = (await this.rpc.callSoroban((s) => s.simulateTransaction(tx as any))) as unknown as rpc.Api.SimulateTransactionSuccessResponse;
|
|
218
|
+
const result = (await this.wallet.rpc.callSoroban((s) => s.simulateTransaction(tx as any))) as unknown as rpc.Api.SimulateTransactionSuccessResponse;
|
|
219
219
|
|
|
220
220
|
const value = result?.result?.retval?.value();
|
|
221
221
|
if (!value) throw "Asset not found";
|
|
@@ -227,7 +227,7 @@ class StellarWallet extends OmniWallet {
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
async buildSmartContactTx(publicKey: string, contactId: string, method: string, ...args: any[]) {
|
|
230
|
-
const account = await this.rpc.callSoroban((s) => s.getAccount(publicKey));
|
|
230
|
+
const account = await this.wallet.rpc.callSoroban((s) => s.getAccount(publicKey));
|
|
231
231
|
const contract = new Contract(contactId);
|
|
232
232
|
const builtTx = new TransactionBuilder(account, { fee: BASE_FEE, networkPassphrase: Networks.PUBLIC });
|
|
233
233
|
|
|
@@ -244,7 +244,7 @@ class StellarWallet extends OmniWallet {
|
|
|
244
244
|
Address.fromString(contract).toScVal()
|
|
245
245
|
);
|
|
246
246
|
|
|
247
|
-
const result = (await this.rpc.callSoroban((s) => s.simulateTransaction(tx as any))) as unknown as rpc.Api.SimulateTransactionSuccessResponse;
|
|
247
|
+
const result = (await this.wallet.rpc.callSoroban((s) => s.simulateTransaction(tx as any))) as unknown as rpc.Api.SimulateTransactionSuccessResponse;
|
|
248
248
|
if (result) return BigInt(this.i128ToInt(result.result?.retval.value() as xdr.Int128Parts));
|
|
249
249
|
return 0n;
|
|
250
250
|
}
|
package/src/ton/connector.ts
CHANGED
|
@@ -69,7 +69,7 @@ class TonConnector extends OmniConnector<TonWallet> {
|
|
|
69
69
|
tonConnect.onStatusChange(async (wallet) => {
|
|
70
70
|
if (!wallet) return this.removeWallet();
|
|
71
71
|
this.setWallet(
|
|
72
|
-
new TonWallet(
|
|
72
|
+
new TonWallet({
|
|
73
73
|
sendTransaction: (params) => tonConnect.sendTransaction(params),
|
|
74
74
|
signData: (params) => tonConnect.signData(params),
|
|
75
75
|
account: wallet.account,
|
|
@@ -108,10 +108,6 @@ class TonConnector extends OmniConnector<TonWallet> {
|
|
|
108
108
|
return tonConnect;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
async createWallet(address: string) {
|
|
112
|
-
return new TonWallet(this, { account: { address } });
|
|
113
|
-
}
|
|
114
|
-
|
|
115
111
|
async connect(id: string) {
|
|
116
112
|
const connector = await this.tonConnect;
|
|
117
113
|
connector.openSingleWalletModal(id);
|
package/src/ton/wallet.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { base58, base64, hex } from "@scure/base";
|
|
|
6
6
|
|
|
7
7
|
import { OmniWallet } from "../OmniWallet";
|
|
8
8
|
import { WalletType } from "../core/chains";
|
|
9
|
-
import { OmniConnector } from "../OmniConnector";
|
|
10
9
|
import { ReviewFee } from "../core/bridge";
|
|
11
10
|
import { Token } from "../core/token";
|
|
12
11
|
|
|
@@ -19,10 +18,11 @@ interface ProtocolWallet {
|
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
class TonWallet extends OmniWallet {
|
|
21
|
+
readonly icon = "https://storage.herewallet.app/upload/3ffa61e237f8e38d390abd60200db8edff3ec2b20aad0cc0a8c7a8ba9c318124.png";
|
|
22
22
|
readonly type = WalletType.TON;
|
|
23
23
|
|
|
24
|
-
constructor(readonly
|
|
25
|
-
super(
|
|
24
|
+
constructor(readonly wallet: ProtocolWallet) {
|
|
25
|
+
super();
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
get address() {
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { WalletType } from "../core/chains";
|
|
2
|
+
import { ConnectorType, OmniConnector } from "../OmniConnector";
|
|
3
|
+
import { HotConnector } from "../HotConnector";
|
|
4
|
+
import TronWallet from "./wallet";
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
tronLink?: {
|
|
9
|
+
ready?: boolean;
|
|
10
|
+
request?: (args: { method: string; params?: any }) => Promise<any>;
|
|
11
|
+
tronWeb?: {
|
|
12
|
+
defaultAddress?: { base58?: string; hex?: string };
|
|
13
|
+
address?: { toHex?: (address: string) => string };
|
|
14
|
+
contract?: () => { at: (address: string) => Promise<any> };
|
|
15
|
+
trx?: {
|
|
16
|
+
getBalance?: (address: string) => Promise<number | string>;
|
|
17
|
+
sendTransaction?: (to: string, amount: number | string) => Promise<any>;
|
|
18
|
+
signMessageV2?: (message: string) => Promise<string>;
|
|
19
|
+
signMessage?: (message: string) => Promise<string>;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const TRONLINK = {
|
|
27
|
+
id: "tronlink",
|
|
28
|
+
name: "Tron Link",
|
|
29
|
+
type: window?.tronLink ? ("extension" as const) : ("external" as const),
|
|
30
|
+
icon: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png",
|
|
31
|
+
download: "https://www.tronlink.org/",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
class TronConnector extends OmniConnector<TronWallet> {
|
|
35
|
+
type = ConnectorType.WALLET;
|
|
36
|
+
walletTypes = [WalletType.Tron, WalletType.OMNI];
|
|
37
|
+
icon = "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png";
|
|
38
|
+
name = "TRON Wallet";
|
|
39
|
+
options = [TRONLINK];
|
|
40
|
+
id = "tron";
|
|
41
|
+
|
|
42
|
+
constructor(wibe3: HotConnector) {
|
|
43
|
+
super(wibe3);
|
|
44
|
+
|
|
45
|
+
this.syncFromProvider().catch(() => this.removeStorage());
|
|
46
|
+
window.addEventListener("message", () => {
|
|
47
|
+
this.syncFromProvider().catch(() => {});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private async syncFromProvider() {
|
|
52
|
+
const stored = (await this.getStorage().catch(() => ({} as any))) as { type?: string; id?: string; address?: string };
|
|
53
|
+
if (stored.type !== "wallet" || stored.id !== TRONLINK.id) return;
|
|
54
|
+
|
|
55
|
+
const tronWeb = window?.tronLink?.tronWeb;
|
|
56
|
+
const address = tronWeb?.defaultAddress?.base58;
|
|
57
|
+
if (!window?.tronLink?.ready || !address) return;
|
|
58
|
+
|
|
59
|
+
const current = this.wallets[0]?.address;
|
|
60
|
+
if (current === address) return;
|
|
61
|
+
|
|
62
|
+
if (this.wallets.length > 0) this.removeWallet();
|
|
63
|
+
await this.setStorage({ type: "wallet", id: TRONLINK.id, address });
|
|
64
|
+
this.setWallet(new TronWallet(this, address, tronWeb as any));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async connect(id: string = TRONLINK.id) {
|
|
68
|
+
if (id !== TRONLINK.id) throw new Error("Wallet not found");
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
if (this.wallets.length > 0) this.removeWallet();
|
|
72
|
+
|
|
73
|
+
const res = await window?.tronLink?.request?.({ method: "tron_requestAccounts" });
|
|
74
|
+
if (res?.code !== 200) throw new Error("Failed to connect to TronLink");
|
|
75
|
+
if (!window?.tronLink?.tronWeb) throw new Error("TronLink not found");
|
|
76
|
+
|
|
77
|
+
const address = window?.tronLink?.tronWeb?.defaultAddress?.base58;
|
|
78
|
+
if (!address) throw new Error("No account found");
|
|
79
|
+
|
|
80
|
+
await this.setStorage({ type: "wallet", id: TRONLINK.id, address });
|
|
81
|
+
return this.setWallet(new TronWallet(this, address, window.tronLink.tronWeb));
|
|
82
|
+
} catch (e) {
|
|
83
|
+
await this.removeStorage();
|
|
84
|
+
throw e;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default TronConnector;
|