@hot-labs/kit 1.0.33
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/.eslintrc.cjs +11 -0
- package/.github/workflows/deploy-example.yml +55 -0
- package/.github/workflows/release.yml +74 -0
- package/.prettierrc +4 -0
- package/.prototools +2 -0
- package/.vscode/settings.json +3 -0
- package/CHANGELOG.md +1 -0
- package/README.md +67 -0
- package/build/GoogleConnector.d.ts +20 -0
- package/build/GoogleConnector.js +76 -0
- package/build/GoogleConnector.js.map +1 -0
- package/build/HotConnector.d.ts +91 -0
- package/build/HotConnector.js +285 -0
- package/build/HotConnector.js.map +1 -0
- package/build/OmniConnector.d.ts +95 -0
- package/build/OmniConnector.js +123 -0
- package/build/OmniConnector.js.map +1 -0
- package/build/OmniWallet.d.ts +57 -0
- package/build/OmniWallet.js +56 -0
- package/build/OmniWallet.js.map +1 -0
- package/build/cosmos/connector.d.ts +53 -0
- package/build/cosmos/connector.js +207 -0
- package/build/cosmos/connector.js.map +1 -0
- package/build/cosmos/wallet.d.ts +28 -0
- package/build/cosmos/wallet.js +59 -0
- package/build/cosmos/wallet.js.map +1 -0
- package/build/events.d.ts +42 -0
- package/build/events.js +64 -0
- package/build/events.js.map +1 -0
- package/build/evm/abi.d.ts +17 -0
- package/build/evm/abi.js +38 -0
- package/build/evm/abi.js.map +1 -0
- package/build/evm/connector.d.ts +35 -0
- package/build/evm/connector.js +124 -0
- package/build/evm/connector.js.map +1 -0
- package/build/evm/wallet.d.ts +47 -0
- package/build/evm/wallet.js +136 -0
- package/build/evm/wallet.js.map +1 -0
- package/build/exchange.d.ts +63 -0
- package/build/exchange.js +384 -0
- package/build/exchange.js.map +1 -0
- package/build/hot-wallet/evm.d.ts +1 -0
- package/build/hot-wallet/evm.js +33 -0
- package/build/hot-wallet/evm.js.map +1 -0
- package/build/hot-wallet/hot.d.ts +3 -0
- package/build/hot-wallet/hot.js +40 -0
- package/build/hot-wallet/hot.js.map +1 -0
- package/build/hot-wallet/index.d.ts +4 -0
- package/build/hot-wallet/index.js +5 -0
- package/build/hot-wallet/index.js.map +1 -0
- package/build/hot-wallet/solana/account.d.ts +11 -0
- package/build/hot-wallet/solana/account.js +42 -0
- package/build/hot-wallet/solana/account.js.map +1 -0
- package/build/hot-wallet/solana/index.d.ts +1 -0
- package/build/hot-wallet/solana/index.js +85 -0
- package/build/hot-wallet/solana/index.js.map +1 -0
- package/build/hot-wallet/solana/register.d.ts +2 -0
- package/build/hot-wallet/solana/register.js +41 -0
- package/build/hot-wallet/solana/register.js.map +1 -0
- package/build/hot-wallet/solana/solana-wallet.d.ts +34 -0
- package/build/hot-wallet/solana/solana-wallet.js +223 -0
- package/build/hot-wallet/solana/solana-wallet.js.map +1 -0
- package/build/hot-wallet/solana/utils.d.ts +32 -0
- package/build/hot-wallet/solana/utils.js +36 -0
- package/build/hot-wallet/solana/utils.js.map +1 -0
- package/build/hot-wallet/stellar.d.ts +38 -0
- package/build/hot-wallet/stellar.js +32 -0
- package/build/hot-wallet/stellar.js.map +1 -0
- package/build/hot-wallet/ton.d.ts +1 -0
- package/build/hot-wallet/ton.js +49 -0
- package/build/hot-wallet/ton.js.map +1 -0
- package/build/hot-wallet/wallet.d.ts +1 -0
- package/build/hot-wallet/wallet.js +40 -0
- package/build/hot-wallet/wallet.js.map +1 -0
- package/build/index.d.ts +24 -0
- package/build/index.js +25 -0
- package/build/index.js.map +1 -0
- package/build/near/connector.d.ts +28 -0
- package/build/near/connector.js +56 -0
- package/build/near/connector.js.map +1 -0
- package/build/near/wallet.d.ts +62 -0
- package/build/near/wallet.js +233 -0
- package/build/near/wallet.js.map +1 -0
- package/build/omni/Intents.d.ts +93 -0
- package/build/omni/Intents.js +395 -0
- package/build/omni/Intents.js.map +1 -0
- package/build/omni/bridge.d.ts +3 -0
- package/build/omni/bridge.js +34 -0
- package/build/omni/bridge.js.map +1 -0
- package/build/omni/config.d.ts +99 -0
- package/build/omni/config.js +126 -0
- package/build/omni/config.js.map +1 -0
- package/build/omni/defaultTokens.d.ts +17 -0
- package/build/omni/defaultTokens.js +1079 -0
- package/build/omni/defaultTokens.js.map +1 -0
- package/build/omni/index.d.ts +8 -0
- package/build/omni/index.js +9 -0
- package/build/omni/index.js.map +1 -0
- package/build/omni/nearRpc.d.ts +24 -0
- package/build/omni/nearRpc.js +167 -0
- package/build/omni/nearRpc.js.map +1 -0
- package/build/omni/recipient.d.ts +10 -0
- package/build/omni/recipient.js +40 -0
- package/build/omni/recipient.js.map +1 -0
- package/build/omni/token.d.ts +36 -0
- package/build/omni/token.js +136 -0
- package/build/omni/token.js.map +1 -0
- package/build/omni/tokens.d.ts +14 -0
- package/build/omni/tokens.js +57 -0
- package/build/omni/tokens.js.map +1 -0
- package/build/omni/types.d.ts +41 -0
- package/build/omni/types.js +2 -0
- package/build/omni/types.js.map +1 -0
- package/build/omni/utils.d.ts +24 -0
- package/build/omni/utils.js +150 -0
- package/build/omni/utils.js.map +1 -0
- package/build/settings.d.ts +5 -0
- package/build/settings.js +6 -0
- package/build/settings.js.map +1 -0
- package/build/solana/connector.d.ts +31 -0
- package/build/solana/connector.js +138 -0
- package/build/solana/connector.js.map +1 -0
- package/build/solana/protocol.d.ts +25 -0
- package/build/solana/protocol.js +56 -0
- package/build/solana/protocol.js.map +1 -0
- package/build/solana/wallet.d.ts +47 -0
- package/build/solana/wallet.js +188 -0
- package/build/solana/wallet.js.map +1 -0
- package/build/solana/wallets.d.ts +102 -0
- package/build/solana/wallets.js +150 -0
- package/build/solana/wallets.js.map +1 -0
- package/build/stellar/connector.d.ts +25 -0
- package/build/stellar/connector.js +56 -0
- package/build/stellar/connector.js.map +1 -0
- package/build/stellar/wallet.d.ts +70 -0
- package/build/stellar/wallet.js +225 -0
- package/build/stellar/wallet.js.map +1 -0
- package/build/storage.d.ts +10 -0
- package/build/storage.js +12 -0
- package/build/storage.js.map +1 -0
- package/build/ton/connector.d.ts +25 -0
- package/build/ton/connector.js +119 -0
- package/build/ton/connector.js.map +1 -0
- package/build/ton/utils.d.ts +45 -0
- package/build/ton/utils.js +64 -0
- package/build/ton/utils.js.map +1 -0
- package/build/ton/wallet.d.ts +70 -0
- package/build/ton/wallet.js +154 -0
- package/build/ton/wallet.js.map +1 -0
- package/build/ui/Popup.d.ts +10 -0
- package/build/ui/Popup.js +38 -0
- package/build/ui/Popup.js.map +1 -0
- package/build/ui/connect/AuthPopup.d.ts +2 -0
- package/build/ui/connect/AuthPopup.js +48 -0
- package/build/ui/connect/AuthPopup.js.map +1 -0
- package/build/ui/connect/ConnectWallet.d.ts +9 -0
- package/build/ui/connect/ConnectWallet.js +22 -0
- package/build/ui/connect/ConnectWallet.js.map +1 -0
- package/build/ui/connect/LogoutPopup.d.ts +10 -0
- package/build/ui/connect/LogoutPopup.js +8 -0
- package/build/ui/connect/LogoutPopup.js.map +1 -0
- package/build/ui/connect/WCPopup.d.ts +13 -0
- package/build/ui/connect/WCPopup.js +81 -0
- package/build/ui/connect/WCPopup.js.map +1 -0
- package/build/ui/connect/WCRequest.d.ts +9 -0
- package/build/ui/connect/WCRequest.js +13 -0
- package/build/ui/connect/WCRequest.js.map +1 -0
- package/build/ui/connect/WalletPicker.d.ts +11 -0
- package/build/ui/connect/WalletPicker.js +48 -0
- package/build/ui/connect/WalletPicker.js.map +1 -0
- package/build/ui/icons/arrow-right.d.ts +1 -0
- package/build/ui/icons/arrow-right.js +5 -0
- package/build/ui/icons/arrow-right.js.map +1 -0
- package/build/ui/icons/exchange.d.ts +6 -0
- package/build/ui/icons/exchange.js +6 -0
- package/build/ui/icons/exchange.js.map +1 -0
- package/build/ui/icons/logout.d.ts +1 -0
- package/build/ui/icons/logout.js +3 -0
- package/build/ui/icons/logout.js.map +1 -0
- package/build/ui/icons/pending.d.ts +1 -0
- package/build/ui/icons/pending.js +5 -0
- package/build/ui/icons/pending.js.map +1 -0
- package/build/ui/icons/qr.d.ts +1 -0
- package/build/ui/icons/qr.js +5 -0
- package/build/ui/icons/qr.js.map +1 -0
- package/build/ui/icons/search.d.ts +1 -0
- package/build/ui/icons/search.js +5 -0
- package/build/ui/icons/search.js.map +1 -0
- package/build/ui/icons/switch.d.ts +1 -0
- package/build/ui/icons/switch.js +5 -0
- package/build/ui/icons/switch.js.map +1 -0
- package/build/ui/icons/wallet.d.ts +1 -0
- package/build/ui/icons/wallet.js +5 -0
- package/build/ui/icons/wallet.js.map +1 -0
- package/build/ui/payment/Bridge.d.ts +27 -0
- package/build/ui/payment/Bridge.js +340 -0
- package/build/ui/payment/Bridge.js.map +1 -0
- package/build/ui/payment/DepositQR.d.ts +9 -0
- package/build/ui/payment/DepositQR.js +56 -0
- package/build/ui/payment/DepositQR.js.map +1 -0
- package/build/ui/payment/Payment.d.ts +16 -0
- package/build/ui/payment/Payment.js +50 -0
- package/build/ui/payment/Payment.js.map +1 -0
- package/build/ui/payment/Profile.d.ts +7 -0
- package/build/ui/payment/Profile.js +88 -0
- package/build/ui/payment/Profile.js.map +1 -0
- package/build/ui/payment/SelectRecipient.d.ts +14 -0
- package/build/ui/payment/SelectRecipient.js +68 -0
- package/build/ui/payment/SelectRecipient.js.map +1 -0
- package/build/ui/payment/SelectSender.d.ts +13 -0
- package/build/ui/payment/SelectSender.js +23 -0
- package/build/ui/payment/SelectSender.js.map +1 -0
- package/build/ui/payment/SelectToken.d.ts +13 -0
- package/build/ui/payment/SelectToken.js +92 -0
- package/build/ui/payment/SelectToken.js.map +1 -0
- package/build/ui/payment/TokenCard.d.ts +23 -0
- package/build/ui/payment/TokenCard.js +50 -0
- package/build/ui/payment/TokenCard.js.map +1 -0
- package/build/ui/router.d.ts +37 -0
- package/build/ui/router.js +56 -0
- package/build/ui/router.js.map +1 -0
- package/build/ui/styles.d.ts +11 -0
- package/build/ui/styles.js +273 -0
- package/build/ui/styles.js.map +1 -0
- package/package.json +60 -0
- package/skill.md +989 -0
- package/src/GoogleConnector.ts +102 -0
- package/src/HotConnector.ts +344 -0
- package/src/OmniConnector.ts +161 -0
- package/src/OmniWallet.ts +94 -0
- package/src/cosmos/connector.ts +242 -0
- package/src/cosmos/wallet.ts +77 -0
- package/src/events.ts +66 -0
- package/src/evm/abi.ts +39 -0
- package/src/evm/connector.ts +139 -0
- package/src/evm/wallet.ts +156 -0
- package/src/exchange.ts +426 -0
- package/src/hot-wallet/evm.ts +38 -0
- package/src/hot-wallet/hot.ts +39 -0
- package/src/hot-wallet/index.ts +4 -0
- package/src/hot-wallet/solana/account.ts +52 -0
- package/src/hot-wallet/solana/index.ts +98 -0
- package/src/hot-wallet/solana/register.ts +48 -0
- package/src/hot-wallet/solana/solana-wallet.ts +280 -0
- package/src/hot-wallet/solana/utils.ts +56 -0
- package/src/hot-wallet/stellar.ts +39 -0
- package/src/hot-wallet/ton.ts +56 -0
- package/src/hot-wallet/wallet.ts +44 -0
- package/src/index.ts +30 -0
- package/src/near/connector.ts +71 -0
- package/src/near/wallet.ts +255 -0
- package/src/omni/Intents.ts +454 -0
- package/src/omni/bridge.ts +38 -0
- package/src/omni/config.ts +130 -0
- package/src/omni/defaultTokens.ts +1078 -0
- package/src/omni/index.ts +8 -0
- package/src/omni/nearRpc.ts +187 -0
- package/src/omni/recipient.ts +41 -0
- package/src/omni/token.ts +125 -0
- package/src/omni/tokens.ts +68 -0
- package/src/omni/types.ts +46 -0
- package/src/omni/utils.ts +163 -0
- package/src/settings.ts +5 -0
- package/src/solana/connector.ts +151 -0
- package/src/solana/protocol.ts +66 -0
- package/src/solana/wallet.ts +230 -0
- package/src/solana/wallets.ts +243 -0
- package/src/stellar/connector.ts +69 -0
- package/src/stellar/wallet.ts +267 -0
- package/src/storage.ts +19 -0
- package/src/ton/connector.ts +138 -0
- package/src/ton/utils.ts +73 -0
- package/src/ton/wallet.ts +178 -0
- package/src/ui/Popup.tsx +62 -0
- package/src/ui/connect/AuthPopup.tsx +78 -0
- package/src/ui/connect/ConnectWallet.tsx +63 -0
- package/src/ui/connect/LogoutPopup.tsx +20 -0
- package/src/ui/connect/WCPopup.tsx +122 -0
- package/src/ui/connect/WCRequest.tsx +28 -0
- package/src/ui/connect/WalletPicker.tsx +92 -0
- package/src/ui/icons/arrow-right.tsx +8 -0
- package/src/ui/icons/exchange.tsx +17 -0
- package/src/ui/icons/logout.tsx +18 -0
- package/src/ui/icons/pending.tsx +18 -0
- package/src/ui/icons/qr.tsx +12 -0
- package/src/ui/icons/search.tsx +18 -0
- package/src/ui/icons/switch.tsx +10 -0
- package/src/ui/icons/wallet.tsx +18 -0
- package/src/ui/payment/Bridge.tsx +582 -0
- package/src/ui/payment/DepositQR.tsx +88 -0
- package/src/ui/payment/Payment.tsx +78 -0
- package/src/ui/payment/Profile.tsx +140 -0
- package/src/ui/payment/SelectRecipient.tsx +111 -0
- package/src/ui/payment/SelectSender.tsx +60 -0
- package/src/ui/payment/SelectToken.tsx +134 -0
- package/src/ui/payment/TokenCard.tsx +83 -0
- package/src/ui/router.tsx +92 -0
- package/src/ui/styles.ts +284 -0
- package/tsconfig.json +22 -0
- package/vite.config.ts +17 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { WalletManifest, SignAndSendTransactionParams, SignAndSendTransactionsParams, SignMessageParams } from "@hot-labs/near-connect";
|
|
2
|
+
import { Transaction } from "@stellar/stellar-base";
|
|
3
|
+
import { action, makeObservable } from "mobx";
|
|
4
|
+
|
|
5
|
+
import { requestWebWallet } from "./hot-wallet/wallet";
|
|
6
|
+
import { ConnectorType, OmniConnector } from "./OmniConnector";
|
|
7
|
+
import { OmniWallet } from "./OmniWallet";
|
|
8
|
+
import { WalletType } from "./omni/config";
|
|
9
|
+
|
|
10
|
+
import EvmWallet from "./evm/wallet";
|
|
11
|
+
import NearWallet from "./near/wallet";
|
|
12
|
+
import SolanaWallet from "./solana/wallet";
|
|
13
|
+
import TonWallet from "./ton/wallet";
|
|
14
|
+
import StellarWallet from "./stellar/wallet";
|
|
15
|
+
import { HotConnector } from "./HotConnector";
|
|
16
|
+
|
|
17
|
+
class GoogleConnector extends OmniConnector<OmniWallet> {
|
|
18
|
+
walletTypes = [WalletType.EVM, WalletType.STELLAR, WalletType.TON, WalletType.NEAR, WalletType.SOLANA];
|
|
19
|
+
icon = "https://storage.herewallet.app/upload/0eb073753bd1ddabc3ceb5611ad80dd0cb5ca5a9c6ed066bf89ec4f1364c809d.svg";
|
|
20
|
+
type = ConnectorType.SOCIAL;
|
|
21
|
+
name = "Google Wallet";
|
|
22
|
+
id = "google";
|
|
23
|
+
|
|
24
|
+
constructor(wibe3: HotConnector) {
|
|
25
|
+
super(wibe3);
|
|
26
|
+
|
|
27
|
+
makeObservable(this, {
|
|
28
|
+
connectWallet: action,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
this.getStorage().then((accounts: any) => {
|
|
32
|
+
accounts.forEach((account: any) => this.connectWallet(account));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
connectWallet(account: { type: number; address: string; publicKey: string }) {
|
|
37
|
+
const request = requestWebWallet(account.type, account.address);
|
|
38
|
+
|
|
39
|
+
if (account.type === WalletType.EVM) {
|
|
40
|
+
this.setWallet(
|
|
41
|
+
new EvmWallet(this, account.address, {
|
|
42
|
+
request: (args: any) => request("evm:request", args),
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (account.type === WalletType.STELLAR) {
|
|
48
|
+
const signMessage = async (message: string) => request("stellar:signMessage", { message });
|
|
49
|
+
const signTransaction = async (transaction: Transaction) => request("stellar:signTransaction", { transaction: transaction.toXDR() });
|
|
50
|
+
this.wallets.push(new StellarWallet(this, { address: account.address, signMessage, signTransaction }));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (account.type === WalletType.TON) {
|
|
54
|
+
this.setWallet(
|
|
55
|
+
new TonWallet(this, {
|
|
56
|
+
sendTransaction: (params) => request("ton:sendTransaction", params),
|
|
57
|
+
signData: (params) => request("ton:signData", params),
|
|
58
|
+
account: { address: account.address, publicKey: account.publicKey },
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (account.type === WalletType.NEAR) {
|
|
64
|
+
this.setWallet(
|
|
65
|
+
new NearWallet(this, account.address, account.publicKey, {
|
|
66
|
+
signAndSendTransaction: (params: SignAndSendTransactionParams) => request("near:signAndSendTransaction", params),
|
|
67
|
+
signAndSendTransactions: (params: SignAndSendTransactionsParams) => request("near:signAndSendTransactions", params),
|
|
68
|
+
signMessage: (params: SignMessageParams) => request("near:signMessage", params),
|
|
69
|
+
getAccounts: async () => [{ accountId: account.address, publicKey: account.publicKey }],
|
|
70
|
+
signIn: () => request("near:signIn", {}),
|
|
71
|
+
signOut: async () => {},
|
|
72
|
+
manifest: {} as unknown as WalletManifest,
|
|
73
|
+
}) as NearWallet
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (account.type === WalletType.SOLANA) {
|
|
78
|
+
this.setWallet(
|
|
79
|
+
new SolanaWallet(this, {
|
|
80
|
+
sendTransaction: async (transaction: unknown, _: unknown, options?: unknown) => await request("solana:sendTransaction", { transaction, options }),
|
|
81
|
+
signMessage: async (message: string) => await request("solana:signMessage", { message }),
|
|
82
|
+
disconnect: async () => {},
|
|
83
|
+
address: account.address,
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async connect() {
|
|
90
|
+
const accounts = await requestWebWallet()("connect:google", {});
|
|
91
|
+
accounts.forEach((account: { type: number; address: string; publicKey: string }) => this.connectWallet(account));
|
|
92
|
+
this.setStorage(accounts);
|
|
93
|
+
return this.wallets[0];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async silentDisconnect() {
|
|
97
|
+
this.removeAllWallets();
|
|
98
|
+
this.removeStorage();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export default GoogleConnector;
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { computed, makeObservable, observable, runInAction } from "mobx";
|
|
2
|
+
|
|
3
|
+
import { openBridge, openConnector, openPayment, openProfile, openWalletPicker } from "./ui/router";
|
|
4
|
+
import { ConnectorType, OmniConnector, OmniConnectorOptions } from "./OmniConnector";
|
|
5
|
+
import { chainsMap, Network, WalletType } from "./omni/config";
|
|
6
|
+
import { OmniWallet, SignedAuth } from "./OmniWallet";
|
|
7
|
+
|
|
8
|
+
import NearConnector, { NearConnectorOptions } from "./near/connector";
|
|
9
|
+
import EvmConnector, { EvmConnectorOptions } from "./evm/connector";
|
|
10
|
+
import CosmosConnector, { CosmosConnectorOptions } from "./cosmos/connector";
|
|
11
|
+
import TonConnector, { TonConnectorOptions } from "./ton/connector";
|
|
12
|
+
import SolanaConnector from "./solana/connector";
|
|
13
|
+
import StellarConnector from "./stellar/connector";
|
|
14
|
+
import GoogleConnector from "./GoogleConnector";
|
|
15
|
+
|
|
16
|
+
import { Exchange } from "./exchange";
|
|
17
|
+
import { OmniToken } from "./omni/config";
|
|
18
|
+
import { formatter } from "./omni/utils";
|
|
19
|
+
import { Token } from "./omni/token";
|
|
20
|
+
import { GlobalSettings } from "./settings";
|
|
21
|
+
import { EventEmitter } from "./events";
|
|
22
|
+
|
|
23
|
+
import NearWallet from "./near/wallet";
|
|
24
|
+
import EvmWallet from "./evm/wallet";
|
|
25
|
+
import SolanaWallet from "./solana/wallet";
|
|
26
|
+
import StellarWallet from "./stellar/wallet";
|
|
27
|
+
import TonWallet from "./ton/wallet";
|
|
28
|
+
import CosmosWallet from "./cosmos/wallet";
|
|
29
|
+
import { Intents } from "./omni/Intents";
|
|
30
|
+
import { Recipient } from "./omni/recipient";
|
|
31
|
+
import { openAuthPopup } from "./ui/connect/AuthPopup";
|
|
32
|
+
import { tokens } from "./omni/tokens";
|
|
33
|
+
|
|
34
|
+
export const near = (options?: NearConnectorOptions) => (wibe3: HotConnector) => new NearConnector(wibe3, options);
|
|
35
|
+
export const evm = (options?: EvmConnectorOptions) => (wibe3: HotConnector) => new EvmConnector(wibe3, options);
|
|
36
|
+
export const solana = (options?: OmniConnectorOptions) => (wibe3: HotConnector) => new SolanaConnector(wibe3, options);
|
|
37
|
+
export const cosmos = (options?: CosmosConnectorOptions) => (wibe3: HotConnector) => new CosmosConnector(wibe3, options);
|
|
38
|
+
export const ton = (options?: TonConnectorOptions) => (wibe3: HotConnector) => new TonConnector(wibe3, options);
|
|
39
|
+
export const stellar = () => (wibe3: HotConnector) => new StellarConnector(wibe3);
|
|
40
|
+
export const google = () => (wibe3: HotConnector) => new GoogleConnector(wibe3);
|
|
41
|
+
|
|
42
|
+
interface HotConnectorOptions extends EvmConnectorOptions, OmniConnectorOptions, TonConnectorOptions, NearConnectorOptions, CosmosConnectorOptions {
|
|
43
|
+
connectors?: OmniConnector[];
|
|
44
|
+
webWallet?: string;
|
|
45
|
+
tonApi?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class HotConnector {
|
|
49
|
+
public connectors: OmniConnector[] = [];
|
|
50
|
+
public balances: Record<string, Record<string, bigint>> = {};
|
|
51
|
+
public exchange = new Exchange(this);
|
|
52
|
+
|
|
53
|
+
private events = new EventEmitter<{
|
|
54
|
+
connect: { wallet: OmniWallet };
|
|
55
|
+
disconnect: { wallet: OmniWallet };
|
|
56
|
+
tokensUpdate: { tokens: Token[] };
|
|
57
|
+
}>();
|
|
58
|
+
|
|
59
|
+
constructor(options?: HotConnectorOptions) {
|
|
60
|
+
makeObservable(this, {
|
|
61
|
+
balances: observable,
|
|
62
|
+
walletsTokens: computed,
|
|
63
|
+
wallets: computed,
|
|
64
|
+
tokens: computed,
|
|
65
|
+
|
|
66
|
+
near: computed,
|
|
67
|
+
evm: computed,
|
|
68
|
+
solana: computed,
|
|
69
|
+
stellar: computed,
|
|
70
|
+
ton: computed,
|
|
71
|
+
cosmos: computed,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (typeof window !== "undefined") {
|
|
75
|
+
this.connectors = [near(), evm(options), solana(options), stellar(), ton(options), cosmos(options)].map((t) => t(this));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
GlobalSettings.webWallet = options?.webWallet ?? GlobalSettings.webWallet;
|
|
79
|
+
GlobalSettings.tonApi = options?.tonApi ?? GlobalSettings.tonApi;
|
|
80
|
+
|
|
81
|
+
this.connectors.forEach((t) => {
|
|
82
|
+
t.onConnect((payload) => this.events.emit("connect", payload));
|
|
83
|
+
t.onDisconnect((payload) => this.events.emit("disconnect", payload));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
this.onConnect((payload) => {
|
|
87
|
+
this.fetchTokens(payload.wallet);
|
|
88
|
+
this.fetchOmniTokens(payload.wallet);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
this.onDisconnect(({ wallet }) => {
|
|
92
|
+
if (!wallet) return;
|
|
93
|
+
runInAction(() => (this.balances[`${wallet.type}:${wallet.address}`] = {}));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
setOmniChainBranding(branding: { name: string; icon: string }) {
|
|
98
|
+
chainsMap[Network.Hot].name = branding.name;
|
|
99
|
+
chainsMap[Network.Hot].logo = branding.icon;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
getWalletConnector(type: WalletType): OmniConnector | null {
|
|
103
|
+
return this.connectors.find((t) => t.type === ConnectorType.WALLET && t.walletTypes.includes(type)) ?? null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
omni(token: OmniToken) {
|
|
107
|
+
return tokens.get(token);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
get tokens() {
|
|
111
|
+
return tokens.list;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
get priorityWallet() {
|
|
115
|
+
if (this.near) return this.near;
|
|
116
|
+
if (this.evm) return this.evm;
|
|
117
|
+
if (this.solana) return this.solana;
|
|
118
|
+
if (this.ton) return this.ton;
|
|
119
|
+
if (this.stellar) return this.stellar;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
get wallets(): OmniWallet[] {
|
|
123
|
+
return this.connectors.flatMap((t) => t.wallets);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get walletsTokens() {
|
|
127
|
+
return this.wallets
|
|
128
|
+
.flatMap((wallet) => {
|
|
129
|
+
return tokens.list.map((token) => ({ token, wallet, balance: this.balance(wallet, token) }));
|
|
130
|
+
})
|
|
131
|
+
.filter((t) => t.balance !== 0n)
|
|
132
|
+
.sort((a, b) => {
|
|
133
|
+
const balanceA = a.token.float(a.balance) * a.token.usd;
|
|
134
|
+
const balanceB = b.token.float(b.balance) * b.token.usd;
|
|
135
|
+
return balanceB - balanceA;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
get near(): NearWallet | null {
|
|
140
|
+
return this.wallets.find((w) => w.type === WalletType.NEAR) as NearWallet | null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
get evm(): EvmWallet | null {
|
|
144
|
+
return this.wallets.find((w) => w.type === WalletType.EVM) as EvmWallet | null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
get solana(): SolanaWallet | null {
|
|
148
|
+
return this.wallets.find((w) => w.type === WalletType.SOLANA) as SolanaWallet | null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
get stellar(): StellarWallet | null {
|
|
152
|
+
return this.wallets.find((w) => w.type === WalletType.STELLAR) as StellarWallet | null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
get ton(): TonWallet | null {
|
|
156
|
+
return this.wallets.find((w) => w.type === WalletType.TON) as TonWallet | null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
get cosmos(): CosmosWallet | null {
|
|
160
|
+
return this.wallets.find((w) => w.type === WalletType.COSMOS) as CosmosWallet | null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
getChainBalances(chain: number) {
|
|
164
|
+
return tokens.list
|
|
165
|
+
.filter((t) => t.chain === chain)
|
|
166
|
+
.reduce((acc: number, token: Token) => {
|
|
167
|
+
return this.wallets.reduce((acc: number, wallet) => {
|
|
168
|
+
if (token.chain === chain) return acc;
|
|
169
|
+
const balance = this.balances[`${wallet.type}:${wallet.address}`][token.id] ?? 0n;
|
|
170
|
+
return acc + token.float(balance) * token.usd;
|
|
171
|
+
}, acc);
|
|
172
|
+
}, 0);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
balance(wallet?: OmniWallet, token?: Token) {
|
|
176
|
+
if (!wallet || !token) return 0n;
|
|
177
|
+
return this.balances[`${wallet.type}:${wallet.address}`]?.[token.id] ?? 0n;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
omniBalance(token: OmniToken) {
|
|
181
|
+
const omni = tokens.get(token);
|
|
182
|
+
const omniToken = this.walletsTokens.find((t) => t.token.address === omni.address);
|
|
183
|
+
const onchainToken = this.walletsTokens.find((t) => t.token.address === omni.originalAddress);
|
|
184
|
+
|
|
185
|
+
const reseve = onchainToken ? onchainToken.token.int(onchainToken.token.reserve) : 0n;
|
|
186
|
+
const available = onchainToken ? formatter.bigIntMax(0n, onchainToken.balance - reseve) : 0n;
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
token: omni,
|
|
190
|
+
onchain: available,
|
|
191
|
+
omni: omniToken?.balance ?? 0n,
|
|
192
|
+
total: +omni.float((omniToken?.balance ?? 0n) + available).toFixed(6),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async auth<T = SignedAuth>(wallet: OmniWallet, domain: string, intents?: Record<string, any>[], then?: (signed: SignedAuth) => Promise<T>): Promise<T> {
|
|
197
|
+
return openAuthPopup<T>(wallet, async () => {
|
|
198
|
+
const signed = await wallet.signIntentsWithAuth(domain, intents);
|
|
199
|
+
return (await then?.(signed)) ?? (signed as T);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async fetchToken(token: Token, wallet: OmniWallet) {
|
|
204
|
+
const key = `${wallet.type}:${wallet.address}`;
|
|
205
|
+
|
|
206
|
+
if (token.type === WalletType.OMNI) {
|
|
207
|
+
if (!wallet.omniAddress) return 0n;
|
|
208
|
+
const balances = await Intents.getIntentsBalances([token.address], wallet.omniAddress);
|
|
209
|
+
runInAction(() => (this.balances[key][token.id] = balances[token.address]));
|
|
210
|
+
return balances[token.address] ?? 0n;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (token.type === wallet.type) {
|
|
214
|
+
const balance = await wallet.fetchBalance(token.chain, token.address);
|
|
215
|
+
runInAction(() => (this.balances[key][token.id] = balance));
|
|
216
|
+
return balance;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return 0n;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
async fetchOmniTokens(wallet: OmniWallet) {
|
|
223
|
+
const key = `${wallet.type}:${wallet.address}`;
|
|
224
|
+
const assets = await wallet.getAssets();
|
|
225
|
+
runInAction(() => {
|
|
226
|
+
Object.keys(assets).forEach((id) => {
|
|
227
|
+
this.balances[key][`-4:${id}`] = assets[id];
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async fetchTokens(wallet: OmniWallet) {
|
|
233
|
+
const key = `${wallet.type}:${wallet.address}`;
|
|
234
|
+
if (!this.balances[key]) runInAction(() => (this.balances[key] = {}));
|
|
235
|
+
const tokensList = (await tokens.getTokens()).filter((t) => t.type === wallet.type && t.type !== WalletType.OMNI);
|
|
236
|
+
|
|
237
|
+
// Group tokens by their chain
|
|
238
|
+
const groups: Record<number, string[]> = tokensList.reduce((acc, token) => {
|
|
239
|
+
if (!acc[token.chain]) acc[token.chain] = [];
|
|
240
|
+
acc[token.chain].push(token.address);
|
|
241
|
+
return acc;
|
|
242
|
+
}, {} as Record<number, string[]>);
|
|
243
|
+
|
|
244
|
+
Object.entries(groups).forEach(async ([chain, tokens]) => {
|
|
245
|
+
const balances = await wallet.fetchBalances(+chain, tokens);
|
|
246
|
+
runInAction(() => {
|
|
247
|
+
for (const [token, balance] of Object.entries(balances)) {
|
|
248
|
+
this.balances[key][`${chain}:${token}`] = balance;
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async requestToken(token: OmniToken, amount: bigint | number): Promise<{ wallet: OmniWallet; token: Token; amount: bigint }> {
|
|
255
|
+
if (!token) throw new Error("Token not found");
|
|
256
|
+
|
|
257
|
+
const tokensList = await tokens.getTokens();
|
|
258
|
+
const ftToken = tokensList.find((t) => t.address === token)!;
|
|
259
|
+
const amountInt = typeof amount === "number" ? ftToken.int(amount) : amount;
|
|
260
|
+
const [existed] = this.walletsTokens.filter((t) => t.token.id === ftToken.id);
|
|
261
|
+
|
|
262
|
+
if (existed?.balance >= amountInt) return { token: ftToken, wallet: existed.wallet, amount: amountInt };
|
|
263
|
+
|
|
264
|
+
const needed = amountInt - (existed?.balance ?? 0n);
|
|
265
|
+
const result = await openPayment(this, ftToken, needed, Recipient.fromWallet(existed?.wallet));
|
|
266
|
+
|
|
267
|
+
const recipientWallet = this.wallets.find((w) => w.address === result.recipient.address);
|
|
268
|
+
if (!recipientWallet) throw new Error("Recipient not found");
|
|
269
|
+
const exist = await this.fetchToken(ftToken, recipientWallet);
|
|
270
|
+
|
|
271
|
+
return {
|
|
272
|
+
token: result.to,
|
|
273
|
+
wallet: recipientWallet,
|
|
274
|
+
amount: formatter.bigIntMin(exist, amountInt),
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
onConnect(handler: (payload: { wallet: OmniWallet }) => void) {
|
|
279
|
+
this.events.on("connect", handler);
|
|
280
|
+
return () => this.events.off("connect", handler);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
onDisconnect(handler: (payload: { wallet: OmniWallet }) => void) {
|
|
284
|
+
this.events.on("disconnect", handler);
|
|
285
|
+
return () => this.events.off("disconnect", handler);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async withdraw(token: OmniToken, amount: number, settings?: { title?: string; sender?: OmniWallet }) {
|
|
289
|
+
const tokensList = await tokens.getTokens();
|
|
290
|
+
const omniToken = tokensList.find((t) => t.address === token)!;
|
|
291
|
+
const originalToken = tokensList.find((t) => t.chain === omniToken.originalChain && t.address === omniToken.originalAddress)!;
|
|
292
|
+
const recipient = Recipient.fromWallet(this.wallets.find((w) => w.type === originalToken.type));
|
|
293
|
+
|
|
294
|
+
const sender =
|
|
295
|
+
settings?.sender ||
|
|
296
|
+
this.wallets.sort((a, b) => {
|
|
297
|
+
const aBalance = omniToken.float(this.balance(a, omniToken));
|
|
298
|
+
const bBalance = omniToken.float(this.balance(b, omniToken));
|
|
299
|
+
return bBalance - aBalance;
|
|
300
|
+
})[0];
|
|
301
|
+
|
|
302
|
+
return openBridge(this, {
|
|
303
|
+
// title: settings?.title,
|
|
304
|
+
sender: sender,
|
|
305
|
+
recipient: recipient,
|
|
306
|
+
to: originalToken,
|
|
307
|
+
from: omniToken,
|
|
308
|
+
amount: amount,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async deposit(token: OmniToken, amount: number, settings?: { title?: string }) {
|
|
313
|
+
const tokensList = await tokens.getTokens();
|
|
314
|
+
const omni = tokensList.find((t) => t.address === token)!;
|
|
315
|
+
const orig = tokensList.find((t) => t.chain === omni.originalChain && t.address === omni.originalAddress)!;
|
|
316
|
+
const sender = this.wallets.find((t) => t.type === orig.type)!;
|
|
317
|
+
const recipient = Recipient.fromWallet(this.wallets.find((w) => !!w.omniAddress));
|
|
318
|
+
|
|
319
|
+
return openBridge(this, {
|
|
320
|
+
sender: sender,
|
|
321
|
+
type: "exactOut",
|
|
322
|
+
readonlyAmount: true,
|
|
323
|
+
readonlyTo: true,
|
|
324
|
+
title: settings?.title,
|
|
325
|
+
recipient: recipient,
|
|
326
|
+
amount: amount,
|
|
327
|
+
from: orig,
|
|
328
|
+
to: omni,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
async openBridge() {
|
|
333
|
+
await openBridge(this);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
async connect(type?: WalletType) {
|
|
337
|
+
if (this.wallets.length > 0) return openProfile(this);
|
|
338
|
+
if (!type) return openConnector(this);
|
|
339
|
+
|
|
340
|
+
const connector = this.connectors.find((t) => t.type === ConnectorType.WALLET && t.walletTypes.includes(type));
|
|
341
|
+
if (!connector) throw new Error("Connector not found");
|
|
342
|
+
return openWalletPicker(connector);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { makeObservable, observable, runInAction } from "mobx";
|
|
2
|
+
import UniversalProvider, { NamespaceConfig } from "@walletconnect/universal-provider";
|
|
3
|
+
|
|
4
|
+
import { EventEmitter } from "./events";
|
|
5
|
+
import { LocalStorage } from "./storage";
|
|
6
|
+
import { HotConnector } from "./HotConnector";
|
|
7
|
+
|
|
8
|
+
import { OmniWallet } from "./OmniWallet";
|
|
9
|
+
import { WalletType } from "./omni/config";
|
|
10
|
+
import { openWCRequest } from "./ui/router";
|
|
11
|
+
|
|
12
|
+
export enum ConnectorType {
|
|
13
|
+
WALLET = "wallet",
|
|
14
|
+
SOCIAL = "social",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface OmniConnectorOption {
|
|
18
|
+
name: string;
|
|
19
|
+
icon: string;
|
|
20
|
+
id: string;
|
|
21
|
+
download?: string;
|
|
22
|
+
type: "extension" | "external";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface OmniConnectorOptions {
|
|
26
|
+
projectId?: string;
|
|
27
|
+
metadata?: { name: string; description: string; url: string; icons: string[] };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const WC_ICON = "https://raw.githubusercontent.com/WalletConnect/walletconnect-assets/refs/heads/master/Icon/Blue%20(Default)/Icon.svg";
|
|
31
|
+
|
|
32
|
+
export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
|
|
33
|
+
wallets: T[] = [];
|
|
34
|
+
options: (O & OmniConnectorOption)[] = [];
|
|
35
|
+
|
|
36
|
+
private storage = new LocalStorage();
|
|
37
|
+
protected events = new EventEmitter<{
|
|
38
|
+
connect: { wallet: T };
|
|
39
|
+
disconnect: { wallet: T };
|
|
40
|
+
}>();
|
|
41
|
+
|
|
42
|
+
protected wc: Promise<UniversalProvider> | null = null;
|
|
43
|
+
|
|
44
|
+
constructor(readonly wibe3: HotConnector, readonly settings?: OmniConnectorOptions) {
|
|
45
|
+
makeObservable(this, {
|
|
46
|
+
wallets: observable,
|
|
47
|
+
options: observable,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async initWalletConnect() {
|
|
52
|
+
if (!this.settings?.projectId) throw new Error("Project ID is required");
|
|
53
|
+
if (this.wc) return this.wc;
|
|
54
|
+
this.wc = UniversalProvider.init({
|
|
55
|
+
relayUrl: "wss://relay.walletconnect.org",
|
|
56
|
+
projectId: this.settings?.projectId,
|
|
57
|
+
metadata: this.settings?.metadata,
|
|
58
|
+
customStoragePrefix: `wibe3:${this.id}`,
|
|
59
|
+
name: this.name,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return this.wc;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async connectWalletConnect(args: { deeplink?: string; onConnect: () => Promise<OmniWallet>; namespaces: NamespaceConfig }): Promise<{ qrcode: string; deeplink?: string; task: Promise<OmniWallet> }> {
|
|
66
|
+
const provider = await this.wc;
|
|
67
|
+
if (!provider) throw new Error("No provider found");
|
|
68
|
+
|
|
69
|
+
return new Promise((resolve) => {
|
|
70
|
+
const session = provider.connect({ namespaces: args.namespaces });
|
|
71
|
+
const handler = (uri: string) => {
|
|
72
|
+
provider.off("display_uri", handler);
|
|
73
|
+
resolve({ qrcode: uri, deeplink: `${args.deeplink || "wc://"}${encodeURIComponent(uri)}`, task: session.then(args.onConnect) });
|
|
74
|
+
};
|
|
75
|
+
provider.on("display_uri", handler);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async disconnectWalletConnect() {
|
|
80
|
+
const provider = await this.wc;
|
|
81
|
+
if (provider?.session) await provider.disconnect();
|
|
82
|
+
provider?.cleanupPendingPairings();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async requestWalletConnect<T>(args: { chain?: string; request: any; deeplink?: string; name?: string; icon?: string }): Promise<T> {
|
|
86
|
+
return openWCRequest<T>({
|
|
87
|
+
deeplink: args.deeplink,
|
|
88
|
+
name: args.name || "WalletConnect",
|
|
89
|
+
icon: args.icon || WC_ICON,
|
|
90
|
+
request: args.request,
|
|
91
|
+
task: async () => {
|
|
92
|
+
const wc = await this.wc;
|
|
93
|
+
if (!wc) throw new Error("No provider found");
|
|
94
|
+
return await wc.request<T>(args.request, args.chain);
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
abstract connect(id?: string): Promise<OmniWallet | { qrcode: string; deeplink?: string; task: Promise<OmniWallet> }>;
|
|
100
|
+
|
|
101
|
+
abstract walletTypes: WalletType[];
|
|
102
|
+
abstract type: ConnectorType;
|
|
103
|
+
abstract name: string;
|
|
104
|
+
abstract icon: string;
|
|
105
|
+
abstract id: string;
|
|
106
|
+
|
|
107
|
+
protected setWallet(wallet: T) {
|
|
108
|
+
runInAction(() => this.wallets.push(wallet));
|
|
109
|
+
this.events.emit("connect", { wallet });
|
|
110
|
+
return wallet;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
protected removeWallet() {
|
|
114
|
+
runInAction(() => {
|
|
115
|
+
const wallet = this.wallets.pop();
|
|
116
|
+
if (wallet) this.events.emit("disconnect", { wallet });
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
protected removeAllWallets(): void {
|
|
121
|
+
runInAction(() => {
|
|
122
|
+
const wallets = this.wallets;
|
|
123
|
+
this.wallets = [];
|
|
124
|
+
wallets.forEach((wallet) => this.events.emit("disconnect", { wallet }));
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async setStorage(obj: { type?: string; id?: string; address?: string; publicKey?: string }) {
|
|
129
|
+
await this.storage.set(`wibe3:${this.id}`, JSON.stringify(obj));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async removeStorage() {
|
|
133
|
+
await this.storage.remove(`wibe3:${this.id}`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async getStorage(): Promise<{ type?: string; id?: string; address?: string; publicKey?: string }> {
|
|
137
|
+
const data = await this.storage.get(`wibe3:${this.id}`);
|
|
138
|
+
if (!data) throw new Error("No storage found");
|
|
139
|
+
return JSON.parse(data);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
removeAllListeners() {
|
|
143
|
+
this.events.removeAllListeners();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
onConnect(handler: (payload: { wallet: T }) => void) {
|
|
147
|
+
this.events.on("connect", handler);
|
|
148
|
+
return () => this.events.off("connect", handler);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
onDisconnect(handler: (payload: { wallet: T }) => void) {
|
|
152
|
+
this.events.on("disconnect", handler);
|
|
153
|
+
return () => this.events.off("disconnect", handler);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async disconnect() {
|
|
157
|
+
this.disconnectWalletConnect();
|
|
158
|
+
this.removeStorage();
|
|
159
|
+
this.removeWallet();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
2
|
+
|
|
3
|
+
import { openAuthPopup } from "./ui/connect/AuthPopup";
|
|
4
|
+
import { OmniToken, WalletType } from "./omni/config";
|
|
5
|
+
import { OmniConnector } from "./OmniConnector";
|
|
6
|
+
import { Intents } from "./omni/Intents";
|
|
7
|
+
import { ReviewFee } from "./omni/bridge";
|
|
8
|
+
import { Token } from "./omni/token";
|
|
9
|
+
|
|
10
|
+
export interface AuthCommitment {
|
|
11
|
+
tradingAddress: string;
|
|
12
|
+
signed: Record<string, any>;
|
|
13
|
+
address: string;
|
|
14
|
+
publicKey: string;
|
|
15
|
+
chainId: WalletType;
|
|
16
|
+
seed: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface SignedAuth {
|
|
20
|
+
signed: Record<string, any>;
|
|
21
|
+
address: string;
|
|
22
|
+
publicKey: string;
|
|
23
|
+
chainId: WalletType;
|
|
24
|
+
seed: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export abstract class OmniWallet {
|
|
28
|
+
constructor(readonly connector: OmniConnector) {}
|
|
29
|
+
|
|
30
|
+
abstract address: string;
|
|
31
|
+
abstract publicKey?: string;
|
|
32
|
+
abstract omniAddress: string;
|
|
33
|
+
abstract type: WalletType;
|
|
34
|
+
|
|
35
|
+
async disconnect() {
|
|
36
|
+
if (!this.connector) throw new Error("Connector not implemented");
|
|
37
|
+
await this.connector.disconnect();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
abstract transferFee(token: Token, receiver: string, amount: bigint): Promise<ReviewFee>;
|
|
41
|
+
abstract transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee?: ReviewFee }): Promise<string>;
|
|
42
|
+
|
|
43
|
+
abstract signIntentsWithAuth(domain: string, intents?: Record<string, any>[]): Promise<SignedAuth>;
|
|
44
|
+
abstract signIntents(intents: Record<string, any>[], options?: { nonce?: Uint8Array; deadline?: number }): Promise<Record<string, any>>;
|
|
45
|
+
|
|
46
|
+
abstract fetchBalance(chain: number, address: string): Promise<bigint>;
|
|
47
|
+
abstract fetchBalances(chain?: number, whitelist?: string[]): Promise<Record<string, bigint>>;
|
|
48
|
+
|
|
49
|
+
async executeIntents(intents: Record<string, any>[], hashes: string[] = []) {
|
|
50
|
+
const signed = await this.signIntents(intents);
|
|
51
|
+
return await Intents.publishSignedIntents([signed], hashes);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get icon() {
|
|
55
|
+
return this.connector?.icon;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get intents() {
|
|
59
|
+
return new Intents(this.connector.wibe3).attachWallet(this);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async auth<T = SignedAuth>(domain: string, intents?: Record<string, any>[], then?: (signed: SignedAuth) => Promise<T>): Promise<T> {
|
|
63
|
+
return openAuthPopup<T>(this, async () => {
|
|
64
|
+
const signed = await this.signIntentsWithAuth(domain, intents);
|
|
65
|
+
return (await then?.(signed)) ?? (signed as T);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async pay({ token, amount, recipient, paymentId }: { token: OmniToken; amount: number; recipient: string; paymentId: string }) {
|
|
70
|
+
const nonce = new Uint8Array(sha256(new TextEncoder().encode(paymentId))).slice(0, 32);
|
|
71
|
+
return this.intents.attachNonce(nonce).transfer({ recipient, token, amount }).execute();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async waitUntilBalance(need: Record<string, bigint>, receiver: string, attempts = 0) {
|
|
75
|
+
if (attempts > 120) throw "Balance is not enough";
|
|
76
|
+
const assets = Object.keys(need) as string[];
|
|
77
|
+
const balances = await Intents.getIntentsBalances(assets, receiver);
|
|
78
|
+
if (assets.every((asset) => (balances[asset] || 0n) >= (need[asset] || 0n))) return;
|
|
79
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
80
|
+
await this.waitUntilBalance(need, receiver, attempts + 1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async getIntentsBalance(asset: string, receiver: string): Promise<bigint> {
|
|
84
|
+
const balances = await Intents.getIntentsBalances([asset], receiver);
|
|
85
|
+
return balances[asset] || 0n;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async getAssets() {
|
|
89
|
+
if (!this.omniAddress) return {};
|
|
90
|
+
const assets = await Intents.getIntentsAssets(this.omniAddress);
|
|
91
|
+
const balances = await Intents.getIntentsBalances(assets, this.omniAddress);
|
|
92
|
+
return balances;
|
|
93
|
+
}
|
|
94
|
+
}
|