@hot-labs/kit 1.1.2 → 1.2.0-alpha.1
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 +9 -2
- package/package.json +4 -8
- package/src/HotConnector.ts +31 -21
- package/src/OmniConnector.ts +9 -10
- package/src/OmniWallet.ts +25 -24
- package/src/core/Intents.ts +151 -222
- package/src/core/api.ts +4 -37
- package/src/core/bridge.ts +2 -3
- package/src/core/index.ts +1 -1
- package/src/{near/rpc.ts → core/nearRpc.ts} +11 -4
- package/src/core/types.ts +0 -21
- package/src/core/utils.ts +1 -17
- package/src/cosmos/connector.ts +26 -22
- package/src/cosmos/wallet.ts +8 -3
- package/src/evm/connector.ts +0 -5
- package/src/evm/wallet.ts +6 -9
- package/src/exchange.ts +30 -24
- package/src/hot-wallet/google.ts +5 -12
- package/src/index.ts +0 -2
- package/src/near/connector.ts +2 -2
- package/src/near/wallet.ts +9 -4
- package/src/solana/connector.ts +8 -9
- package/src/solana/injected/solana-wallet.ts +6 -6
- package/src/solana/{WalletStandard.ts → protocol.ts} +4 -2
- package/src/solana/wallet.ts +20 -11
- package/src/stellar/connector.ts +6 -1
- package/src/stellar/wallet.ts +17 -17
- package/src/ton/connector.ts +5 -1
- package/src/ton/wallet.ts +3 -3
- package/src/ui/Popup.tsx +4 -12
- package/src/ui/connect/AuthPopup.tsx +1 -2
- package/src/ui/connect/ConnectWallet.tsx +6 -12
- 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 +4 -2
- package/src/ui/icons/qr.tsx +2 -1
- package/src/ui/icons/search.tsx +4 -4
- package/src/ui/icons/switch.tsx +4 -4
- package/src/ui/icons/wallet.tsx +4 -2
- package/src/ui/payment/Bridge.tsx +6 -25
- package/src/ui/payment/Payment.tsx +46 -241
- package/src/ui/payment/Profile.tsx +8 -10
- package/src/ui/payment/SelectToken.tsx +1 -1
- package/src/ui/payment/TokenCard.tsx +18 -22
- package/src/ui/router.tsx +16 -56
- package/src/ui/styles.ts +0 -2
- package/build/HotConnector.d.ts +0 -103
- package/build/HotConnector.js +0 -300
- package/build/HotConnector.js.map +0 -1
- package/build/OmniConnector.d.ts +0 -90
- package/build/OmniConnector.js +0 -121
- package/build/OmniConnector.js.map +0 -1
- package/build/OmniWallet.d.ts +0 -35
- package/build/OmniWallet.js +0 -56
- package/build/OmniWallet.js.map +0 -1
- package/build/activity.d.ts +0 -18
- package/build/activity.js +0 -87
- package/build/activity.js.map +0 -1
- package/build/core/Intents.d.ts +0 -100
- package/build/core/Intents.js +0 -472
- package/build/core/Intents.js.map +0 -1
- package/build/core/api.d.ts +0 -48
- package/build/core/api.js +0 -93
- package/build/core/api.js.map +0 -1
- package/build/core/bridge.d.ts +0 -3
- package/build/core/bridge.js +0 -36
- package/build/core/bridge.js.map +0 -1
- package/build/core/chains.d.ts +0 -115
- package/build/core/chains.js +0 -381
- package/build/core/chains.js.map +0 -1
- package/build/core/defaultTokens.d.ts +0 -17
- package/build/core/defaultTokens.js +0 -1079
- package/build/core/defaultTokens.js.map +0 -1
- package/build/core/events.d.ts +0 -42
- package/build/core/events.js +0 -64
- package/build/core/events.js.map +0 -1
- package/build/core/index.d.ts +0 -10
- package/build/core/index.js +0 -11
- package/build/core/index.js.map +0 -1
- package/build/core/recipient.d.ts +0 -10
- package/build/core/recipient.js +0 -40
- package/build/core/recipient.js.map +0 -1
- package/build/core/token.d.ts +0 -36
- package/build/core/token.js +0 -103
- package/build/core/token.js.map +0 -1
- package/build/core/tokens.d.ts +0 -14
- package/build/core/tokens.js +0 -59
- package/build/core/tokens.js.map +0 -1
- package/build/core/types.d.ts +0 -60
- package/build/core/types.js +0 -2
- package/build/core/types.js.map +0 -1
- package/build/core/utils.d.ts +0 -25
- package/build/core/utils.js +0 -170
- package/build/core/utils.js.map +0 -1
- package/build/cosmos/connector.d.ts +0 -36
- package/build/cosmos/connector.js +0 -211
- package/build/cosmos/connector.js.map +0 -1
- package/build/cosmos/helpers.d.ts +0 -2
- package/build/cosmos/helpers.js +0 -29
- package/build/cosmos/helpers.js.map +0 -1
- package/build/cosmos/index.d.ts +0 -6
- package/build/cosmos/index.js +0 -5
- package/build/cosmos/index.js.map +0 -1
- package/build/cosmos/wallet.d.ts +0 -26
- package/build/cosmos/wallet.js +0 -51
- package/build/cosmos/wallet.js.map +0 -1
- package/build/defaults.d.ts +0 -1
- package/build/defaults.js +0 -7
- package/build/defaults.js.map +0 -1
- package/build/evm/abi.d.ts +0 -17
- package/build/evm/abi.js +0 -38
- package/build/evm/abi.js.map +0 -1
- package/build/evm/connector.d.ts +0 -29
- package/build/evm/connector.js +0 -118
- package/build/evm/connector.js.map +0 -1
- package/build/evm/index.d.ts +0 -6
- package/build/evm/index.js +0 -5
- package/build/evm/index.js.map +0 -1
- package/build/evm/injected.d.ts +0 -1
- package/build/evm/injected.js +0 -33
- package/build/evm/injected.js.map +0 -1
- package/build/evm/wallet.d.ts +0 -42
- package/build/evm/wallet.js +0 -130
- package/build/evm/wallet.js.map +0 -1
- package/build/exchange.d.ts +0 -68
- package/build/exchange.js +0 -384
- package/build/exchange.js.map +0 -1
- package/build/hot-wallet/google.d.ts +0 -25
- package/build/hot-wallet/google.js +0 -117
- package/build/hot-wallet/google.js.map +0 -1
- package/build/hot-wallet/iframe.d.ts +0 -36
- package/build/hot-wallet/iframe.js +0 -140
- package/build/hot-wallet/iframe.js.map +0 -1
- package/build/hot-wallet/index.d.ts +0 -5
- package/build/hot-wallet/index.js +0 -4
- package/build/hot-wallet/index.js.map +0 -1
- package/build/hot-wallet/proxy.d.ts +0 -8
- package/build/hot-wallet/proxy.js +0 -45
- package/build/hot-wallet/proxy.js.map +0 -1
- package/build/index.d.ts +0 -6
- package/build/index.js +0 -7
- package/build/index.js.map +0 -1
- package/build/near/connector.d.ts +0 -18
- package/build/near/connector.js +0 -58
- package/build/near/connector.js.map +0 -1
- package/build/near/index.d.ts +0 -7
- package/build/near/index.js +0 -5
- package/build/near/index.js.map +0 -1
- package/build/near/rpc.d.ts +0 -23
- package/build/near/rpc.js +0 -161
- package/build/near/rpc.js.map +0 -1
- package/build/near/wallet.d.ts +0 -53
- package/build/near/wallet.js +0 -190
- package/build/near/wallet.js.map +0 -1
- package/build/solana/WalletStandard.d.ts +0 -25
- package/build/solana/WalletStandard.js +0 -56
- package/build/solana/WalletStandard.js.map +0 -1
- package/build/solana/connector.d.ts +0 -30
- package/build/solana/connector.js +0 -139
- package/build/solana/connector.js.map +0 -1
- package/build/solana/index.d.ts +0 -6
- package/build/solana/index.js +0 -5
- package/build/solana/index.js.map +0 -1
- package/build/solana/injected/account.d.ts +0 -11
- package/build/solana/injected/account.js +0 -41
- package/build/solana/injected/account.js.map +0 -1
- package/build/solana/injected/index.d.ts +0 -1
- package/build/solana/injected/index.js +0 -82
- package/build/solana/injected/index.js.map +0 -1
- package/build/solana/injected/register.d.ts +0 -2
- package/build/solana/injected/register.js +0 -41
- package/build/solana/injected/register.js.map +0 -1
- package/build/solana/injected/solana-wallet.d.ts +0 -34
- package/build/solana/injected/solana-wallet.js +0 -223
- package/build/solana/injected/solana-wallet.js.map +0 -1
- package/build/solana/injected/utils.d.ts +0 -32
- package/build/solana/injected/utils.js +0 -36
- package/build/solana/injected/utils.js.map +0 -1
- package/build/solana/wallet.d.ts +0 -40
- package/build/solana/wallet.js +0 -181
- package/build/solana/wallet.js.map +0 -1
- package/build/solana/walletStandartList.d.ts +0 -102
- package/build/solana/walletStandartList.js +0 -150
- package/build/solana/walletStandartList.js.map +0 -1
- package/build/stellar/connector.d.ts +0 -29
- package/build/stellar/connector.js +0 -64
- package/build/stellar/connector.js.map +0 -1
- package/build/stellar/freigher.d.ts +0 -46
- package/build/stellar/freigher.js +0 -110
- package/build/stellar/freigher.js.map +0 -1
- package/build/stellar/hotWallet.d.ts +0 -33
- package/build/stellar/hotWallet.js +0 -28
- package/build/stellar/hotWallet.js.map +0 -1
- package/build/stellar/index.d.ts +0 -6
- package/build/stellar/index.js +0 -5
- package/build/stellar/index.js.map +0 -1
- package/build/stellar/wallet.d.ts +0 -67
- package/build/stellar/wallet.js +0 -212
- package/build/stellar/wallet.js.map +0 -1
- package/build/storage.d.ts +0 -10
- package/build/storage.js +0 -12
- package/build/storage.js.map +0 -1
- package/build/ton/connector.d.ts +0 -24
- package/build/ton/connector.js +0 -111
- package/build/ton/connector.js.map +0 -1
- package/build/ton/index.d.ts +0 -7
- package/build/ton/index.js +0 -5
- package/build/ton/index.js.map +0 -1
- package/build/ton/injected.d.ts +0 -1
- package/build/ton/injected.js +0 -49
- package/build/ton/injected.js.map +0 -1
- package/build/ton/utils.d.ts +0 -45
- package/build/ton/utils.js +0 -63
- package/build/ton/utils.js.map +0 -1
- package/build/ton/wallet.d.ts +0 -54
- package/build/ton/wallet.js +0 -138
- package/build/ton/wallet.js.map +0 -1
- package/build/tron/connector.d.ts +0 -51
- package/build/tron/connector.js +0 -65
- package/build/tron/connector.js.map +0 -1
- package/build/tron/index.d.ts +0 -6
- package/build/tron/index.js +0 -5
- package/build/tron/index.js.map +0 -1
- package/build/tron/wallet.d.ts +0 -52
- package/build/tron/wallet.js +0 -122
- package/build/tron/wallet.js.map +0 -1
- package/build/ui/Popup.d.ts +0 -12
- package/build/ui/Popup.js +0 -43
- package/build/ui/Popup.js.map +0 -1
- package/build/ui/Toast.d.ts +0 -4
- package/build/ui/Toast.js +0 -33
- package/build/ui/Toast.js.map +0 -1
- package/build/ui/connect/AuthPopup.d.ts +0 -2
- package/build/ui/connect/AuthPopup.js +0 -48
- package/build/ui/connect/AuthPopup.js.map +0 -1
- package/build/ui/connect/ConnectWallet.d.ts +0 -14
- package/build/ui/connect/ConnectWallet.js +0 -22
- package/build/ui/connect/ConnectWallet.js.map +0 -1
- package/build/ui/connect/LogoutPopup.d.ts +0 -10
- package/build/ui/connect/LogoutPopup.js +0 -8
- package/build/ui/connect/LogoutPopup.js.map +0 -1
- package/build/ui/connect/PrimaryWallet.d.ts +0 -6
- package/build/ui/connect/PrimaryWallet.js +0 -18
- package/build/ui/connect/PrimaryWallet.js.map +0 -1
- package/build/ui/connect/WCPopup.d.ts +0 -13
- package/build/ui/connect/WCPopup.js +0 -81
- package/build/ui/connect/WCPopup.js.map +0 -1
- package/build/ui/connect/WCRequest.d.ts +0 -9
- package/build/ui/connect/WCRequest.js +0 -13
- package/build/ui/connect/WCRequest.js.map +0 -1
- package/build/ui/connect/WalletPicker.d.ts +0 -11
- package/build/ui/connect/WalletPicker.js +0 -48
- package/build/ui/connect/WalletPicker.js.map +0 -1
- package/build/ui/icons/arrow-right.d.ts +0 -1
- package/build/ui/icons/arrow-right.js +0 -5
- package/build/ui/icons/arrow-right.js.map +0 -1
- package/build/ui/icons/close.d.ts +0 -1
- package/build/ui/icons/close.js +0 -5
- package/build/ui/icons/close.js.map +0 -1
- package/build/ui/icons/exchange.d.ts +0 -6
- package/build/ui/icons/exchange.js +0 -6
- package/build/ui/icons/exchange.js.map +0 -1
- package/build/ui/icons/logout.d.ts +0 -1
- package/build/ui/icons/logout.js +0 -3
- package/build/ui/icons/logout.js.map +0 -1
- package/build/ui/icons/pending.d.ts +0 -1
- package/build/ui/icons/pending.js +0 -5
- package/build/ui/icons/pending.js.map +0 -1
- package/build/ui/icons/qr.d.ts +0 -1
- package/build/ui/icons/qr.js +0 -5
- package/build/ui/icons/qr.js.map +0 -1
- package/build/ui/icons/search.d.ts +0 -1
- package/build/ui/icons/search.js +0 -5
- package/build/ui/icons/search.js.map +0 -1
- package/build/ui/icons/switch.d.ts +0 -1
- package/build/ui/icons/switch.js +0 -5
- package/build/ui/icons/switch.js.map +0 -1
- package/build/ui/icons/wallet.d.ts +0 -1
- package/build/ui/icons/wallet.js +0 -5
- package/build/ui/icons/wallet.js.map +0 -1
- package/build/ui/payment/Bridge.d.ts +0 -29
- package/build/ui/payment/Bridge.js +0 -373
- package/build/ui/payment/Bridge.js.map +0 -1
- package/build/ui/payment/DepositQR.d.ts +0 -9
- package/build/ui/payment/DepositQR.js +0 -56
- package/build/ui/payment/DepositQR.js.map +0 -1
- package/build/ui/payment/Payment.d.ts +0 -23
- package/build/ui/payment/Payment.js +0 -136
- package/build/ui/payment/Payment.js.map +0 -1
- package/build/ui/payment/Profile.d.ts +0 -8
- package/build/ui/payment/Profile.js +0 -110
- package/build/ui/payment/Profile.js.map +0 -1
- package/build/ui/payment/SelectRecipient.d.ts +0 -14
- package/build/ui/payment/SelectRecipient.js +0 -68
- package/build/ui/payment/SelectRecipient.js.map +0 -1
- package/build/ui/payment/SelectSender.d.ts +0 -13
- package/build/ui/payment/SelectSender.js +0 -23
- package/build/ui/payment/SelectSender.js.map +0 -1
- package/build/ui/payment/SelectToken.d.ts +0 -13
- package/build/ui/payment/SelectToken.js +0 -92
- package/build/ui/payment/SelectToken.js.map +0 -1
- package/build/ui/payment/Stepper.d.ts +0 -13
- package/build/ui/payment/Stepper.js +0 -22
- package/build/ui/payment/Stepper.js.map +0 -1
- package/build/ui/payment/TokenCard.d.ts +0 -25
- package/build/ui/payment/TokenCard.js +0 -63
- package/build/ui/payment/TokenCard.js.map +0 -1
- package/build/ui/router.d.ts +0 -51
- package/build/ui/router.js +0 -68
- package/build/ui/router.js.map +0 -1
- package/build/ui/styles.d.ts +0 -13
- package/build/ui/styles.js +0 -290
- package/build/ui/styles.js.map +0 -1
- package/src/tron/connector.ts +0 -89
- package/src/tron/index.ts +0 -7
- package/src/tron/wallet.ts +0 -146
- package/src/ui/Toast.tsx +0 -45
- package/src/ui/connect/PrimaryWallet.tsx +0 -65
- package/src/ui/payment/Stepper.tsx +0 -50
- /package/src/solana/{walletStandartList.ts → wallets.ts} +0 -0
package/README.md
CHANGED
|
@@ -36,10 +36,17 @@ export default defineConfig({
|
|
|
36
36
|
|
|
37
37
|
```ts
|
|
38
38
|
import { HotConnector } from "@hot-labs/kit";
|
|
39
|
-
|
|
39
|
+
|
|
40
|
+
// Tree-shaking - use only chains what you need
|
|
41
|
+
import stellar from "@hot-labs/kit/stellar";
|
|
42
|
+
import solana from "@hot-labs/kit/solana";
|
|
43
|
+
import cosmos from "@hot-labs/kit/cosmos";
|
|
44
|
+
import near from "@hot-labs/kit/near";
|
|
45
|
+
import ton from "@hot-labs/kit/ton";
|
|
46
|
+
import evm from "@hot-labs/kit/evm";
|
|
40
47
|
|
|
41
48
|
const connector = new HotConnector({
|
|
42
|
-
connectors:
|
|
49
|
+
connectors: [near(), evm(), solana(), ton(), stellar(), cosmos()],
|
|
43
50
|
|
|
44
51
|
// optional
|
|
45
52
|
walletConnect: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-labs/kit",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.0-alpha.1",
|
|
4
4
|
"description": "HOT Labs Kit is chain agnostic connector with omni payments",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "",
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"./solana": "./build/solana/index.js",
|
|
18
18
|
"./stellar": "./build/stellar/index.js",
|
|
19
19
|
"./ton": "./build/ton/index.js",
|
|
20
|
-
"./tron": "./build/tron/index.js",
|
|
21
20
|
"./core": "./build/core/index.js"
|
|
22
21
|
},
|
|
23
22
|
"directories": {
|
|
@@ -32,31 +31,28 @@
|
|
|
32
31
|
"@cosmjs/stargate": "^0.37.0",
|
|
33
32
|
"@defuse-protocol/one-click-sdk-typescript": "^0.1.13",
|
|
34
33
|
"@hot-labs/near-connect": "^0.8.1",
|
|
35
|
-
"@hot-labs/omni-sdk": "^2.24.
|
|
34
|
+
"@hot-labs/omni-sdk": "^2.24.5",
|
|
36
35
|
"@keplr-wallet/proto-types": "^0.12.291",
|
|
37
36
|
"@keplr-wallet/provider-extension": "^0.12.291",
|
|
38
|
-
"@
|
|
37
|
+
"@metamask/sdk": "^0.34.0",
|
|
39
38
|
"@near-js/crypto": "^2.3.3",
|
|
40
39
|
"@near-js/providers": "^2.5.1",
|
|
41
40
|
"@near-js/utils": "^2.2.4",
|
|
42
41
|
"@noble/hashes": "^2.0.1",
|
|
43
42
|
"@scure/base": "^2.0.0",
|
|
44
43
|
"@solana/spl-token": "^0.4.14",
|
|
45
|
-
"@solana/wallet-standard-features": "^1.3.0",
|
|
46
44
|
"@stellar/freighter-api": "^6.0.1",
|
|
47
45
|
"@ton-api/client": "^0.4.0",
|
|
48
46
|
"@ton/core": "^0.62.0",
|
|
49
47
|
"@ton/crypto": "^3.3.0",
|
|
50
48
|
"@tonconnect/ui": "^2.2.0",
|
|
51
49
|
"@wallet-standard/base": "^1.1.0",
|
|
52
|
-
"@wallet-standard/features": "^1.1.0",
|
|
53
50
|
"@walletconnect/universal-provider": "^2.23.0",
|
|
54
51
|
"ethers": "^6.15.0",
|
|
55
52
|
"mobx": "^6.15.0",
|
|
56
53
|
"mobx-react-lite": "^4.1.1",
|
|
57
54
|
"qr-code-styling": "^1.9.2",
|
|
58
|
-
"styled-components": "^6.1.19"
|
|
59
|
-
"uuid4": "^2.0.3"
|
|
55
|
+
"styled-components": "^6.1.19"
|
|
60
56
|
},
|
|
61
57
|
"scripts": {
|
|
62
58
|
"build": "rm -rf build && yarn tsc",
|
package/src/HotConnector.ts
CHANGED
|
@@ -8,11 +8,10 @@ import { OmniToken } from "./core/chains";
|
|
|
8
8
|
import { formatter } from "./core/utils";
|
|
9
9
|
import { Intents } from "./core/Intents";
|
|
10
10
|
import { tokens } from "./core/tokens";
|
|
11
|
-
import { rpc } from "./
|
|
11
|
+
import { rpc } from "./core/nearRpc";
|
|
12
12
|
import { Token } from "./core/token";
|
|
13
13
|
import { api } from "./core/api";
|
|
14
14
|
|
|
15
|
-
import { defaultConnectors } from "./defaults";
|
|
16
15
|
import type CosmosWallet from "./cosmos/wallet";
|
|
17
16
|
import type NearWallet from "./near/wallet";
|
|
18
17
|
import type EvmWallet from "./evm/wallet";
|
|
@@ -20,7 +19,7 @@ import type SolanaWallet from "./solana/wallet";
|
|
|
20
19
|
import type StellarWallet from "./stellar/wallet";
|
|
21
20
|
import type TonWallet from "./ton/wallet";
|
|
22
21
|
|
|
23
|
-
import { openBridge, openConnector, openProfile, openWalletPicker } from "./ui/router";
|
|
22
|
+
import { openBridge, openConnector, openPayment, openProfile, openWalletPicker } from "./ui/router";
|
|
24
23
|
import { ConnectorType, OmniConnector } from "./OmniConnector";
|
|
25
24
|
import { OmniWallet } from "./OmniWallet";
|
|
26
25
|
import { Exchange } from "./exchange";
|
|
@@ -49,9 +48,11 @@ export class HotConnector {
|
|
|
49
48
|
public hotBridge: HotBridge;
|
|
50
49
|
public exchange: Exchange;
|
|
51
50
|
|
|
51
|
+
readonly version = "1.0.58";
|
|
52
|
+
|
|
52
53
|
private events = new EventEmitter<{
|
|
53
|
-
connect: { wallet: OmniWallet
|
|
54
|
-
disconnect: { wallet: OmniWallet
|
|
54
|
+
connect: { wallet: OmniWallet };
|
|
55
|
+
disconnect: { wallet: OmniWallet };
|
|
55
56
|
tokensUpdate: { tokens: Token[] };
|
|
56
57
|
}>();
|
|
57
58
|
|
|
@@ -88,8 +89,7 @@ export class HotConnector {
|
|
|
88
89
|
this.activity = new Activity(this);
|
|
89
90
|
|
|
90
91
|
const connectors: OmniConnector[] = [];
|
|
91
|
-
const
|
|
92
|
-
const tasks = configConnectors.map(async (initConnector, index) => {
|
|
92
|
+
const tasks = options?.connectors?.map(async (initConnector, index) => {
|
|
93
93
|
const connector = await initConnector(this);
|
|
94
94
|
connector.onConnect((payload) => this.events.emit("connect", payload));
|
|
95
95
|
connector.onDisconnect((payload) => this.events.emit("disconnect", payload));
|
|
@@ -296,16 +296,36 @@ export class HotConnector {
|
|
|
296
296
|
});
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
|
|
300
|
-
|
|
299
|
+
async requestToken(token: OmniToken, amount: bigint | number): Promise<{ wallet: OmniWallet; token: Token; amount: bigint }> {
|
|
300
|
+
if (!token) throw new Error("Token not found");
|
|
301
|
+
|
|
302
|
+
const tokensList = await tokens.getTokens();
|
|
303
|
+
const ftToken = tokensList.find((t) => t.address === token)!;
|
|
304
|
+
const amountInt = typeof amount === "number" ? ftToken.int(amount) : amount;
|
|
305
|
+
const [existed] = this.walletsTokens.filter((t) => t.token.id === ftToken.id);
|
|
306
|
+
|
|
307
|
+
if (existed?.balance >= amountInt) return { token: ftToken, wallet: existed.wallet, amount: amountInt };
|
|
308
|
+
|
|
309
|
+
const needed = amountInt - (existed?.balance ?? 0n);
|
|
310
|
+
const result = await openPayment(this, ftToken, needed, Recipient.fromWallet(existed?.wallet));
|
|
311
|
+
|
|
312
|
+
const recipientWallet = this.wallets.find((w) => w.address === result.recipient.address);
|
|
313
|
+
if (!recipientWallet) throw new Error("Recipient not found");
|
|
314
|
+
const exist = await this.fetchToken(ftToken, recipientWallet);
|
|
315
|
+
|
|
316
|
+
return {
|
|
317
|
+
token: result.to,
|
|
318
|
+
wallet: recipientWallet,
|
|
319
|
+
amount: formatter.bigIntMin(exist, amountInt),
|
|
320
|
+
};
|
|
301
321
|
}
|
|
302
322
|
|
|
303
|
-
onConnect(handler: (payload: { wallet: OmniWallet
|
|
323
|
+
onConnect(handler: (payload: { wallet: OmniWallet }) => void) {
|
|
304
324
|
this.events.on("connect", handler);
|
|
305
325
|
return () => this.events.off("connect", handler);
|
|
306
326
|
}
|
|
307
327
|
|
|
308
|
-
onDisconnect(handler: (payload: { wallet: OmniWallet
|
|
328
|
+
onDisconnect(handler: (payload: { wallet: OmniWallet }) => void) {
|
|
309
329
|
this.events.on("disconnect", handler);
|
|
310
330
|
return () => this.events.off("disconnect", handler);
|
|
311
331
|
}
|
|
@@ -366,14 +386,4 @@ export class HotConnector {
|
|
|
366
386
|
if (!connector) throw new Error("Connector not found");
|
|
367
387
|
return openWalletPicker(connector);
|
|
368
388
|
}
|
|
369
|
-
|
|
370
|
-
async disconnect(wallet: WalletType | OmniWallet) {
|
|
371
|
-
const connector = this.connectors.find((t) => {
|
|
372
|
-
if (wallet instanceof OmniWallet) return t.wallets.includes(wallet);
|
|
373
|
-
return t.walletTypes.includes(wallet);
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
if (!connector) throw new Error("Connector not found");
|
|
377
|
-
await connector.disconnect();
|
|
378
|
-
}
|
|
379
389
|
}
|
package/src/OmniConnector.ts
CHANGED
|
@@ -19,7 +19,6 @@ export interface OmniConnectorOption {
|
|
|
19
19
|
icon: string;
|
|
20
20
|
id: string;
|
|
21
21
|
download?: string;
|
|
22
|
-
deeplink?: string;
|
|
23
22
|
type: "extension" | "external";
|
|
24
23
|
}
|
|
25
24
|
|
|
@@ -31,8 +30,8 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
|
|
|
31
30
|
|
|
32
31
|
private storage = new LocalStorage();
|
|
33
32
|
protected events = new EventEmitter<{
|
|
34
|
-
connect: { wallet: T
|
|
35
|
-
disconnect: { wallet: T
|
|
33
|
+
connect: { wallet: T };
|
|
34
|
+
disconnect: { wallet: T };
|
|
36
35
|
}>();
|
|
37
36
|
|
|
38
37
|
protected wc: Promise<UniversalProvider> | null = null;
|
|
@@ -102,14 +101,14 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
|
|
|
102
101
|
|
|
103
102
|
protected setWallet(wallet: T) {
|
|
104
103
|
runInAction(() => this.wallets.push(wallet));
|
|
105
|
-
this.events.emit("connect", { wallet
|
|
104
|
+
this.events.emit("connect", { wallet });
|
|
106
105
|
return wallet;
|
|
107
106
|
}
|
|
108
107
|
|
|
109
108
|
protected removeWallet() {
|
|
110
109
|
runInAction(() => {
|
|
111
110
|
const wallet = this.wallets.pop();
|
|
112
|
-
if (wallet) this.events.emit("disconnect", { wallet
|
|
111
|
+
if (wallet) this.events.emit("disconnect", { wallet });
|
|
113
112
|
});
|
|
114
113
|
}
|
|
115
114
|
|
|
@@ -117,7 +116,7 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
|
|
|
117
116
|
runInAction(() => {
|
|
118
117
|
const wallets = this.wallets;
|
|
119
118
|
this.wallets = [];
|
|
120
|
-
wallets.forEach((wallet) => this.events.emit("disconnect", { wallet
|
|
119
|
+
wallets.forEach((wallet) => this.events.emit("disconnect", { wallet }));
|
|
121
120
|
});
|
|
122
121
|
}
|
|
123
122
|
|
|
@@ -131,7 +130,7 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
|
|
|
131
130
|
|
|
132
131
|
async getStorage(): Promise<{ type?: string; id?: string; address?: string; publicKey?: string }> {
|
|
133
132
|
const data = await this.storage.get(`wibe3:${this.id}`);
|
|
134
|
-
if (!data)
|
|
133
|
+
if (!data) throw new Error("No storage found");
|
|
135
134
|
return JSON.parse(data);
|
|
136
135
|
}
|
|
137
136
|
|
|
@@ -139,19 +138,19 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
|
|
|
139
138
|
this.events.removeAllListeners();
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
onConnect(handler: (payload: { wallet: T
|
|
141
|
+
onConnect(handler: (payload: { wallet: T }) => void) {
|
|
143
142
|
this.events.on("connect", handler);
|
|
144
143
|
return () => this.events.off("connect", handler);
|
|
145
144
|
}
|
|
146
145
|
|
|
147
|
-
onDisconnect(handler: (payload: { wallet: T
|
|
146
|
+
onDisconnect(handler: (payload: { wallet: T }) => void) {
|
|
148
147
|
this.events.on("disconnect", handler);
|
|
149
148
|
return () => this.events.off("disconnect", handler);
|
|
150
149
|
}
|
|
151
150
|
|
|
152
151
|
async disconnect() {
|
|
153
152
|
this.disconnectWalletConnect();
|
|
154
|
-
this.removeAllWallets();
|
|
155
153
|
this.removeStorage();
|
|
154
|
+
this.removeWallet();
|
|
156
155
|
}
|
|
157
156
|
}
|
package/src/OmniWallet.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
1
2
|
import { hex } from "@scure/base";
|
|
2
3
|
|
|
3
4
|
import { openAuthPopup } from "./ui/connect/AuthPopup";
|
|
4
|
-
import { WalletType } from "./core/chains";
|
|
5
|
+
import { OmniToken, WalletType } from "./core/chains";
|
|
6
|
+
import { OmniConnector } from "./OmniConnector";
|
|
5
7
|
import { Intents } from "./core/Intents";
|
|
6
8
|
import { ReviewFee } from "./core/bridge";
|
|
7
9
|
import { Token } from "./core/token";
|
|
@@ -9,44 +11,38 @@ import { Commitment } from "./core";
|
|
|
9
11
|
import { api } from "./core/api";
|
|
10
12
|
|
|
11
13
|
export abstract class OmniWallet {
|
|
14
|
+
constructor(readonly connector: OmniConnector) {}
|
|
15
|
+
|
|
12
16
|
abstract address: string;
|
|
13
17
|
abstract publicKey?: string;
|
|
14
18
|
abstract omniAddress: string;
|
|
15
19
|
abstract type: WalletType;
|
|
16
|
-
abstract icon: string;
|
|
17
20
|
|
|
18
|
-
async
|
|
19
|
-
|
|
21
|
+
async disconnect() {
|
|
22
|
+
if (!this.connector) throw new Error("Connector not implemented");
|
|
23
|
+
await this.connector.disconnect();
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
26
|
+
abstract transferFee(token: Token, receiver: string, amount: bigint): Promise<ReviewFee>;
|
|
27
|
+
abstract transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee?: ReviewFee }): Promise<string>;
|
|
28
|
+
abstract signIntents(intents: Record<string, any>[], options?: { nonce?: Uint8Array; deadline?: number }): Promise<Commitment>;
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
30
|
+
abstract fetchBalance(chain: number, address: string): Promise<bigint>;
|
|
31
|
+
abstract fetchBalances(chain?: number, whitelist?: string[]): Promise<Record<string, bigint>>;
|
|
29
32
|
|
|
30
|
-
async
|
|
31
|
-
|
|
33
|
+
async executeIntents(intents: Record<string, any>[], hashes: string[] = []) {
|
|
34
|
+
const signed = await this.signIntents(intents);
|
|
35
|
+
return await Intents.publishSignedIntents([signed], hashes);
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
|
|
35
|
-
return
|
|
38
|
+
get icon() {
|
|
39
|
+
return this.connector?.icon;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
get intents() {
|
|
43
|
+
return new Intents(this.connector.wibe3).attachWallet(this);
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
abstract transferFee(token: Token, receiver: string, amount: bigint): Promise<ReviewFee>;
|
|
43
|
-
abstract transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee?: ReviewFee }): Promise<string>;
|
|
44
|
-
|
|
45
|
-
abstract fetchBalance(chain: number, address: string): Promise<bigint>;
|
|
46
|
-
abstract fetchBalances(chain?: number, whitelist?: string[]): Promise<Record<string, bigint>>;
|
|
47
|
-
|
|
48
|
-
abstract signIntents(intents: Record<string, any>[], options?: { nonce?: Uint8Array; deadline?: number }): Promise<Commitment>;
|
|
49
|
-
|
|
50
46
|
async auth(intents?: Record<string, any>[]): Promise<string> {
|
|
51
47
|
return openAuthPopup(this, async () => {
|
|
52
48
|
const seed = hex.encode(new Uint8Array(window.crypto.getRandomValues(new Uint8Array(32))));
|
|
@@ -57,6 +53,11 @@ export abstract class OmniWallet {
|
|
|
57
53
|
});
|
|
58
54
|
}
|
|
59
55
|
|
|
56
|
+
async pay({ token, amount, recipient, paymentId }: { token: OmniToken; amount: number; recipient: string; paymentId: string }) {
|
|
57
|
+
const nonce = new Uint8Array(sha256(new TextEncoder().encode(paymentId))).slice(0, 32);
|
|
58
|
+
return this.intents.attachNonce(nonce).transfer({ recipient, token, amount }).execute();
|
|
59
|
+
}
|
|
60
|
+
|
|
60
61
|
async waitUntilBalance(need: Record<string, bigint>, receiver: string, attempts = 0) {
|
|
61
62
|
if (attempts > 120) throw "Balance is not enough";
|
|
62
63
|
const assets = Object.keys(need) as string[];
|