@hot-labs/kit 1.5.4 → 1.6.0

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.
Files changed (202) hide show
  1. package/.github/workflows/release.yml +1 -1
  2. package/README.md +5 -5
  3. package/build/HotBridgeWithdrawal.d.ts +10 -0
  4. package/build/HotBridgeWithdrawal.js +80 -0
  5. package/build/HotBridgeWithdrawal.js.map +1 -0
  6. package/build/{HotConnector.d.ts → HotKit.d.ts} +9 -5
  7. package/build/{HotConnector.js → HotKit.js} +14 -11
  8. package/build/HotKit.js.map +1 -0
  9. package/build/activity.d.ts +8 -12
  10. package/build/activity.js +16 -67
  11. package/build/activity.js.map +1 -1
  12. package/build/core/Intents.d.ts +6 -9
  13. package/build/core/Intents.js +28 -29
  14. package/build/core/Intents.js.map +1 -1
  15. package/build/core/OmniConnector.d.ts +3 -3
  16. package/build/core/OmniConnector.js +13 -13
  17. package/build/core/OmniConnector.js.map +1 -1
  18. package/build/core/OmniWallet.d.ts +3 -2
  19. package/build/core/OmniWallet.js +5 -5
  20. package/build/core/OmniWallet.js.map +1 -1
  21. package/build/core/chains.d.ts +2 -1
  22. package/build/core/chains.js +1 -0
  23. package/build/core/chains.js.map +1 -1
  24. package/build/core/exchange.d.ts +6 -9
  25. package/build/core/exchange.js +17 -93
  26. package/build/core/exchange.js.map +1 -1
  27. package/build/core/pendings.d.ts +32 -0
  28. package/build/core/pendings.js +143 -0
  29. package/build/core/pendings.js.map +1 -0
  30. package/build/core/telemetry.d.ts +3 -3
  31. package/build/core/telemetry.js +4 -4
  32. package/build/core/telemetry.js.map +1 -1
  33. package/build/cosmos/connector.d.ts +2 -2
  34. package/build/cosmos/connector.js +2 -2
  35. package/build/cosmos/connector.js.map +1 -1
  36. package/build/cosmos/index.d.ts +2 -2
  37. package/build/cosmos/index.js +1 -1
  38. package/build/cosmos/index.js.map +1 -1
  39. package/build/defaults.d.ts +1 -1
  40. package/build/evm/connector.d.ts +4 -4
  41. package/build/evm/connector.js +2 -2
  42. package/build/evm/connector.js.map +1 -1
  43. package/build/evm/index.d.ts +2 -2
  44. package/build/evm/index.js +1 -1
  45. package/build/evm/index.js.map +1 -1
  46. package/build/hocraft/connector.d.ts +3 -3
  47. package/build/hocraft/connector.js +7 -7
  48. package/build/hocraft/connector.js.map +1 -1
  49. package/build/hocraft/index.d.ts +2 -2
  50. package/build/hocraft/index.js +1 -1
  51. package/build/hocraft/index.js.map +1 -1
  52. package/build/hot-wallet/google.d.ts +2 -2
  53. package/build/hot-wallet/google.js +5 -5
  54. package/build/hot-wallet/google.js.map +1 -1
  55. package/build/hot-wallet/index.d.ts +2 -2
  56. package/build/hot-wallet/index.js +1 -1
  57. package/build/hot-wallet/index.js.map +1 -1
  58. package/build/index.d.ts +3 -1
  59. package/build/index.js +4 -1
  60. package/build/index.js.map +1 -1
  61. package/build/near/connector.d.ts +3 -3
  62. package/build/near/connector.js +4 -4
  63. package/build/near/connector.js.map +1 -1
  64. package/build/near/index.d.ts +2 -2
  65. package/build/near/index.js +1 -1
  66. package/build/near/index.js.map +1 -1
  67. package/build/solana/connector.d.ts +4 -4
  68. package/build/solana/connector.js +2 -2
  69. package/build/solana/connector.js.map +1 -1
  70. package/build/solana/index.d.ts +2 -2
  71. package/build/solana/index.js +1 -1
  72. package/build/solana/index.js.map +1 -1
  73. package/build/stellar/connector.d.ts +2 -2
  74. package/build/stellar/connector.js +3 -3
  75. package/build/stellar/connector.js.map +1 -1
  76. package/build/stellar/index.d.ts +2 -2
  77. package/build/stellar/index.js +1 -1
  78. package/build/stellar/index.js.map +1 -1
  79. package/build/storage.d.ts +10 -0
  80. package/build/storage.js +56 -0
  81. package/build/storage.js.map +1 -1
  82. package/build/ton/connector.d.ts +2 -2
  83. package/build/ton/connector.js +3 -3
  84. package/build/ton/connector.js.map +1 -1
  85. package/build/ton/index.d.ts +2 -2
  86. package/build/ton/index.js +1 -1
  87. package/build/ton/index.js.map +1 -1
  88. package/build/tron/connector.d.ts +2 -2
  89. package/build/tron/connector.js +2 -2
  90. package/build/tron/connector.js.map +1 -1
  91. package/build/tron/index.d.ts +2 -2
  92. package/build/tron/index.js +1 -1
  93. package/build/tron/index.js.map +1 -1
  94. package/build/ui/Popup.d.ts +2 -1
  95. package/build/ui/Popup.js +3 -3
  96. package/build/ui/Popup.js.map +1 -1
  97. package/build/ui/bridge/Bridge.d.ts +4 -4
  98. package/build/ui/bridge/Bridge.js +36 -40
  99. package/build/ui/bridge/Bridge.js.map +1 -1
  100. package/build/ui/bridge/SelectRecipient.d.ts +3 -3
  101. package/build/ui/bridge/SelectRecipient.js +2 -2
  102. package/build/ui/bridge/SelectSender.d.ts +3 -3
  103. package/build/ui/bridge/SelectSender.js +2 -2
  104. package/build/ui/bridge/SelectToken.d.ts +3 -3
  105. package/build/ui/bridge/SelectToken.js +12 -12
  106. package/build/ui/bridge/TokenCard.d.ts +10 -8
  107. package/build/ui/bridge/TokenCard.js +3 -3
  108. package/build/ui/bridge/TokenCard.js.map +1 -1
  109. package/build/ui/connect/AuthPopup.d.ts +8 -1
  110. package/build/ui/connect/AuthPopup.js +2 -20
  111. package/build/ui/connect/AuthPopup.js.map +1 -1
  112. package/build/ui/connect/ConnectWallet.d.ts +3 -3
  113. package/build/ui/connect/ConnectWallet.js +3 -3
  114. package/build/ui/connect/PrimaryWallet.d.ts +3 -3
  115. package/build/ui/connect/PrimaryWallet.js +2 -2
  116. package/build/ui/connect/PrimaryWallet.js.map +1 -1
  117. package/build/ui/icons/copy.d.ts +1 -0
  118. package/build/ui/icons/copy.js +5 -0
  119. package/build/ui/icons/copy.js.map +1 -0
  120. package/build/ui/icons/warning.d.ts +1 -0
  121. package/build/ui/icons/warning.js +5 -0
  122. package/build/ui/icons/warning.js.map +1 -0
  123. package/build/ui/profile/DepositFlow.d.ts +8 -0
  124. package/build/ui/profile/DepositFlow.js +13 -0
  125. package/build/ui/profile/DepositFlow.js.map +1 -0
  126. package/build/ui/profile/DepositQR.d.ts +4 -2
  127. package/build/ui/profile/DepositQR.js +25 -4
  128. package/build/ui/profile/DepositQR.js.map +1 -1
  129. package/build/ui/profile/Payment.d.ts +6 -9
  130. package/build/ui/profile/Payment.js +36 -28
  131. package/build/ui/profile/Payment.js.map +1 -1
  132. package/build/ui/profile/Profile.d.ts +3 -3
  133. package/build/ui/profile/Profile.js +17 -52
  134. package/build/ui/profile/Profile.js.map +1 -1
  135. package/build/ui/router.d.ts +14 -15
  136. package/build/ui/router.js +37 -16
  137. package/build/ui/router.js.map +1 -1
  138. package/build/ui/toast/index.d.ts +42 -0
  139. package/build/ui/toast/index.js +165 -0
  140. package/build/ui/toast/index.js.map +1 -0
  141. package/build/ui/uikit/button.js +1 -1
  142. package/build/ui/uikit/checkbox.d.ts +8 -0
  143. package/build/ui/uikit/checkbox.js +39 -0
  144. package/build/ui/uikit/checkbox.js.map +1 -0
  145. package/build/ui/uikit/text.js +27 -27
  146. package/package.json +1 -1
  147. package/src/HotBridgeWithdrawal.ts +80 -0
  148. package/src/{HotConnector.ts → HotKit.ts} +17 -13
  149. package/src/activity.ts +22 -69
  150. package/src/core/Intents.ts +22 -36
  151. package/src/core/OmniConnector.ts +12 -12
  152. package/src/core/OmniWallet.ts +6 -6
  153. package/src/core/chains.ts +1 -0
  154. package/src/core/exchange.ts +19 -89
  155. package/src/core/pendings.ts +151 -0
  156. package/src/core/telemetry.ts +3 -3
  157. package/src/cosmos/connector.ts +3 -3
  158. package/src/cosmos/index.ts +3 -3
  159. package/src/evm/connector.ts +3 -3
  160. package/src/evm/index.ts +2 -2
  161. package/src/hocraft/connector.ts +6 -6
  162. package/src/hocraft/index.ts +2 -2
  163. package/src/hot-wallet/google.ts +6 -6
  164. package/src/hot-wallet/index.ts +2 -2
  165. package/src/index.ts +6 -1
  166. package/src/near/connector.ts +3 -3
  167. package/src/near/index.ts +2 -2
  168. package/src/solana/connector.ts +3 -3
  169. package/src/solana/index.ts +2 -2
  170. package/src/stellar/connector.ts +4 -4
  171. package/src/stellar/index.ts +2 -2
  172. package/src/storage.ts +69 -0
  173. package/src/ton/connector.ts +4 -4
  174. package/src/ton/index.ts +2 -2
  175. package/src/tron/connector.ts +3 -3
  176. package/src/tron/index.ts +2 -2
  177. package/src/ui/Popup.tsx +4 -3
  178. package/src/ui/bridge/Bridge.tsx +43 -46
  179. package/src/ui/bridge/SelectRecipient.tsx +4 -4
  180. package/src/ui/bridge/SelectSender.tsx +4 -4
  181. package/src/ui/bridge/SelectToken.tsx +14 -14
  182. package/src/ui/bridge/TokenCard.tsx +31 -24
  183. package/src/ui/connect/AuthPopup.tsx +1 -24
  184. package/src/ui/connect/ConnectWallet.tsx +5 -5
  185. package/src/ui/connect/PrimaryWallet.tsx +3 -3
  186. package/src/ui/icons/copy.tsx +8 -0
  187. package/src/ui/icons/warning.tsx +10 -0
  188. package/src/ui/profile/DepositFlow.tsx +27 -0
  189. package/src/ui/profile/DepositQR.tsx +47 -16
  190. package/src/ui/profile/Payment.tsx +67 -37
  191. package/src/ui/profile/Profile.tsx +39 -68
  192. package/src/ui/router.tsx +48 -21
  193. package/src/ui/toast/index.tsx +238 -0
  194. package/src/ui/uikit/button.tsx +1 -1
  195. package/src/ui/uikit/checkbox.tsx +60 -0
  196. package/src/ui/uikit/text.tsx +27 -27
  197. package/build/HotConnector.js.map +0 -1
  198. package/build/ui/uikit/Toast.d.ts +0 -4
  199. package/build/ui/uikit/Toast.js +0 -33
  200. package/build/ui/uikit/Toast.js.map +0 -1
  201. package/src/ui/uikit/Toast.tsx +0 -45
  202. package/vite.config.ts +0 -17
