@hot-labs/kit 1.2.0-alpha.2 → 1.2.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.
Files changed (280) hide show
  1. package/README.md +2 -9
  2. package/build/HotConnector.d.ts +8 -7
  3. package/build/HotConnector.js +21 -24
  4. package/build/HotConnector.js.map +1 -1
  5. package/build/OmniConnector.d.ts +5 -0
  6. package/build/OmniConnector.js +5 -5
  7. package/build/OmniConnector.js.map +1 -1
  8. package/build/OmniWallet.d.ts +10 -17
  9. package/build/OmniWallet.js +14 -19
  10. package/build/OmniWallet.js.map +1 -1
  11. package/build/core/Intents.d.ts +53 -43
  12. package/build/core/Intents.js +207 -133
  13. package/build/core/Intents.js.map +1 -1
  14. package/build/core/api.d.ts +30 -2
  15. package/build/core/api.js +43 -10
  16. package/build/core/api.js.map +1 -1
  17. package/build/core/bridge.js +1 -1
  18. package/build/core/bridge.js.map +1 -1
  19. package/build/core/index.d.ts +1 -1
  20. package/build/core/index.js +1 -1
  21. package/build/core/index.js.map +1 -1
  22. package/build/core/telemetry.d.ts +13 -0
  23. package/build/core/telemetry.js +27 -0
  24. package/build/core/telemetry.js.map +1 -0
  25. package/build/core/token.d.ts +1 -0
  26. package/build/core/token.js +3 -0
  27. package/build/core/token.js.map +1 -1
  28. package/build/core/tokens.js +0 -8
  29. package/build/core/tokens.js.map +1 -1
  30. package/build/core/types.d.ts +17 -0
  31. package/build/core/utils.d.ts +1 -0
  32. package/build/core/utils.js +21 -1
  33. package/build/core/utils.js.map +1 -1
  34. package/build/cosmos/connector.d.ts +2 -2
  35. package/build/cosmos/connector.js +17 -21
  36. package/build/cosmos/connector.js.map +1 -1
  37. package/build/cosmos/wallet.d.ts +2 -4
  38. package/build/cosmos/wallet.js +3 -8
  39. package/build/cosmos/wallet.js.map +1 -1
  40. package/build/evm/connector.d.ts +1 -0
  41. package/build/evm/connector.js +4 -0
  42. package/build/evm/connector.js.map +1 -1
  43. package/build/evm/wallet.d.ts +2 -1
  44. package/build/evm/wallet.js +7 -5
  45. package/build/evm/wallet.js.map +1 -1
  46. package/build/exchange.d.ts +6 -1
  47. package/build/exchange.js +34 -33
  48. package/build/exchange.js.map +1 -1
  49. package/build/hot-wallet/google.js +10 -5
  50. package/build/hot-wallet/google.js.map +1 -1
  51. package/build/hot-wallet/proxy.js +2 -2
  52. package/build/hot-wallet/proxy.js.map +1 -1
  53. package/build/index.d.ts +2 -1
  54. package/build/index.js +2 -1
  55. package/build/index.js.map +1 -1
  56. package/build/near/connector.js +2 -2
  57. package/build/near/connector.js.map +1 -1
  58. package/build/{core/nearRpc.d.ts → near/rpc.d.ts} +0 -1
  59. package/build/{core/nearRpc.js → near/rpc.js} +8 -22
  60. package/build/near/rpc.js.map +1 -0
  61. package/build/near/wallet.d.ts +4 -4
  62. package/build/near/wallet.js +36 -30
  63. package/build/near/wallet.js.map +1 -1
  64. package/build/solana/{protocol.d.ts → WalletStandard.d.ts} +1 -1
  65. package/build/solana/{protocol.js → WalletStandard.js} +1 -1
  66. package/build/solana/WalletStandard.js.map +1 -0
  67. package/build/solana/connector.d.ts +1 -1
  68. package/build/solana/connector.js +9 -8
  69. package/build/solana/connector.js.map +1 -1
  70. package/build/solana/injected/solana-wallet.js.map +1 -1
  71. package/build/solana/wallet.d.ts +5 -7
  72. package/build/solana/wallet.js +8 -17
  73. package/build/solana/wallet.js.map +1 -1
  74. package/build/solana/{wallets.js → walletStandartList.js} +1 -1
  75. package/build/solana/walletStandartList.js.map +1 -0
  76. package/build/stellar/connector.d.ts +0 -2
  77. package/build/stellar/connector.js +1 -4
  78. package/build/stellar/connector.js.map +1 -1
  79. package/build/stellar/wallet.d.ts +10 -8
  80. package/build/stellar/wallet.js +12 -16
  81. package/build/stellar/wallet.js.map +1 -1
  82. package/build/ton/connector.d.ts +0 -1
  83. package/build/ton/connector.js +1 -4
  84. package/build/ton/connector.js.map +1 -1
  85. package/build/ton/wallet.d.ts +2 -3
  86. package/build/ton/wallet.js +3 -4
  87. package/build/ton/wallet.js.map +1 -1
  88. package/build/tron/connector.d.ts +51 -0
  89. package/build/tron/connector.js +65 -0
  90. package/build/tron/connector.js.map +1 -0
  91. package/build/tron/index.d.ts +6 -0
  92. package/build/tron/index.js +5 -0
  93. package/build/tron/index.js.map +1 -0
  94. package/build/tron/wallet.d.ts +52 -0
  95. package/build/tron/wallet.js +122 -0
  96. package/build/tron/wallet.js.map +1 -0
  97. package/build/ui/Popup.d.ts +2 -2
  98. package/build/ui/Popup.js +5 -1
  99. package/build/ui/Popup.js.map +1 -1
  100. package/build/ui/bridge/Bridge.js +389 -0
  101. package/build/ui/bridge/Bridge.js.map +1 -0
  102. package/build/ui/{payment → bridge}/SelectRecipient.js +3 -3
  103. package/build/ui/bridge/SelectRecipient.js.map +1 -0
  104. package/build/ui/{payment → bridge}/SelectSender.js +2 -2
  105. package/build/ui/bridge/SelectSender.js.map +1 -0
  106. package/build/ui/{payment → bridge}/SelectToken.js +4 -3
  107. package/build/ui/bridge/SelectToken.js.map +1 -0
  108. package/build/ui/{payment → bridge}/TokenCard.d.ts +7 -9
  109. package/build/ui/bridge/TokenCard.js +65 -0
  110. package/build/ui/bridge/TokenCard.js.map +1 -0
  111. package/build/ui/connect/AuthPopup.js +1 -1
  112. package/build/ui/connect/AuthPopup.js.map +1 -1
  113. package/build/ui/connect/ConnectWallet.d.ts +7 -2
  114. package/build/ui/connect/ConnectWallet.js +7 -7
  115. package/build/ui/connect/ConnectWallet.js.map +1 -1
  116. package/build/ui/connect/PrimaryWallet.d.ts +6 -0
  117. package/build/ui/connect/PrimaryWallet.js +18 -0
  118. package/build/ui/connect/PrimaryWallet.js.map +1 -0
  119. package/build/ui/connect/WCRequest.js +1 -1
  120. package/build/ui/connect/WCRequest.js.map +1 -1
  121. package/build/ui/connect/WalletPicker.js +1 -1
  122. package/build/ui/connect/WalletPicker.js.map +1 -1
  123. package/build/ui/icons/arrow-right.d.ts +3 -1
  124. package/build/ui/icons/arrow-right.js +3 -3
  125. package/build/ui/icons/arrow-right.js.map +1 -1
  126. package/build/ui/icons/close.js +1 -1
  127. package/build/ui/icons/close.js.map +1 -1
  128. package/build/ui/icons/exchange.d.ts +3 -4
  129. package/build/ui/icons/exchange.js +2 -2
  130. package/build/ui/icons/exchange.js.map +1 -1
  131. package/build/ui/icons/logout.js +1 -1
  132. package/build/ui/icons/logout.js.map +1 -1
  133. package/build/ui/icons/pending.js +1 -1
  134. package/build/ui/icons/pending.js.map +1 -1
  135. package/build/ui/icons/plus.d.ts +2 -0
  136. package/build/ui/icons/plus.js +6 -0
  137. package/build/ui/icons/plus.js.map +1 -0
  138. package/build/ui/icons/qr.js +1 -1
  139. package/build/ui/icons/qr.js.map +1 -1
  140. package/build/ui/icons/refresh.d.ts +2 -0
  141. package/build/ui/icons/refresh.js +6 -0
  142. package/build/ui/icons/refresh.js.map +1 -0
  143. package/build/ui/icons/search.js +1 -1
  144. package/build/ui/icons/search.js.map +1 -1
  145. package/build/ui/icons/switch.js +1 -1
  146. package/build/ui/icons/switch.js.map +1 -1
  147. package/build/ui/icons/wallet.js +1 -1
  148. package/build/ui/icons/wallet.js.map +1 -1
  149. package/build/ui/{payment → profile}/DepositQR.js.map +1 -1
  150. package/build/ui/profile/Payment.d.ts +23 -0
  151. package/build/ui/profile/Payment.js +154 -0
  152. package/build/ui/profile/Payment.js.map +1 -0
  153. package/build/ui/profile/Profile.d.ts +7 -0
  154. package/build/ui/profile/Profile.js +135 -0
  155. package/build/ui/profile/Profile.js.map +1 -0
  156. package/build/ui/router.d.ts +19 -5
  157. package/build/ui/router.js +21 -9
  158. package/build/ui/router.js.map +1 -1
  159. package/build/ui/styles.js +4 -11
  160. package/build/ui/styles.js.map +1 -1
  161. package/build/ui/uikit/Stepper.d.ts +13 -0
  162. package/build/ui/uikit/Stepper.js +23 -0
  163. package/build/ui/uikit/Stepper.js.map +1 -0
  164. package/build/ui/uikit/Toast.d.ts +4 -0
  165. package/build/ui/uikit/Toast.js +33 -0
  166. package/build/ui/uikit/Toast.js.map +1 -0
  167. package/build/ui/uikit/button.d.ts +2 -0
  168. package/build/ui/uikit/button.js +52 -0
  169. package/build/ui/uikit/button.js.map +1 -0
  170. package/build/ui/uikit/image.d.ts +6 -0
  171. package/build/ui/uikit/image.js +38 -0
  172. package/build/ui/uikit/image.js.map +1 -0
  173. package/build/ui/uikit/loader.d.ts +2 -0
  174. package/build/ui/uikit/loader.js +50 -0
  175. package/build/ui/uikit/loader.js.map +1 -0
  176. package/build/ui/uikit/tabs.d.ts +12 -0
  177. package/build/ui/uikit/tabs.js +35 -0
  178. package/build/ui/uikit/tabs.js.map +1 -0
  179. package/build/ui/uikit/text.d.ts +7 -0
  180. package/build/ui/uikit/text.js +68 -0
  181. package/build/ui/uikit/text.js.map +1 -0
  182. package/build/ui/utils.d.ts +1 -0
  183. package/build/ui/utils.js +20 -0
  184. package/build/ui/utils.js.map +1 -0
  185. package/package.json +8 -4
  186. package/src/HotConnector.ts +24 -31
  187. package/src/OmniConnector.ts +10 -9
  188. package/src/OmniWallet.ts +24 -25
  189. package/src/core/Intents.ts +222 -151
  190. package/src/core/api.ts +56 -10
  191. package/src/core/bridge.ts +3 -2
  192. package/src/core/index.ts +1 -1
  193. package/src/core/telemetry.ts +28 -0
  194. package/src/core/token.ts +4 -0
  195. package/src/core/tokens.ts +0 -9
  196. package/src/core/types.ts +21 -0
  197. package/src/core/utils.ts +17 -1
  198. package/src/cosmos/connector.ts +22 -26
  199. package/src/cosmos/wallet.ts +3 -8
  200. package/src/evm/connector.ts +5 -0
  201. package/src/evm/wallet.ts +9 -6
  202. package/src/exchange.ts +36 -33
  203. package/src/hot-wallet/google.ts +12 -5
  204. package/src/hot-wallet/proxy.ts +2 -2
  205. package/src/index.ts +3 -1
  206. package/src/near/connector.ts +2 -2
  207. package/src/{core/nearRpc.ts → near/rpc.ts} +9 -23
  208. package/src/near/wallet.ts +39 -31
  209. package/src/solana/{protocol.ts → WalletStandard.ts} +2 -4
  210. package/src/solana/connector.ts +9 -8
  211. package/src/solana/injected/solana-wallet.ts +6 -6
  212. package/src/solana/wallet.ts +11 -20
  213. package/src/stellar/connector.ts +1 -6
  214. package/src/stellar/wallet.ts +17 -17
  215. package/src/ton/connector.ts +1 -5
  216. package/src/ton/wallet.ts +3 -3
  217. package/src/tron/connector.ts +89 -0
  218. package/src/tron/index.ts +7 -0
  219. package/src/tron/wallet.ts +146 -0
  220. package/src/ui/Popup.tsx +12 -4
  221. package/src/ui/{payment → bridge}/Bridge.tsx +266 -212
  222. package/src/ui/{payment → bridge}/SelectRecipient.tsx +5 -4
  223. package/src/ui/{payment → bridge}/SelectSender.tsx +5 -5
  224. package/src/ui/{payment → bridge}/SelectToken.tsx +6 -4
  225. package/src/ui/bridge/TokenCard.tsx +99 -0
  226. package/src/ui/connect/AuthPopup.tsx +1 -1
  227. package/src/ui/connect/ConnectWallet.tsx +16 -10
  228. package/src/ui/connect/PrimaryWallet.tsx +65 -0
  229. package/src/ui/connect/WCRequest.tsx +1 -1
  230. package/src/ui/connect/WalletPicker.tsx +1 -1
  231. package/src/ui/icons/arrow-right.tsx +3 -4
  232. package/src/ui/icons/close.tsx +1 -1
  233. package/src/ui/icons/exchange.tsx +4 -11
  234. package/src/ui/icons/logout.tsx +4 -13
  235. package/src/ui/icons/pending.tsx +2 -4
  236. package/src/ui/icons/plus.tsx +12 -0
  237. package/src/ui/icons/qr.tsx +1 -2
  238. package/src/ui/icons/refresh.tsx +20 -0
  239. package/src/ui/icons/search.tsx +4 -4
  240. package/src/ui/icons/switch.tsx +4 -4
  241. package/src/ui/icons/wallet.tsx +2 -4
  242. package/src/ui/profile/Payment.tsx +329 -0
  243. package/src/ui/{payment → profile}/Profile.tsx +110 -70
  244. package/src/ui/router.tsx +57 -17
  245. package/src/ui/styles.ts +4 -11
  246. package/src/ui/uikit/Stepper.tsx +51 -0
  247. package/src/ui/uikit/Toast.tsx +45 -0
  248. package/src/ui/uikit/button.tsx +53 -0
  249. package/src/ui/uikit/image.tsx +45 -0
  250. package/src/ui/uikit/loader.tsx +52 -0
  251. package/src/ui/uikit/tabs.tsx +56 -0
  252. package/src/ui/uikit/text.tsx +74 -0
  253. package/src/ui/utils.ts +14 -0
  254. package/build/core/nearRpc.js.map +0 -1
  255. package/build/solana/protocol.js.map +0 -1
  256. package/build/solana/wallets.js.map +0 -1
  257. package/build/ui/payment/Bridge.js +0 -358
  258. package/build/ui/payment/Bridge.js.map +0 -1
  259. package/build/ui/payment/Payment.d.ts +0 -16
  260. package/build/ui/payment/Payment.js +0 -50
  261. package/build/ui/payment/Payment.js.map +0 -1
  262. package/build/ui/payment/Profile.d.ts +0 -8
  263. package/build/ui/payment/Profile.js +0 -110
  264. package/build/ui/payment/Profile.js.map +0 -1
  265. package/build/ui/payment/SelectRecipient.js.map +0 -1
  266. package/build/ui/payment/SelectSender.js.map +0 -1
  267. package/build/ui/payment/SelectToken.js.map +0 -1
  268. package/build/ui/payment/TokenCard.js +0 -63
  269. package/build/ui/payment/TokenCard.js.map +0 -1
  270. package/src/ui/payment/Payment.tsx +0 -79
  271. package/src/ui/payment/TokenCard.tsx +0 -98
  272. package/build/solana/{wallets.d.ts → walletStandartList.d.ts} +0 -0
  273. package/build/ui/{payment → bridge}/Bridge.d.ts +3 -3
  274. package/build/ui/{payment → bridge}/SelectRecipient.d.ts +0 -0
  275. package/build/ui/{payment → bridge}/SelectSender.d.ts +2 -2
  276. package/build/ui/{payment → bridge}/SelectToken.d.ts +1 -1
  277. /package/build/ui/{payment → profile}/DepositQR.d.ts +0 -0
  278. /package/build/ui/{payment → profile}/DepositQR.js +0 -0
  279. /package/src/solana/{wallets.ts → walletStandartList.ts} +0 -0
  280. /package/src/ui/{payment → profile}/DepositQR.tsx +0 -0
