@gardenfi/wallet-connectors 3.0.0-beta.21 → 3.0.0-beta.22

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/dist/index9.js CHANGED
@@ -1,106 +1,64 @@
1
- var m = (e) => {
1
+ var y = (e) => {
2
2
  throw TypeError(e);
3
3
  };
4
- var g = (e, t, r) => t.has(e) || m("Cannot " + r);
5
- var i = (e, t, r) => (g(e, t, "read from private field"), r ? r.call(e) : t.get(e)), w = (e, t, r) => t.has(e) ? m("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), d = (e, t, r, s) => (g(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
6
- import { getBalance as C } from "./index17.js";
7
- import { Err as o, Ok as u, Network as l } from "@gardenfi/utils";
8
- import { WALLET_CONFIG as f } from "./index6.js";
9
- function L() {
10
- if (typeof window > "u") return;
11
- const e = window.ctrl ?? window.xfi;
12
- return e == null ? void 0 : e.litecoin;
13
- }
14
- function N(e, t, r = []) {
15
- return new Promise((s, a) => {
16
- e.request({ method: t, params: r }, (h, T) => {
17
- h ? a(h) : s(T);
18
- });
19
- });
20
- }
21
- var c, n;
22
- class q {
23
- constructor(t) {
24
- w(this, c);
25
- w(this, n);
26
- this.address = "", this.id = f.Ctrl.id, this.name = f.Ctrl.name, this.icon = f.Ctrl.icon, this.sendLitecoin = async (r, s) => {
27
- try {
28
- if (!this.address) {
29
- const h = await this.requestAccounts();
30
- if (!h.ok || h.val.length === 0)
31
- return o("No connected account to send from");
32
- }
33
- const a = await N(
34
- i(this, c),
35
- "transfer",
36
- [
37
- {
38
- feeRate: 10,
39
- from: this.address,
40
- recipient: r,
41
- amount: {
42
- amount: s,
43
- decimals: 8
44
- },
45
- memo: ""
46
- }
47
- ]
48
- );
49
- return u(a);
50
- } catch (a) {
51
- return o(
52
- `Error while sending Litecoin: ${a instanceof Error ? a.message : String(a)}`
53
- );
54
- }
55
- }, this.on = (r, s) => i(this, c).on(r, s), this.off = (r, s) => i(this, c).off(r, s), this.disconnect = () => (this.address = "", Promise.resolve(u("Disconnected CTRL wallet"))), d(this, c, t), d(this, n, l.MAINNET);
4
+ var g = (e, t, r) => t.has(e) || y("Cannot " + r);
5
+ var n = (e, t, r) => (g(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => t.has(e) ? y("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), a = (e, t, r, w) => (g(e, t, "write to private field"), w ? w.call(e, r) : t.set(e, r), r);
6
+ import { Ok as c, Err as o, executeWithTryCatch as h, Network as l } from "@gardenfi/utils";
7
+ import { WALLET_CONFIG as u } from "./index3.js";
8
+ var i, s;
9
+ class E {
10
+ constructor(t, r) {
11
+ d(this, i);
12
+ d(this, s);
13
+ this.address = "", this.id = u.OKX.id, this.name = u.OKX.name, this.icon = u.OKX.icon, this.disconnect = () => (this.address = "", n(this, i).disconnect(), Promise.resolve(c("Disconnected OKX wallet"))), a(this, i, t), a(this, s, r);
56
14
  }
57
- async connect(t) {
15
+ async connect() {
58
16
  try {
59
- const r = L();
60
- if (!r)
61
- return o("CTRL wallet Litecoin provider not found");
62
- d(this, c, r), t || (t = l.MAINNET), d(this, n, t);
63
- const s = await this.requestAccounts();
64
- return s.ok ? s.val.length === 0 ? o("No accounts found in CTRL wallet") : (this.address = s.val[0], u({
17
+ const t = await n(this, i).connect();
18
+ return !t || !t.address ? o("Failed to connect to OKX wallet") : (this.address = t.address, c({
65
19
  address: this.address,
66
20
  provider: this,
67
- network: i(this, n),
68
- id: f.Ctrl.id
69
- })) : o("Failed to get accounts from CTRL wallet");
70
- } catch (r) {
71
- return o("Error while connecting to the CTRL wallet", r);
21
+ network: n(this, s),
22
+ id: u.OKX.id
23
+ }));
24
+ } catch (t) {
25
+ return o("Error while connecting to the OKX wallet", t);
72
26
  }
73
27
  }
28
+ async getPublicKey() {
29
+ return await h(async () => await n(this, i).getPublicKey(), "Error while getting public key from OKX wallet");
30
+ }
74
31
  async requestAccounts() {
75
- try {
76
- const t = await N(
77
- i(this, c),
78
- "request_accounts"
79
- );
80
- return t && t.length > 0 && (this.address = t[0]), u(t);
81
- } catch {
82
- return o("Error while requesting accounts from the CTRL wallet");
83
- }
32
+ const t = await this.connect();
33
+ return t.ok ? c([t.val.address]) : o(t.error);
84
34
  }
85
35
  async getAccounts() {
86
- return this.requestAccounts();
36
+ return n(this, s) === l.TESTNET ? await this.requestAccounts() : await h(async () => await n(this, i).getAccounts(), "Error while getting accounts from OKX wallet");
87
37
  }
88
38
  async getNetwork() {
89
- return u(i(this, n));
39
+ return c(n(this, s));
90
40
  }
91
41
  async switchNetwork() {
92
- d(this, n, i(this, n) === l.MAINNET ? l.TESTNET : l.MAINNET);
93
- const t = await this.requestAccounts();
94
- return t.ok ? u(i(this, n)) : o(`Failed to get CTRL accounts: ${t.error}`);
42
+ a(this, s, n(this, s) === l.MAINNET ? l.TESTNET : l.MAINNET);
43
+ const t = await this.connect();
44
+ return t.error ? o(
45
+ `Failed to connect to ${n(this, s)}: ${t.error}`
46
+ ) : c(n(this, s));
95
47
  }
96
48
  async getBalance() {
97
- if (!this.address && !(await this.requestAccounts()).ok)
98
- return o("Failed to get address for balance");
99
- const t = await C(this.address, i(this, n));
100
- return t.ok ? u(t.val) : o(t.error);
49
+ return await h(async () => await n(this, i).getBalance(), "Error while getting balance from OKX wallet");
50
+ }
51
+ async sendBitcoin(t, r) {
52
+ return await h(async () => await n(this, i).sendBitcoin(t, r), "Error while sending bitcoin from OKX wallet");
53
+ }
54
+ on(t, r) {
55
+ n(this, i).on(t, r);
56
+ }
57
+ off(t, r) {
58
+ n(this, i).off(t, r);
101
59
  }
102
60
  }
103
- c = new WeakMap(), n = new WeakMap();
61
+ i = new WeakMap(), s = new WeakMap();
104
62
  export {
105
- q as CtrlProvider
63
+ E as OKXProvider
106
64
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/wallet-connectors",
3
- "version": "3.0.0-beta.21",
3
+ "version": "3.0.0-beta.22",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "vite build",
@@ -37,8 +37,8 @@
37
37
  },
38
38
  "sideEffects": false,
39
39
  "dependencies": {
40
- "@gardenfi/core": "3.1.3-beta.9",
41
- "@gardenfi/utils": "3.1.1-beta.7",
40
+ "@gardenfi/core": "3.1.3-beta.10",
41
+ "@gardenfi/utils": "3.1.1-beta.8",
42
42
  "axios": "^1.7.9",
43
43
  "bitcoinjs-lib": "^6.1.7",
44
44
  "bitcore-lib-ltc": "^10.10.5",