@@ -1,7 +1,7 @@
1
1
  import { action, makeObservable, observable, runInAction } from "mobx";
2
2
  import UniversalProvider, { NamespaceConfig } from "@walletconnect/universal-provider";
3
3
 
4
- import type { HotConnector } from "../HotConnector";
4
+ import type { HotKit } from "../HotKit";
5
5
  import { EventEmitter } from "./events";
6
6
  import { OmniWallet } from "./OmniWallet";
7
7
  import { WalletType } from "./chains";
@@ -36,7 +36,7 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
36
36
 
37
37
  protected wc: Promise<UniversalProvider> | null = null;
38
38
 
39
- constructor(readonly wibe3: HotConnector) {
39
+ constructor(readonly kit: HotKit) {
40
40
  makeObservable(this, {
41
41
  wallets: observable,
42
42
  options: observable,
@@ -46,19 +46,19 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
46
46
  }
47
47
 
48
48
  get storage() {
49
- return this.wibe3.storage;
49
+ return this.kit.storage;
50
50
  }
51
51
 
52
52
  openWallet() {}
53
53
 
54
54
  async initWalletConnect() {
55
- if (!this.wibe3.settings?.projectId) throw new Error("Project ID is required");
55
+ if (!this.kit.settings?.projectId) throw new Error("Project ID is required");
56
56
  if (this.wc) return this.wc;
57
57
  this.wc = UniversalProvider.init({
58
58
  relayUrl: "wss://relay.walletconnect.org",
59
- projectId: this.wibe3.settings?.projectId,
60
- metadata: this.wibe3.settings?.metadata,
61
- customStoragePrefix: `wibe3:${this.id}`,
59
+ projectId: this.kit.settings?.projectId,
60
+ metadata: this.kit.settings?.metadata,
61
+ customStoragePrefix: `kit:${this.id}`,
62
62
  name: this.name,
63
63
  });
64
64
 
@@ -86,8 +86,7 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
86
86
  }
87
87
 
88
88
  async requestWalletConnect<T>(args: { chain?: string; request: any; deeplink?: string; name?: string; icon?: string }): Promise<T> {
89
- const { openWCRequest } = await import("../ui/router");
90
- return openWCRequest<T>({
89
+ return this.kit.router.openWCRequest<T>({
91
90
  deeplink: args.deeplink,
92
91
  name: args.name || "WalletConnect",
93
92
  icon: args.icon || WC_ICON,
@@ -109,6 +108,7 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
109
108
  abstract id: string;
110
109
 
111
110
  protected setWallet({ wallet, isNew }: { wallet: T; isNew: boolean }) {
111
+ wallet.kit = this.kit;
112
112
  const existing = this.wallets.find((t) => t.address === wallet.address);
113
113
  if (existing) return existing;
114
114
 
@@ -140,15 +140,15 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
140
140
  }
141
141
 
142
142
  async setStorage(obj: { type?: string; id?: string; address?: string; publicKey?: string; [key: string]: any }) {
143
- await this.storage.set(`wibe3:${this.id}`, JSON.stringify(obj));
143
+ await this.storage.set(`kit:${this.id}`, JSON.stringify(obj));
144
144
  }
145
145
 
146
146
  async removeStorage() {
147
- await this.storage.remove(`wibe3:${this.id}`);
147
+ await this.storage.remove(`kit:${this.id}`);
148
148
  }
149
149
 
150
150
  async getStorage(): Promise<{ type?: string; id?: string; address?: string; publicKey?: string; [key: string]: any }> {
151
- const data = await this.storage.get(`wibe3:${this.id}`);
151
+ const data = await this.storage.get(`kit:${this.id}`);
152
152
  if (!data) return {};
153
153
  return JSON.parse(data);
154
154
  }
@@ -1,7 +1,7 @@
1
1
  import { hex } from "@scure/base";
2
2
  import { action, makeObservable, observable } from "mobx";
3
3
 
4
- import type { HotConnector } from "../HotConnector";
4
+ import type { HotKit } from "../HotKit";
5
5
  import { Network, OmniToken, WalletType } from "./chains";
6
6
  import { Commitment } from "./types";
7
7
  import { Intents } from "./Intents";
@@ -11,6 +11,7 @@ import { api } from "./api";
11
11
 
12
12
  export abstract class OmniWallet {
13
13
  balances: Record<string, bigint> = {};
14
+ kit?: HotKit;
14
15
 
15
16
  abstract address: string;
16
17
  abstract publicKey?: string;
@@ -22,8 +23,8 @@ export abstract class OmniWallet {
22
23
  makeObservable(this, { balances: observable, setBalance: action });
23
24
  }
24
25
 
25
- intents(wibe3?: HotConnector) {
26
- return new Intents(wibe3).attachWallet(this);
26
+ intents(kit?: HotKit) {
27
+ return new Intents(kit).attachWallet(this);
27
28
  }
28
29
 
29
30
  setBalance(id: string, balance: bigint) {
@@ -113,9 +114,8 @@ export abstract class OmniWallet {
113
114
  return (await api.auth(signed, seed)) as T;
114
115
  };
115
116
 
116
- if (typeof window === "undefined") return await authFn();
117
- const { openAuthPopup } = await import("../ui/connect/AuthPopup");
118
- return openAuthPopup(this, authFn);
117
+ if (this.kit == null) return await authFn();
118
+ return this.kit.router.openAuthPopup(this, authFn);
119
119
  }
120
120
 
121
121
  async waitUntilOmniBalance(need: Record<string, bigint>, receiver = this.omniAddress, attempts = 0) {
@@ -8,6 +8,7 @@ export enum OmniToken {
8
8
  SOL = "nep141:sol.omft.near",
9
9
  BNB = "nep245:v2_1.omni.hot.tg:56_11111111111111111111",
10
10
  ADI = "nep245:v2_1.omni.hot.tg:36900_11111111111111111111",
11
+ ZEC = "nep141:zec.omft.near",
11
12
  }
12
13
 
13
14
  export enum WalletType {
@@ -1,9 +1,12 @@
1
- import { GetExecutionStatusResponse, OneClickService, ApiError, QuoteRequest, QuoteResponse } from "@defuse-protocol/one-click-sdk-typescript";
1
+ import { OneClickService, ApiError, QuoteRequest, QuoteResponse } from "@defuse-protocol/one-click-sdk-typescript";
2
2
  import { utils } from "@hot-labs/omni-sdk";
3
3
  import { hex } from "@scure/base";
4
4
 
5
- import { chains, Network, OmniToken, WalletType } from "./chains";
5
+ import type { HotKit } from "../HotKit";
6
+
7
+ import { chains, Network, WalletType } from "./chains";
6
8
  import { createHotBridge, ReviewFee } from "./bridge";
9
+ import { BridgePending } from "./pendings";
7
10
  import { OmniWallet } from "./OmniWallet";
8
11
  import { Recipient } from "./recipient";
9
12
  import { ILogger } from "./telemetry";
@@ -55,9 +58,8 @@ export interface BridgeRequest {
55
58
  to: Token;
56
59
  }
57
60
 
58
- const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
59
-
60
61
  export class Exchange {
62
+ constructor(readonly kit?: HotKit) {}
61
63
  readonly bridge = createHotBridge();
62
64
 
63
65
  async getToken(chain: number, address: string): Promise<string | null> {
@@ -196,11 +198,17 @@ export class Exchange {
196
198
  }
197
199
 
198
200
  async reviewSwap(request: BridgeRequest): Promise<BridgeReview> {
199
- const { sender, refund, from, to, amount, recipient, slippage, type, logger } = request;
201
+ const { sender, refund, from, to, amount, recipient, type, logger } = request;
200
202
 
201
203
  const deadlineTime = 5 * 60 * 1000;
202
204
  const deadline = new Date(Date.now() + deadlineTime).toISOString();
203
- const noFee = from.symbol === to.symbol || (from.symbol.toLowerCase().includes("usd") && to.symbol.toLowerCase().includes("usd"));
205
+
206
+ const stables = ["usdt", "usdc", "dai", "frax"];
207
+ const isFromStable = stables.some((stable) => from.symbol.toLowerCase().includes(stable));
208
+ const isToStable = stables.some((stable) => to.symbol.toLowerCase().includes(stable));
209
+ const isDirect = from.originalId === to.originalId;
210
+ const noFee = from.symbol === to.symbol || (isFromStable && isToStable) || isDirect;
211
+ const slippage = isDirect ? 0 : request.slippage;
204
212
 
205
213
  if (sender !== "qr" && this.isDirectDeposit(from, to)) {
206
214
  let fee: ReviewFee | null = null;
@@ -335,7 +343,7 @@ export class Exchange {
335
343
  };
336
344
  }
337
345
 
338
- async makeSwap(review: BridgeReview): Promise<{ review: BridgeReview; processing?: () => Promise<BridgeReview> }> {
346
+ async makeSwap(review: BridgeReview): Promise<BridgePending> {
339
347
  const { sender, recipient, logger, refund } = review;
340
348
  if (sender == null) throw new Error("Sender is required");
341
349
  if (recipient == null) throw new Error("Recipient is required");
@@ -346,7 +354,7 @@ export class Exchange {
346
354
  await this.withdraw({ sender, token: review.to, amount: review.amountIn, recipient, logger });
347
355
  if (recipient instanceof OmniWallet) recipient.fetchBalance(review.to.chain, review.to.address);
348
356
  if (sender instanceof OmniWallet) sender.fetchBalance(review.from.chain, review.from.address);
349
- return { review };
357
+ return new BridgePending(review, this.kit);
350
358
  }
351
359
 
352
360
  if (review.qoute === "deposit") {
@@ -354,7 +362,7 @@ export class Exchange {
354
362
  await this.deposit({ sender, token: review.from, amount: review.amountIn, recipient, logger });
355
363
  if (recipient instanceof OmniWallet) recipient.fetchBalance(review.to.chain, review.to.address);
356
364
  if (sender instanceof OmniWallet) sender.fetchBalance(review.from.chain, review.from.address);
357
- return { review };
365
+ return new BridgePending(review, this.kit);
358
366
  }
359
367
 
360
368
  if (recipient.type === WalletType.STELLAR) {
@@ -364,18 +372,7 @@ export class Exchange {
364
372
  }
365
373
 
366
374
  if (sender === "qr") {
367
- return {
368
- review,
369
- processing: async () => {
370
- if (!(recipient instanceof OmniWallet)) return await this.processing(review);
371
- const beforeBalance = await recipient.fetchBalance(review.to.chain, review.to.address).catch(() => null);
372
- if (!beforeBalance) return await this.processing(review);
373
- return await Promise.race([
374
- this.waitBalance(review.to, recipient, beforeBalance, review),
375
- this.processing(review), //
376
- ]);
377
- },
378
- };
375
+ return new BridgePending(review, this.kit);
379
376
  }
380
377
 
381
378
  const depositAddress = review.qoute.depositAddress!;
@@ -389,73 +386,6 @@ export class Exchange {
389
386
 
390
387
  if (sender instanceof OmniWallet) sender.fetchBalance(review.from.chain, review.from.address);
391
388
  OneClickService.submitDepositTx({ txHash: hash, depositAddress }).catch(() => {});
392
-
393
- return {
394
- review,
395
- processing: async () => {
396
- if (!(recipient instanceof OmniWallet)) return await this.processing(review);
397
-
398
- const beforeBalance = await recipient.fetchBalance(review.to.chain, review.to.address).catch(() => null);
399
- if (!beforeBalance) return await this.processing(review);
400
-
401
- return await Promise.race([
402
- this.waitBalance(review.to, recipient, beforeBalance, review),
403
- this.processing(review), //
404
- ]);
405
- },
406
- };
407
- }
408
-
409
- async waitBalance(to: Token, wallet: OmniWallet, beforeBalance: bigint, review: BridgeReview): Promise<BridgeReview> {
410
- const afterBalance = await wallet.fetchBalance(to.chain, to.address).catch(() => beforeBalance);
411
- if (afterBalance > beforeBalance) {
412
- return {
413
- ...review,
414
- amountOut: afterBalance - beforeBalance,
415
- statusMessage: "Swap successful",
416
- status: "success",
417
- };
418
- }
419
-
420
- await wait(2000);
421
- return await this.waitBalance(to, wallet, beforeBalance, review);
422
- }
423
-
424
- getMessage(status: GetExecutionStatusResponse.status): string | null {
425
- if (status === GetExecutionStatusResponse.status.PENDING_DEPOSIT) return "Waiting for deposit";
426
- if (status === GetExecutionStatusResponse.status.INCOMPLETE_DEPOSIT) return "Incomplete deposit";
427
- if (status === GetExecutionStatusResponse.status.KNOWN_DEPOSIT_TX) return "Known deposit tx";
428
- if (status === GetExecutionStatusResponse.status.PROCESSING) return "Processing swap";
429
- if (status === GetExecutionStatusResponse.status.SUCCESS) return "Swap successful";
430
- if (status === GetExecutionStatusResponse.status.FAILED) return "Swap failed";
431
- if (status === GetExecutionStatusResponse.status.REFUNDED) return "Swap refunded";
432
- return null;
433
- }
434
-
435
- async checkStatus(review: BridgeReview) {
436
- if (review.qoute === "deposit" || review.qoute === "withdraw") return;
437
- const status = await OneClickService.getExecutionStatus(review.qoute.depositAddress!, review.qoute.depositMemo);
438
- const message = this.getMessage(status.status);
439
-
440
- let state: "pending" | "success" | "failed" = "pending";
441
- if (status.status === GetExecutionStatusResponse.status.SUCCESS) state = "success";
442
- if (status.status === GetExecutionStatusResponse.status.FAILED) state = "failed";
443
- if (status.status === GetExecutionStatusResponse.status.REFUNDED) state = "failed";
444
-
445
- if (status.swapDetails.amountOut) review.amountOut = BigInt(status.swapDetails.amountOut);
446
- review.statusMessage = message;
447
- review.status = state;
448
- return review;
449
- }
450
-
451
- async processing(review: BridgeReview, interval = 3000) {
452
- while (review.status === "pending") {
453
- await this.checkStatus(review);
454
- await new Promise((resolve) => setTimeout(resolve, interval));
455
- }
456
-
457
- if (review.status === "success") return review;
458
- if (review.status === "failed") throw review.statusMessage || "Bridge failed";
459
- throw new Error("Unknown status");
389
+ return new BridgePending(review, this.kit);
460
390
  }
461
391
  }
@@ -0,0 +1,151 @@
1
+ import { makeObservable, observable, runInAction } from "mobx";
2
+ import { GetExecutionStatusResponse, OneClickService } from "@defuse-protocol/one-click-sdk-typescript";
3
+ import { v4 as uuidv4 } from "uuid";
4
+
5
+ import type { ToastController } from "../ui/toast";
6
+ import type { HotKit } from "../HotKit";
7
+
8
+ import { wait } from "../hot-wallet/iframe";
9
+ import { OmniWallet } from "../core/OmniWallet";
10
+ import { BridgeReview } from "../core/exchange";
11
+ import { Token } from "./token";
12
+
13
+ export abstract class ActivityController {
14
+ status: "pending" | "success" | "failed" = "pending";
15
+ id = uuidv4();
16
+
17
+ title: string | null = null;
18
+ subtitle: string | null = null;
19
+
20
+ preview: Token | string | null = null;
21
+ actionLoading: boolean = false;
22
+ actionText: string | null = null;
23
+
24
+ action(): Promise<void> {
25
+ throw new Error("Not implemented");
26
+ }
27
+
28
+ constructor() {
29
+ makeObservable(this, {
30
+ status: observable,
31
+ subtitle: observable,
32
+ actionText: observable,
33
+ actionLoading: observable,
34
+ preview: observable,
35
+ title: observable,
36
+ });
37
+ }
38
+ }
39
+
40
+ export class BridgePending extends ActivityController {
41
+ readonly processingTask: Promise<BridgeReview>;
42
+ private toast?: ToastController;
43
+
44
+ constructor(readonly review: BridgeReview, readonly kit?: HotKit) {
45
+ super();
46
+
47
+ this.processingTask = this._processing();
48
+ this.title = this.getTitle();
49
+
50
+ this.toast = this.kit?.toast.pending(this.title);
51
+ this.preview = this.review.to;
52
+ }
53
+
54
+ serialize() {
55
+ return {};
56
+ }
57
+
58
+ getTitle() {
59
+ const from = `${this.review.from.readable(this.review.amountIn)} ${this.review.from.symbol}`;
60
+ const to = `${this.review.to.readable(this.review.amountOut)} ${this.review.to.symbol}`;
61
+
62
+ if (this.review.from.originalId === this.review.to.originalId) {
63
+ if (this.review.from.isOmni) return `Withdraw ${from}`;
64
+ if (this.review.to.isOmni) return `Deposit ${to}`;
65
+ }
66
+
67
+ const fromChain = this.review.from.chainName.toLowerCase();
68
+ const toChain = this.review.to.chainName.toLowerCase();
69
+ return `${from} (${fromChain}) → ${to} (${toChain})`;
70
+ }
71
+
72
+ updateStatus(status: "pending" | "success" | "failed", statusMessage: string | null) {
73
+ runInAction(() => {
74
+ this.status = status;
75
+ this.subtitle = statusMessage;
76
+ this.toast?.update({ type: status, progressText: statusMessage || "Processing..." });
77
+ this.review.statusMessage = "Swap successful";
78
+ this.review.status = "success";
79
+ });
80
+ }
81
+
82
+ processing() {
83
+ return this.processingTask;
84
+ }
85
+
86
+ async _processing() {
87
+ if (this.review.qoute === "deposit" || this.review.qoute === "withdraw") return this.review;
88
+
89
+ if (!(this.review.recipient instanceof OmniWallet)) return await this.waitStatus();
90
+ const beforeBalance = await this.review.recipient.fetchBalance(this.review.to.chain, this.review.to.address).catch(() => null);
91
+ if (!beforeBalance) return await this.waitStatus();
92
+
93
+ return await Promise.race([
94
+ this.waitBalance(this.review.to, this.review.recipient, beforeBalance, this.review), //
95
+ this.waitStatus(),
96
+ ]);
97
+ }
98
+
99
+ async waitBalance(to: Token, wallet: OmniWallet, beforeBalance: bigint, review: BridgeReview): Promise<BridgeReview> {
100
+ const afterBalance = await wallet.fetchBalance(to.chain, to.address).catch(() => beforeBalance);
101
+ if (afterBalance > beforeBalance) {
102
+ return runInAction(() => {
103
+ this.review.amountOut = afterBalance - beforeBalance;
104
+ this.updateStatus("success", "Swap successful");
105
+ this.toast?.update({ duration: 2000 });
106
+ return this.review;
107
+ });
108
+ }
109
+
110
+ await wait(2000);
111
+ return await this.waitBalance(to, wallet, beforeBalance, review);
112
+ }
113
+
114
+ getMessage(status: GetExecutionStatusResponse.status): string | null {
115
+ if (status === GetExecutionStatusResponse.status.PENDING_DEPOSIT) return "Waiting for deposit";
116
+ if (status === GetExecutionStatusResponse.status.INCOMPLETE_DEPOSIT) return "Incomplete deposit";
117
+ if (status === GetExecutionStatusResponse.status.KNOWN_DEPOSIT_TX) return "Known deposit tx";
118
+ if (status === GetExecutionStatusResponse.status.PROCESSING) return "Processing swap";
119
+ if (status === GetExecutionStatusResponse.status.SUCCESS) return "Swap successful";
120
+ if (status === GetExecutionStatusResponse.status.FAILED) return "Swap failed";
121
+ if (status === GetExecutionStatusResponse.status.REFUNDED) return "Swap refunded";
122
+ return null;
123
+ }
124
+
125
+ async checkStatus() {
126
+ if (this.review.qoute === "deposit" || this.review.qoute === "withdraw") return;
127
+ const status = await OneClickService.getExecutionStatus(this.review.qoute.depositAddress!, this.review.qoute.depositMemo);
128
+ const message = this.getMessage(status.status);
129
+
130
+ let state: "pending" | "success" | "failed" = "pending";
131
+ if (status.status === GetExecutionStatusResponse.status.SUCCESS) state = "success";
132
+ if (status.status === GetExecutionStatusResponse.status.FAILED) state = "failed";
133
+ if (status.status === GetExecutionStatusResponse.status.REFUNDED) state = "failed";
134
+
135
+ runInAction(() => {
136
+ if (status.swapDetails.amountOut) this.review.amountOut = BigInt(status.swapDetails.amountOut);
137
+ this.updateStatus(state, message);
138
+ });
139
+ }
140
+
141
+ async waitStatus(interval = 3000) {
142
+ while (this.status === "pending") {
143
+ await this.checkStatus();
144
+ await new Promise((resolve) => setTimeout(resolve, interval));
145
+ }
146
+
147
+ if (this.status === "success") return this.review;
148
+ if (this.status === "failed") throw this.subtitle || "Bridge failed";
149
+ throw new Error("Unknown status");
150
+ }
151
+ }
@@ -1,5 +1,5 @@
1
1
  import { api } from "./api";
2
- import { HotConnector } from "../HotConnector";
2
+ import { HotKit } from "../HotKit";
3
3
  import { formatter } from "./utils";
4
4
 
5
5
  export interface ILogger {
@@ -8,7 +8,7 @@ export interface ILogger {
8
8
 
9
9
  export class Telemetry {
10
10
  events: { event: string; value_str?: string; value_float?: number; ts: number }[] = [];
11
- constructor(readonly wibe3: HotConnector) {
11
+ constructor(readonly kit: HotKit) {
12
12
  this.flush();
13
13
  }
14
14
 
@@ -17,7 +17,7 @@ export class Telemetry {
17
17
 
18
18
  if (this.events.length > 0) {
19
19
  await api
20
- .publishTelemetry(this.events, this.wibe3.priorityWallet?.address ?? "")
20
+ .publishTelemetry(this.events, this.kit.priorityWallet?.address ?? "")
21
21
  .then(() => (this.events = []))
22
22
  .catch(() => {});
23
23
  }
@@ -11,7 +11,7 @@ import { chains, WalletType } from "../core/chains";
11
11
  import { OmniWallet } from "../core/OmniWallet";
12
12
  import { api } from "../core/api";
13
13
 
14
- import type { HotConnector } from "../HotConnector";
14
+ import type { HotKit } from "../HotKit";
15
15
  import { signAndSendTx } from "./helpers";
16
16
  import CosmosWallet from "./wallet";
17
17
 
@@ -56,8 +56,8 @@ export default class CosmosConnector extends OmniConnector<CosmosWallet> {
56
56
  isSupported = true;
57
57
  id = "cosmos";
58
58
 
59
- constructor(wibe3: HotConnector, readonly chainId = "gonka-mainnet") {
60
- super(wibe3);
59
+ constructor(kit: HotKit, readonly chainId = "gonka-mainnet") {
60
+ super(kit);
61
61
 
62
62
  this.options = Object.values(wallets);
63
63
  Keplr.getKeplr().then((keplr) => {
@@ -1,10 +1,10 @@
1
1
  import CosmosConnector from "./connector";
2
2
  import CosmosWallet from "./wallet";
3
3
 
4
- import { HotConnector } from "../HotConnector";
4
+ import { HotKit } from "../HotKit";
5
5
 
6
6
  export { CosmosConnector, CosmosWallet };
7
7
 
8
8
  export default ({ chainId }: { chainId?: string } = {}) =>
9
- async (wibe3: HotConnector) =>
10
- new CosmosConnector(wibe3, chainId);
9
+ async (kit: HotKit) =>
10
+ new CosmosConnector(kit, chainId);
@@ -1,7 +1,7 @@
1
1
  import { runInAction } from "mobx";
2
2
 
3
3
  import HOT from "../hot-wallet/iframe";
4
- import type { HotConnector } from "../HotConnector";
4
+ import type { HotKit } from "../HotKit";
5
5
 
6
6
  import { Network, WalletType } from "../core/chains";
7
7
  import { ConnectorType, OmniConnector, WC_ICON } from "../core/OmniConnector";
@@ -15,8 +15,8 @@ class EvmConnector extends OmniConnector<EvmWallet, { provider: EvmProvider }> {
15
15
  name = "EVM Wallet";
16
16
  id = "evm";
17
17
 
18
- constructor(wibe3: HotConnector) {
19
- super(wibe3);
18
+ constructor(kit: HotKit) {
19
+ super(kit);
20
20
 
21
21
  window.addEventListener<any>("eip6963:announceProvider", async (provider) => {
22
22
  if (this.options.find((t) => t.name === provider.detail.info.name || t.id === provider.detail.info.uuid)) return;
package/src/evm/index.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import EvmConnector from "./connector";
2
- import { HotConnector } from "../HotConnector";
2
+ import { HotKit } from "../HotKit";
3
3
 
4
4
  export { default as EvmConnector } from "./connector";
5
5
  export { default as EvmWallet } from "./wallet";
6
6
  import "./injected";
7
7
 
8
- export default () => async (wibe3: HotConnector) => new EvmConnector(wibe3);
8
+ export default () => async (kit: HotKit) => new EvmConnector(kit);
@@ -1,7 +1,7 @@
1
1
  import { ConnectorType, OmniConnector } from "../core/OmniConnector";
2
2
  import { Network, WalletType } from "../core/chains";
3
3
  import { OmniWallet } from "../core/OmniWallet";
4
- import { HotConnector } from "../HotConnector";
4
+ import { HotKit } from "../HotKit";
5
5
  import HotCraftWallet from "./wallet";
6
6
 
7
7
  export default class HotCraftConnector extends OmniConnector<HotCraftWallet> {
@@ -11,18 +11,18 @@ export default class HotCraftConnector extends OmniConnector<HotCraftWallet> {
11
11
  name = "HotCraft";
12
12
  id = "hotcraft";
13
13
 
14
- constructor(readonly wibe3: HotConnector) {
15
- super(wibe3);
14
+ constructor(readonly kit: HotKit) {
15
+ super(kit);
16
16
 
17
- wibe3.onConnect(async ({ wallet }) => {
17
+ kit.onConnect(async ({ wallet }) => {
18
18
  if (wallet.type === WalletType.HotCraft) return;
19
- const craftWallet = new HotCraftWallet(wallet, wibe3.storage);
19
+ const craftWallet = new HotCraftWallet(wallet, kit.storage);
20
20
  const balances = await craftWallet.fetchBalances(Network.HotCraft);
21
21
  if (Object.values(balances).some((balance) => balance === 0n)) return;
22
22
  this.setWallet({ wallet: craftWallet, isNew: false });
23
23
  });
24
24
 
25
- wibe3.onDisconnect(async ({ wallet }) => {
25
+ kit.onDisconnect(async ({ wallet }) => {
26
26
  if (wallet.type === WalletType.HotCraft) return;
27
27
  const craftWallet = this.wallets.find((t) => t.wallet === wallet);
28
28
  if (craftWallet) this.removeWallet(craftWallet);
@@ -1,7 +1,7 @@
1
- import { HotConnector } from "../HotConnector";
1
+ import { HotKit } from "../HotKit";
2
2
  import HotCraftConnector from "./connector";
3
3
  import HotCraftWallet from "./wallet";
4
4
 
5
5
  export { HotCraftConnector, HotCraftWallet };
6
6
 
7
- export default () => async (wibe3: HotConnector) => new HotCraftConnector(wibe3);
7
+ export default () => async (kit: HotKit) => new HotCraftConnector(kit);
@@ -12,7 +12,7 @@ import TonWallet from "../ton/wallet";
12
12
  import NearWallet from "../near/wallet";
13
13
  import SolanaWallet from "../solana/wallet";
14
14
  import StellarWallet from "../stellar/wallet";
15
- import { HotConnector } from "../HotConnector";
15
+ import { HotKit } from "../HotKit";
16
16
 
17
17
  export interface GoogleConnectorOptions {
18
18
  webWallet?: string;
@@ -26,8 +26,8 @@ class GoogleConnector extends OmniConnector<OmniWallet> {
26
26
  id = "google";
27
27
  webWallet: string;
28
28
 
29
- constructor(wibe3: HotConnector, options?: GoogleConnectorOptions) {
30
- super(wibe3);
29
+ constructor(kit: HotKit, options?: GoogleConnectorOptions) {
30
+ super(kit);
31
31
 
32
32
  this.webWallet = options?.webWallet ?? "https://app.hot-labs.org";
33
33
  makeObservable(this, { connectWallet: action });
@@ -42,7 +42,7 @@ class GoogleConnector extends OmniConnector<OmniWallet> {
42
42
  const height = 640;
43
43
  const x = (window.screen.width - width) / 2;
44
44
  const y = (window.screen.height - height) / 2;
45
- return window.open(`${this.wibe3.settings.webWallet}`, "_blank", `popup=1,width=${width},height=${height},top=${y},left=${x}`);
45
+ return window.open(`${this.kit.settings.webWallet}`, "_blank", `popup=1,width=${width},height=${height},top=${y},left=${x}`);
46
46
  }
47
47
 
48
48
  connectWallet({ account, isNew }: { account: { type: number; address: string; publicKey: string }; isNew: boolean }) {
@@ -57,7 +57,7 @@ class GoogleConnector extends OmniConnector<OmniWallet> {
57
57
  const signMessage = async (message: string) => request("stellar:signMessage", { message });
58
58
  const signTransaction = async (transaction: Transaction) => request("stellar:signTransaction", { transaction: transaction.toXDR() });
59
59
  const wallet = new StellarWallet({
60
- rpc: this.wibe3.exchange.bridge.stellar,
60
+ rpc: this.kit.exchange.bridge.stellar,
61
61
  address: account.address,
62
62
  signTransaction,
63
63
  signMessage,
@@ -122,7 +122,7 @@ class GoogleConnector extends OmniConnector<OmniWallet> {
122
122
 
123
123
  const id = uuid4();
124
124
  const handler = (event: MessageEvent) => {
125
- if (event.origin !== this.wibe3.settings.webWallet) return;
125
+ if (event.origin !== this.kit.settings.webWallet) return;
126
126
 
127
127
  if (event.data === "hot:ready") {
128
128
  popup?.postMessage({ chain, address, method, request, id }, "*");
@@ -1,7 +1,7 @@
1
1
  import GoogleConnector, { GoogleConnectorOptions } from "./google";
2
- import { HotConnector } from "../HotConnector";
2
+ import { HotKit } from "../HotKit";
3
3
 
4
4
  export type { GoogleConnectorOptions };
5
5
  export { GoogleConnector };
6
6
 
7
- export default (options?: GoogleConnectorOptions) => async (wibe3: HotConnector) => new GoogleConnector(wibe3, options);
7
+ export default (options?: GoogleConnectorOptions) => async (kit: HotKit) => new GoogleConnector(kit, options);
package/src/index.ts CHANGED
@@ -1,4 +1,9 @@
1
1
  import "@lottiefiles/dotlottie-wc";
2
2
 
3
3
  export * from "./core";
4
- export { HotConnector } from "./HotConnector";
4
+ import { HotKit } from "./HotKit";
5
+
6
+ export { HotKit };
7
+
8
+ // Alias for backward compatibility
9
+ export const HotConnector = HotKit;