@@ -0,0 +1,89 @@
1
+ import { WalletType } from "../core/chains";
2
+ import { ConnectorType, OmniConnector } from "../OmniConnector";
3
+ import { HotConnector } from "../HotConnector";
4
+ import TronWallet from "./wallet";
5
+
6
+ declare global {
7
+ interface Window {
8
+ tronLink?: {
9
+ ready?: boolean;
10
+ request?: (args: { method: string; params?: any }) => Promise<any>;
11
+ tronWeb?: {
12
+ defaultAddress?: { base58?: string; hex?: string };
13
+ address?: { toHex?: (address: string) => string };
14
+ contract?: () => { at: (address: string) => Promise<any> };
15
+ trx?: {
16
+ getBalance?: (address: string) => Promise<number | string>;
17
+ sendTransaction?: (to: string, amount: number | string) => Promise<any>;
18
+ signMessageV2?: (message: string) => Promise<string>;
19
+ signMessage?: (message: string) => Promise<string>;
20
+ };
21
+ };
22
+ };
23
+ }
24
+ }
25
+
26
+ const TRONLINK = {
27
+ id: "tronlink",
28
+ name: "Tron Link",
29
+ type: window?.tronLink ? ("extension" as const) : ("external" as const),
30
+ icon: "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png",
31
+ download: "https://www.tronlink.org/",
32
+ };
33
+
34
+ class TronConnector extends OmniConnector<TronWallet> {
35
+ type = ConnectorType.WALLET;
36
+ walletTypes = [WalletType.Tron, WalletType.OMNI];
37
+ icon = "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/tron/info/logo.png";
38
+ name = "TRON Wallet";
39
+ options = [TRONLINK];
40
+ id = "tron";
41
+
42
+ constructor(wibe3: HotConnector) {
43
+ super(wibe3);
44
+
45
+ this.syncFromProvider().catch(() => this.removeStorage());
46
+ window.addEventListener("message", () => {
47
+ this.syncFromProvider().catch(() => {});
48
+ });
49
+ }
50
+
51
+ private async syncFromProvider() {
52
+ const stored = (await this.getStorage().catch(() => ({} as any))) as { type?: string; id?: string; address?: string };
53
+ if (stored.type !== "wallet" || stored.id !== TRONLINK.id) return;
54
+
55
+ const tronWeb = window?.tronLink?.tronWeb;
56
+ const address = tronWeb?.defaultAddress?.base58;
57
+ if (!window?.tronLink?.ready || !address) return;
58
+
59
+ const current = this.wallets[0]?.address;
60
+ if (current === address) return;
61
+
62
+ if (this.wallets.length > 0) this.removeWallet();
63
+ await this.setStorage({ type: "wallet", id: TRONLINK.id, address });
64
+ this.setWallet(new TronWallet(this, address, tronWeb as any));
65
+ }
66
+
67
+ async connect(id: string = TRONLINK.id) {
68
+ if (id !== TRONLINK.id) throw new Error("Wallet not found");
69
+
70
+ try {
71
+ if (this.wallets.length > 0) this.removeWallet();
72
+
73
+ const res = await window?.tronLink?.request?.({ method: "tron_requestAccounts" });
74
+ if (res?.code !== 200) throw new Error("Failed to connect to TronLink");
75
+ if (!window?.tronLink?.tronWeb) throw new Error("TronLink not found");
76
+
77
+ const address = window?.tronLink?.tronWeb?.defaultAddress?.base58;
78
+ if (!address) throw new Error("No account found");
79
+
80
+ await this.setStorage({ type: "wallet", id: TRONLINK.id, address });
81
+ return this.setWallet(new TronWallet(this, address, window.tronLink.tronWeb));
82
+ } catch (e) {
83
+ await this.removeStorage();
84
+ throw e;
85
+ }
86
+ }
87
+ }
88
+
89
+ export default TronConnector;
@@ -0,0 +1,7 @@
1
+ import { HotConnector } from "../HotConnector";
2
+ import TronConnector from "./connector";
3
+ import TronWallet from "./wallet";
4
+
5
+ export { TronConnector, TronWallet };
6
+
7
+ export default () => async (wibe3: HotConnector) => new TronConnector(wibe3);
@@ -0,0 +1,146 @@
1
+ import { base58, base64, hex } from "@scure/base";
2
+
3
+ import { Network, WalletType } from "../core/chains";
4
+ import { ReviewFee } from "../core/bridge";
5
+ import { Token } from "../core/token";
6
+ import { Commitment } from "../core";
7
+
8
+ import type { OmniConnector } from "../OmniConnector";
9
+ import { OmniWallet } from "../OmniWallet";
10
+
11
+ interface TronWebLike {
12
+ ready?: boolean;
13
+ defaultAddress?: { base58?: string; hex?: string };
14
+ address?: { toHex?: (address: string) => string };
15
+ trx?: {
16
+ getBalance?: (address: string) => Promise<number | string>;
17
+ sendTransaction?: (to: string, amount: number | string) => Promise<any>;
18
+ signMessageV2?: (message: string) => Promise<string>;
19
+ signMessage?: (message: string) => Promise<string>;
20
+ };
21
+ contract?: () => { at: (address: string) => Promise<any> };
22
+ }
23
+
24
+ class TronWallet extends OmniWallet {
25
+ readonly publicKey?: string;
26
+ readonly type = WalletType.Tron;
27
+
28
+ constructor(readonly connector: OmniConnector, readonly address: string, readonly tronWeb: TronWebLike) {
29
+ super();
30
+ }
31
+
32
+ get icon() {
33
+ return this.connector.icon;
34
+ }
35
+
36
+ get omniAddress() {
37
+ // Convert TRON base58 address -> EVM-like hex (0x + 20 bytes) for signer_id.
38
+ const hexAddrRaw =
39
+ this.tronWeb.address?.toHex?.(this.address) || //
40
+ this.tronWeb.defaultAddress?.hex ||
41
+ "";
42
+
43
+ const clean = hexAddrRaw.startsWith("0x") ? hexAddrRaw.slice(2) : hexAddrRaw;
44
+ if (!clean) return this.address.toLowerCase();
45
+
46
+ // Tron addresses are typically: 41 + 20 bytes (hex).
47
+ if (clean.length >= 42 && clean.startsWith("41")) return `0x${clean.slice(2, 42)}`.toLowerCase();
48
+ if (clean.length === 40) return `0x${clean}`.toLowerCase();
49
+ return `0x${clean}`.toLowerCase();
50
+ }
51
+
52
+ private async trc20Balance(contractAddress: string): Promise<bigint> {
53
+ if (!this.tronWeb.contract) throw new Error("TronLink not available");
54
+ const contract = await this.tronWeb.contract().at(contractAddress);
55
+ const res = await contract.balanceOf(this.address).call();
56
+ const value = typeof res === "string" ? res : res?._hex ?? res?.toString?.() ?? "0";
57
+ return BigInt(value);
58
+ }
59
+
60
+ async fetchBalance(chain: number, address: string): Promise<bigint> {
61
+ if (chain !== Network.Tron) throw "Invalid chain";
62
+ if (!this.tronWeb.trx) throw new Error("TronLink not available");
63
+
64
+ if (address === "native") {
65
+ const balance = await this.tronWeb.trx.getBalance?.(this.address);
66
+ return BigInt(balance || 0);
67
+ }
68
+
69
+ return await this.trc20Balance(address);
70
+ }
71
+
72
+ async fetchBalances(chain: number, whitelist: string[]): Promise<Record<string, bigint>> {
73
+ const native = await this.fetchBalance(chain, "native");
74
+
75
+ try {
76
+ const res = await fetch(`https://api0.herewallet.app/api/v1/user/balances/${chain}/${this.address}`, { body: JSON.stringify({ whitelist, chain_id: chain }), method: "POST" });
77
+ if (!res.ok) throw new Error("Failed to fetch balances");
78
+ const { balances } = await res.json();
79
+ return { ...balances, native };
80
+ } catch {
81
+ const balances = await Promise.all(
82
+ whitelist.map(async (token) => {
83
+ const balance = await this.fetchBalance(chain, token);
84
+ return [token, balance] as const;
85
+ })
86
+ );
87
+ return { ...Object.fromEntries(balances), native };
88
+ }
89
+ }
90
+
91
+ async transferFee(token: Token): Promise<ReviewFee> {
92
+ // Tron fees depend on bandwidth/energy; for UX we return "0" and let wallet handle it.
93
+ return new ReviewFee({ baseFee: 0n, gasLimit: 0n, chain: token.chain });
94
+ }
95
+
96
+ async transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee?: ReviewFee }): Promise<string> {
97
+ if (!this.tronWeb.trx) throw new Error("TronLink not available");
98
+
99
+ if (args.token.address === "native") {
100
+ const result = await this.tronWeb.trx.sendTransaction?.(args.receiver, args.amount.toString());
101
+ return result?.txid || result?.transaction?.txID || result?.txID || result?.id || "";
102
+ }
103
+
104
+ if (!this.tronWeb.contract) throw new Error("TronLink not available");
105
+ const contract = await this.tronWeb.contract().at(args.token.address);
106
+ const result = await contract.transfer(args.receiver, args.amount.toString()).send();
107
+ return typeof result === "string" ? result : result?.txid || result?.transaction?.txID || result?.txID || "";
108
+ }
109
+
110
+ private async signMessageTIP191(message: string): Promise<Uint8Array> {
111
+ if (!this.tronWeb.trx?.signMessageV2 && !this.tronWeb.trx?.signMessage) throw "not impl";
112
+ const signatureHex = (await (this.tronWeb.trx.signMessageV2?.(message) || this.tronWeb.trx.signMessage?.(message))) as string;
113
+ if (!signatureHex) throw new Error("Failed to sign message");
114
+
115
+ const clean = signatureHex.startsWith("0x") ? signatureHex.slice(2) : signatureHex;
116
+ if (clean.length < 130) throw new Error("Invalid signature");
117
+
118
+ const rsv = clean.slice(0, 130);
119
+ const v = parseInt(rsv.slice(128, 130), 16);
120
+ const parity = v === 27 || v === 0 ? 0 : v === 28 || v === 1 ? 1 : v % 2;
121
+ const normalized = rsv.slice(0, 128) + (parity === 0 ? "00" : "01");
122
+ return hex.decode(normalized);
123
+ }
124
+
125
+ async signIntents(intents: Record<string, any>[], options?: { deadline?: number; nonce?: Uint8Array }): Promise<Commitment> {
126
+ const nonce = new Uint8Array(options?.nonce || window.crypto.getRandomValues(new Uint8Array(32)));
127
+
128
+ const message = JSON.stringify({
129
+ deadline: options?.deadline ? new Date(options.deadline).toISOString() : "2100-01-01T00:00:00.000Z",
130
+ verifying_contract: "intents.near",
131
+ signer_id: this.omniAddress,
132
+ nonce: base64.encode(nonce),
133
+ intents: intents,
134
+ });
135
+
136
+ // TronLink signs messages using TIP-191 ("\x19TRON Signed Message:\n").
137
+ const buffer = await this.signMessageTIP191(message);
138
+ return {
139
+ signature: `secp256k1:${base58.encode(buffer)}`,
140
+ payload: message,
141
+ standard: "tip191",
142
+ };
143
+ }
144
+ }
145
+
146
+ export default TronWallet;
package/src/ui/Popup.tsx CHANGED
@@ -16,13 +16,18 @@ export const present = (render: (close: () => void) => React.ReactNode) => {
16
16
  div.remove();
17
17
  })
