@cartridge/controller 0.7.10 → 0.7.12

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/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { WalletAccount as L, shortString as M, num as O } from "starknet";
2
- import { R as A, t as Y, K as $, P as W, B as H, N as u, p as K, A as q } from "./provider-Dr912mPw.js";
3
- import { h as Oe, n as Ye, a as $e, b as We } from "./provider-Dr912mPw.js";
2
+ import { R as A, t as Y, K as $, P as W, B as H, N as u, p as K, A as q } from "./provider-BN3lM6-S.js";
3
+ import { F as Oe, h as Ye, n as $e, a as We, b as He } from "./provider-BN3lM6-S.js";
4
4
  import { MetaMaskSDK as G } from "@metamask/sdk";
5
5
  import { Transaction as V } from "@solana/web3.js";
6
6
  import { connect as J } from "starknetkit";
@@ -31,7 +31,8 @@ class z extends L {
31
31
  e,
32
32
  void 0,
33
33
  void 0,
34
- !1
34
+ !1,
35
+ this.options?.feeSource
35
36
  );
36
37
  if (r.code === A.SUCCESS) {
37
38
  t(r);
@@ -85,10 +86,10 @@ var C;
85
86
  (function(o) {
86
87
  o.Fulfilled = "fulfilled", o.Rejected = "rejected";
87
88
  })(C || (C = {}));
88
- var E;
89
+ var R;
89
90
  (function(o) {
90
91
  o.ConnectionDestroyed = "ConnectionDestroyed", o.ConnectionTimeout = "ConnectionTimeout", o.NoIframeSrc = "NoIframeSrc";
91
- })(E || (E = {}));
92
+ })(R || (R = {}));
92
93
  var D;