18
18
  );
19
+
20
+ return () => {
21
+ root.unmount();
22
+ div.remove();
23
+ };
19
24
  };
20
25
 
21
26
  interface PopupProps {
22
27
  widget?: boolean;
23
28
  children: React.ReactNode;
24
29
  header?: React.ReactNode;
25
- onClose: () => void;
30
+ onClose?: () => void;
26
31
  style?: React.CSSProperties;
27
32
  mobileFullscreen?: boolean;
28
33
  }
@@ -57,9 +62,12 @@ const Popup = ({ widget, children, header, onClose, style, mobileFullscreen }: P
57
62
  <ModalContent ref={contentRef} $mobileFullscreen={mobileFullscreen} style={{ opacity: 0, transform: "translateY(20px)", transition: "all 0.2s ease-in-out" }}>
58
63
  {header && (
59
64
  <ModalHeader>
60
- <button onClick={onClose} style={{ position: "absolute", right: 16, top: 16 }}>
61
- <CloseIcon />
62
- </button>
65
+ {onClose != null && (
66
+ <button onClick={onClose} style={{ position: "absolute", right: 16, top: 16 }}>
67
+ <CloseIcon />
68
+ </button>
69
+ )}
70
+
63
71
  {header}
64
72
  </ModalHeader>
65
73
  )}