93
94
  (function(o) {
94
95
  o.DataCloneError = "DataCloneError";
@@ -142,20 +143,20 @@ const Z = (o, e) => {
142
143
  }
143
144
  const p = d.data, { methodName: h, args: g, id: f } = p;
144
145
  t(`${n}: Received ${h}() call`);
145
- const w = (b) => (k) => {
146
+ const v = (b) => (k) => {
146
147
  if (t(`${n}: Sending ${h}() reply`), s) {
147
148
  t(`${n}: Unable to send ${h}() reply due to destroyed connection`);
148
149
  return;
149
150
  }
150
- const v = {
151
+ const w = {
151
152
  penpal: y.Reply,
152
153
  id: f,
153
154
  resolution: b,
154
155
  returnValue: k
155
156
  };
156
- b === C.Rejected && k instanceof Error && (v.returnValue = N(k), v.returnValueIsError = !0);
157
+ b === C.Rejected && k instanceof Error && (w.returnValue = N(k), w.returnValueIsError = !0);
157
158
  try {
158
- a.postMessage(v, c);
159
+ a.postMessage(w, c);
159
160
  } catch (m) {
160
161
  if (m.name === D.DataCloneError) {
161
162
  const I = {
@@ -170,7 +171,7 @@ const Z = (o, e) => {
170
171
  throw m;
171
172
  }
172
173
  };
173
- new Promise((b) => b(e[h].call(e, d.origin).apply(e, g))).then(w(C.Fulfilled), w(C.Rejected));
174
+ new Promise((b) => b(e[h].call(e, d.origin).apply(e, g))).then(v(C.Fulfilled), v(C.Rejected));
174
175
  };
175
176
  return r.addEventListener(_.Message, l), () => {
176
177
  s = !0, r.removeEventListener(_.Message, l);
@@ -200,33 +201,33 @@ const ce = () => ++se, j = ".", B = (o) => o ? o.split(j) : [], de = (o) => o.jo
200
201
  r(`${a}: Connecting call sender`);
201
202
  const p = (g) => (...f) => {
202
203
  r(`${a}: Sending ${g}() call`);
203
- let w;
204
+ let v;
204
205
  try {
205
- i.closed && (w = !0);
206
+ i.closed && (v = !0);
206
207
  } catch {
207
- w = !0;
208
+ v = !0;
208
209
  }
209
- if (w && n(), d) {
210
+ if (v && n(), d) {
210
211
  const b = new Error(`Unable to send ${g}() call due to destroyed connection`);
211
- throw b.code = E.ConnectionDestroyed, b;
212
+ throw b.code = R.ConnectionDestroyed, b;
212
213
  }
213
214
  return new Promise((b, k) => {
214
- const v = ce(), m = (x) => {
215
- if (x.source !== i || x.data.penpal !== y.Reply || x.data.id !== v)
215
+ const w = ce(), m = (x) => {
216
+ if (x.source !== i || x.data.penpal !== y.Reply || x.data.id !== w)
216
217
  return;
217
218
  if (l !== "*" && x.origin !== l) {
218
219
  r(`${a} received message from origin ${x.origin} which did not match expected origin ${l}`);
219
220
  return;
220
221
  }
221
- const S = x.data;
222
+ const E = x.data;
222
223
  r(`${a}: Received ${g}() reply`), c.removeEventListener(_.Message, m);
223
- let P = S.returnValue;
224
- S.returnValueIsError && (P = ae(P)), (S.resolution === C.Fulfilled ? b : k)(P);
224
+ let P = E.returnValue;
225
+ E.returnValueIsError && (P = ae(P)), (E.resolution === C.Fulfilled ? b : k)(P);
225
226
  };
226
227
  c.addEventListener(_.Message, m);
227
228
  const I = {
228
229
  penpal: y.Call,
229
- id: v,
230
+ id: w,
230
231
  methodName: g,
231
232
  args: f
232
233
  };
@@ -283,23 +284,23 @@ const ce = () => ++se, j = ".", B = (o) => o ? o.split(j) : [], de = (o) => o.jo
283
284
  let t;
284
285
  return o !== void 0 && (t = window.setTimeout(() => {
285
286
  const n = new Error(`Connection timed out after ${o}ms`);
286
- n.code = E.ConnectionTimeout, e(n);
287
+ n.code = R.ConnectionTimeout, e(n);
287
288
  }, o)), () => {
288
289
  clearTimeout(t);
289
290
  };
290
- }, ve = (o) => {
291
+ }, we = (o) => {
291
292
  if (!o.src && !o.srcdoc) {
292
293
  const e = new Error("Iframe must have src or srcdoc property defined.");
293
- throw e.code = E.NoIframeSrc, e;
294
+ throw e.code = R.NoIframeSrc, e;
294
295
  }
295
- }, we = (o) => {
296
+ }, ve = (o) => {
296
297
  let { iframe: e, methods: t = {}, childOrigin: n, timeout: r, debug: a = !1 } = o;
297
298
  const c = ee(a), i = Z("Parent", c), { onDestroy: s, destroy: l } = i;
298
- n || (ve(e), n = re(e.src));
299
+ n || (we(e), n = re(e.src));
299
300
  const d = n === "null" ? "*" : n, p = T(t), h = fe(c, p, n, d), g = he(p, n, d, i, c);
300
301
  return {
301
- promise: new Promise((w, b) => {
302
- const k = ye(r, l), v = (m) => {
302
+ promise: new Promise((v, b) => {
303
+ const k = ye(r, l), w = (m) => {
303
304
  if (!(m.source !== e.contentWindow || !m.data)) {
304
305
  if (m.data.penpal === y.Syn) {
305
306
  h(m);
@@ -307,13 +308,13 @@ const ce = () => ++se, j = ".", B = (o) => o ? o.split(j) : [], de = (o) => o.jo
307
308
  }
308
309
  if (m.data.penpal === y.Ack) {
309
310
  const I = g(m);
310
- I && (k(), w(I));
311
+ I && (k(), v(I));
311
312
  return;
312
313
  }
313
314
  }
314
315
  };
315
- window.addEventListener(_.Message, v), c("Parent: Awaiting handshake"), ue(e, i), s((m) => {
316
- window.removeEventListener(_.Message, v), m && b(m);
316
+ window.addEventListener(_.Message, w), c("Parent: Awaiting handshake"), ue(e, i), s((m) => {
317
+ window.removeEventListener(_.Message, w), m && b(m);
317
318
  });
318
319
  }),
319
320
  destroy() {
@@ -340,7 +341,7 @@ class Q {
340
341
  const i = document.createElement("iframe");
341
342
  i.src = t.toString(), i.id = e, i.style.border = "none", i.sandbox.add("allow-forms"), i.sandbox.add("allow-popups"), i.sandbox.add("allow-scripts"), i.sandbox.add("allow-same-origin"), i.allow = "publickey-credentials-create *; publickey-credentials-get *; clipboard-write", document.hasStorageAccess && i.sandbox.add("allow-storage-access-by-user-activation");
342
343
  const s = document.createElement("div");
343
- s.id = "controller", s.style.position = "fixed", s.style.height = "100%", s.style.width = "100%", s.style.top = "0", s.style.left = "0", s.style.zIndex = "10000", s.style.backgroundColor = "rgba(0,0,0,0.6)", s.style.display = "flex", s.style.alignItems = "center", s.style.justifyContent = "center", s.style.visibility = "hidden", s.style.opacity = "0", s.style.transition = "opacity 0.2s ease", s.appendChild(i), this.iframe = i, this.container = s, we({
344
+ s.id = "controller", s.style.position = "fixed", s.style.height = "100%", s.style.width = "100%", s.style.top = "0", s.style.left = "0", s.style.zIndex = "10000", s.style.backgroundColor = "rgba(0,0,0,0.6)", s.style.display = "flex", s.style.alignItems = "center", s.style.justifyContent = "center", s.style.visibility = "hidden", s.style.opacity = "0", s.style.transition = "opacity 0.2s ease", s.style.pointerEvents = "auto", s.appendChild(i), this.iframe = i, this.container = s, ve({
344
345
  iframe: this.iframe,
345
346
  methods: {
346
347
  close: (p) => () => this.close(),
@@ -732,7 +733,8 @@ class Ae {
732
733
  }
733
734
  class Ce {
734
735
  walletAdapters;
735
- connectedWallets = /* @__PURE__ */ new Map();
736
+ connectedWalletsByType = /* @__PURE__ */ new Map();
737
+ connectedWalletsByAddress = /* @__PURE__ */ new Map();
736
738
  constructor() {
737
739
  this.walletAdapters = /* @__PURE__ */ new Map(), this.walletAdapters.set("metamask", new _e()), this.walletAdapters.set("phantom", new ke()), this.walletAdapters.set("argent", new Ae()), typeof window < "u" && (window.wallet_bridge = this);
738
740
  }
@@ -751,64 +753,114 @@ class Ce {
751
753
  (t) => t.getInfo()
752
754
  );
753
755
  }
754
- getWalletAdapter(e) {
756
+ getWalletAdapterByType(e) {
755
757
  const t = this.walletAdapters.get(e);
756
758
  if (!t)
757
759
  throw new Error(`Unsupported wallet type: ${e}`);
758
760
  return t;
759
761
  }
760
- handleError(e, t, n) {
761
- const r = t instanceof Error ? t.message : "Unknown error";
762
- return console.error(`Error ${n} with ${e} wallet:`, t), { success: !1, wallet: e, error: r };
762
+ handleError(e, t, n, r) {
763
+ const a = t instanceof Error ? t.message : "Unknown error";
764
+ let c = "unknown";
765
+ if (typeof e == "string") {
766
+ const i = this.connectedWalletsByAddress.get(e);
767
+ c = r ?? i?.type ?? e;
768
+ } else
769
+ c = e;
770
+ return console.error(`Error ${n} with ${e} wallet:`, t), {
771
+ success: !1,
772
+ wallet: c,
773
+ error: a
774
+ };
763
775
  }
764
776
  async connectWallet(e) {
765
777
  try {
766
- const t = this.getWalletAdapter(e), n = await t.connect();
767
- return n.success && this.connectedWallets.set(e, t), n;
778
+ const t = this.getWalletAdapterByType(e), n = await t.connect();
779
+ if (n.success && n.account)
780
+ this.connectedWalletsByType.set(e, t), this.connectedWalletsByAddress.set(n.account, t), console.log(
781
+ `Wallet ${e} connected with address ${n.account}`
782
+ );
783
+ else if (n.success && !n.account)
784
+ return console.error(
785
+ `Wallet ${e} connected successfully but did not provide an address.`
786
+ ), {
787
+ ...n,
788
+ success: !1,
789
+ error: "Wallet connected but address not found."
790
+ };
791
+ return n;
768
792
  } catch (t) {
769
793
  return this.handleError(e, t, "connecting to");
770
794
  }
771
795
  }
796
+ getConnectedWalletAdapter(e) {
797
+ let t;
798
+ if (typeof e == "string" ? t = this.connectedWalletsByAddress.get(e) : t = this.connectedWalletsByType.get(e), !t && typeof e == "string" && (t = this.connectedWalletsByType.get(
799
+ e
800
+ )), !t)
801
+ throw new Error(
802
+ `Wallet with identifier ${e} is not connected or supported`
803
+ );
804
+ return t;
805
+ }
772
806
  async signMessage(e, t) {
807
+ let n;
773
808
  try {
774
- if (!this.connectedWallets.has(e))
775
- throw new Error(`Wallet ${e} is not connected`);
776
- const n = this.connectedWallets.get(e);
777
- if (!n.signMessage)
778
- throw new Error(`Wallet ${e} does not support signing messages`);
809
+ if (n = this.getConnectedWalletAdapter(e), !n.signMessage)
810
+ throw new Error(
811
+ `Wallet type ${n.type} (identifier: ${e}) does not support signing messages`
812
+ );
779
813
  return await n.signMessage(t);
780
- } catch (n) {
781
- return this.handleError(e, n, "signing message with");
814
+ } catch (r) {
815
+ return this.handleError(
816
+ e,
817
+ r,
818
+ "signing message with",
819
+ n?.type
820
+ );
782
821
  }
783
822
  }
784
823
  async signTypedData(e, t) {
824
+ let n;
785
825
  try {
786
- if (!this.connectedWallets.has(e))
787
- throw new Error(`Wallet ${e} is not connected`);
788
- const n = this.connectedWallets.get(e);
789
- if (!n.signTypedData)
790
- throw new Error(`Wallet ${e} does not support signing typed data`);
826
+ if (n = this.getConnectedWalletAdapter(e), !n.signTypedData)
827
+ throw new Error(
828
+ `Wallet type ${n.type} (identifier: ${e}) does not support signing typed data`
829
+ );
791
830
  return await n.signTypedData(t);
792
- } catch (n) {
793
- return this.handleError(e, n, "signing typed data with");
831
+ } catch (r) {
832
+ return this.handleError(
833
+ e,
834
+ r,
835
+ "signing typed data with",
836
+ n?.type
837
+ );
794
838
  }
795
839
  }
796
840
  async sendTransaction(e, t) {
841
+ let n;
797
842
  try {
798
- if (!this.connectedWallets.has(e))
799
- throw new Error(`Wallet ${e} is not connected`);
800
- return await this.connectedWallets.get(e).sendTransaction(t);
801
- } catch (n) {
802
- return this.handleError(e, n, "sending transaction with");
843
+ return n = this.getConnectedWalletAdapter(e), await n.sendTransaction(t);
844
+ } catch (r) {
845
+ return this.handleError(
846
+ e,
847
+ r,
848
+ "sending transaction with",
849
+ n?.type
850
+ );
803
851
  }
804
852
  }
805
853
  async getBalance(e, t) {
854
+ let n;
806
855
  try {
807
- if (!this.connectedWallets.has(e))
808
- throw new Error(`Wallet ${e} is not connected`);
809
- return await this.connectedWallets.get(e).getBalance(t);
810
- } catch (n) {
811
- return this.handleError(e, n, "getting balance from");
856
+ return n = this.getConnectedWalletAdapter(e), await n.getBalance(t);
857
+ } catch (r) {
858
+ return this.handleError(
859
+ e,
860
+ r,
861
+ "getting balance from",
862
+ n?.type
863
+ );
812
864
  }
813
865
  }
814
866
  }
@@ -824,7 +876,7 @@ class Ie extends Q {
824
876
  id: "controller-keychain",
825
877
  url: r,
826
878
  methods: a.getIFrameMethods()
827
- }), this.walletBridge = a;
879
+ }), this.walletBridge = a, typeof window < "u" && (window.external_wallets = this.walletBridge);
828
880
  }
829
881
  getWalletBridge() {
830
882
  return this.walletBridge;
@@ -1046,7 +1098,7 @@ class Ne extends H {
1046
1098
  }
1047
1099
  this.iframes.profile.close(), this.iframes.keychain.open(), this.keychain.openPurchaseCredits();
1048
1100
  }
1049
- openStarterPack() {
1101
+ openStarterPack(e) {
1050
1102
  if (!this.keychain || !this.iframes.keychain) {
1051
1103
  console.error(new u().message);
1052
1104
  return;
@@ -1055,7 +1107,7 @@ class Ne extends H {
1055
1107
  console.error("Profile is not ready");
1056
1108
  return;
1057
1109
  }
1058
- this.iframes.profile.close(), this.iframes.keychain.open(), this.keychain.openStarterPack();
1110
+ this.iframes.profile.close(), this.iframes.keychain.open(), this.keychain.openStarterPack(e);
1059
1111
  }
1060
1112
  async openExecute(e, t) {
1061
1113
  if (!this.keychain || !this.iframes.keychain) {
@@ -1069,7 +1121,10 @@ class Ne extends H {
1069
1121
  let n = this.selectedChain;
1070
1122
  t && this.switchStarknetChain(t), this.iframes.profile?.sendBackward(), this.iframes.keychain.open(), this.iframes.profile?.close();
1071
1123
  const r = await this.keychain.execute(e, void 0, void 0, !0);
1072
- return this.iframes.profile?.open(), this.iframes.keychain.close(), this.iframes.profile?.sendForward(), t && this.switchStarknetChain(n), !(r && (r.code === A.NOT_CONNECTED || r.code === A.CANCELED));
1124
+ return this.iframes.profile?.open(), this.iframes.keychain.close(), this.iframes.profile?.sendForward(), t && this.switchStarknetChain(n), {
1125
+ status: !(r && (r.code === A.NOT_CONNECTED || r.code === A.CANCELED)),
1126
+ transactionHash: r?.transaction_hash
1127
+ };
1073
1128
  }
1074
1129
  async delegateAccount() {
1075
1130
  return this.keychain ? await this.keychain.delegateAccount() : (console.error(new u().message), null);
@@ -1101,7 +1156,7 @@ class Ne extends H {
1101
1156
  });
1102
1157
  }
1103
1158
  }
1104
- const R = /* @__PURE__ */ new Map();
1159
+ const S = /* @__PURE__ */ new Map();
1105
1160
  async function F(o) {
1106
1161
  if (!o.addresses?.length && !o.usernames?.length)
1107
1162
  return { results: [] };
@@ -1117,22 +1172,22 @@ async function F(o) {
1117
1172
  return e.json();
1118
1173
  }
1119
1174
  async function je(o) {
1120
- const e = o.filter((t) => !R.has(t));
1175
+ const e = o.filter((t) => !S.has(t));
1121
1176
  return e.length > 0 && (await F({ usernames: e })).results.forEach((n) => {
1122
- R.set(n.username, n.addresses[0]);
1177
+ S.set(n.username, n.addresses[0]);
1123
1178
  }), new Map(
1124
- o.map((t) => [t, R.get(t)]).filter((t) => t[1] !== void 0)
1179
+ o.map((t) => [t, S.get(t)]).filter((t) => t[1] !== void 0)
1125
1180
  );
1126
1181
  }
1127
1182
  async function Be(o) {
1128
1183
  o = o.map(O.toHex);
1129
- const e = o.filter((t) => !R.has(t));
1184
+ const e = o.filter((t) => !S.has(t));
1130
1185
  return e.length > 0 && (await F({
1131
1186
  addresses: e
1132
1187
  })).results.forEach((n) => {
1133
- R.set(n.addresses[0], n.username);
1188
+ S.set(n.addresses[0], n.username);
1134
1189
  }), new Map(
1135
- o.map((t) => [t, R.get(t)]).filter((t) => t[1] !== void 0)
1190
+ o.map((t) => [t, S.get(t)]).filter((t) => t[1] !== void 0)
1136
1191
  );
1137
1192
  }
1138
1193
  var U = {
@@ -3814,7 +3869,7 @@ var U = {
3814
3869
  }
3815
3870
  }
3816
3871
  }
3817
- }, Re = [
3872
+ }, Se = [
3818
3873
  {
3819
3874
  name: "Wrapped BTC",
3820
3875
  symbol: "WBTC",
@@ -4360,9 +4415,10 @@ var U = {
4360
4415
  hidden: !0,
4361
4416
  logo_url: "https://imagedelivery.net/0xPAQaDtnQhBs8IzYRIlNg/6deef27f-df40-4248-4e1b-ed1d79a3f000/logo"
4362
4417
  }
4363
- ], Te = U, Qe = Re, Fe = U.cartridge.theme;
4418
+ ], Te = U, Qe = Se, Fe = U.cartridge.theme;
4364
4419
  export {
4365
4420
  Ae as ArgentWallet,
4421
+ Oe as FeeSource,
4366
4422
  _e as MetaMaskWallet,
4367
4423
  u as NotReadyToConnect,
4368
4424
  ke as PhantomWallet,
@@ -4372,13 +4428,13 @@ export {
4372
4428
  Ne as default,
4373
4429
  Fe as defaultTheme,
4374
4430
  Qe as erc20Metadata,
4375
- Oe as humanizeString,
4431
+ Ye as humanizeString,
4376
4432
  Be as lookupAddresses,
4377
4433
  je as lookupUsernames,
4378
- Ye as normalizeCalls,
4434
+ $e as normalizeCalls,
4379
4435
  K as parseChainId,
4380
4436
  Y as toArray,
4381
- $e as toSessionPolicies,
4382
- We as toWasmPolicies
4437
+ We as toSessionPolicies,
4438
+ He as toWasmPolicies
4383
4439
  };
4384
4440
  //# sourceMappingURL=index.js.map