@solana-mobile/wallet-standard-mobile 0.4.4 → 0.5.0-beta2
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 +5 -5
- package/lib/cjs/index.browser.js +1602 -1092
- package/lib/cjs/index.js +1602 -1092
- package/lib/cjs/index.native.js +1598 -1418
- package/lib/esm/index.browser.js +1606 -1089
- package/lib/esm/index.js +1606 -1089
- package/lib/types/index.browser.d.ts.map +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.native.d.ts.map +1 -1
- package/package.json +67 -63
package/lib/cjs/index.browser.js
CHANGED
|
@@ -1,58 +1,179 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var walletStandardFeatures = require('@solana/wallet-standard-features');
|
|
6
4
|
var QRCode = require('qrcode');
|
|
7
5
|
var mobileWalletAdapterProtocol = require('@solana-mobile/mobile-wallet-adapter-protocol');
|
|
8
6
|
var features = require('@wallet-standard/features');
|
|
9
7
|
var base58 = require('bs58');
|
|
8
|
+
var wallet = require('@wallet-standard/wallet');
|
|
10
9
|
var walletStandardChains = require('@solana/wallet-standard-chains');
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
const modalHtml$1 = `
|
|
12
|
+
<div class="mobile-wallet-adapter-embedded-loading-indicator" role="dialog" aria-modal="true" aria-labelledby="modal-title">
|
|
13
|
+
<div data-modal-close style="position: absolute; width: 100%; height: 100%;"></div>
|
|
14
|
+
<div class="mobile-wallet-adapter-embedded-loading-container">
|
|
15
|
+
<div class="mobile-wallet-adapter-embedded-loading-animation"></div>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
`;
|
|
19
|
+
const css$6 = `
|
|
20
|
+
.mobile-wallet-adapter-embedded-loading-indicator {
|
|
21
|
+
display: flex; /* Use flexbox to center content */
|
|
22
|
+
justify-content: center; /* Center horizontally */
|
|
23
|
+
align-items: start; /* Center vertically */
|
|
24
|
+
position: fixed; /* Stay in place */
|
|
25
|
+
z-index: 1; /* Sit on top */
|
|
26
|
+
left: 0;
|
|
27
|
+
top: 0;
|
|
28
|
+
width: 100%; /* Full width */
|
|
29
|
+
height: 100%; /* Full height */
|
|
30
|
+
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
|
|
31
|
+
overflow-y: auto; /* enable scrolling */
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.mobile-wallet-adapter-embedded-loading-container {
|
|
35
|
+
display: flex;
|
|
36
|
+
margin: auto;
|
|
37
|
+
}
|
|
13
38
|
|
|
14
|
-
|
|
15
|
-
|
|
39
|
+
.mobile-wallet-adapter-embedded-loading-animation {
|
|
40
|
+
position: relative;
|
|
41
|
+
left: -9999px;
|
|
42
|
+
width: 10px;
|
|
43
|
+
height: 10px;
|
|
44
|
+
border-radius: 5px;
|
|
45
|
+
background-color: var(--spinner-color);
|
|
46
|
+
color: var(--spinner-color);
|
|
47
|
+
box-shadow: 9984px 0 0 0 var(--spinner-color),
|
|
48
|
+
9999px 0 0 0 var(--spinner-color),
|
|
49
|
+
10014px 0 0 0 var(--spinner-color);
|
|
50
|
+
animation: dot-typing 1.5s infinite linear;
|
|
51
|
+
}
|
|
16
52
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
@keyframes dot-typing {
|
|
54
|
+
0% {
|
|
55
|
+
box-shadow: 9984px 0 0 0 var(--spinner-color),
|
|
56
|
+
9999px 0 0 0 var(--spinner-color),
|
|
57
|
+
10014px 0 0 0 var(--spinner-color);
|
|
58
|
+
}
|
|
59
|
+
16.667% {
|
|
60
|
+
box-shadow: 9984px -10px 0 0 var(--spinner-color),
|
|
61
|
+
9999px 0 0 0 var(--spinner-color),
|
|
62
|
+
10014px 0 0 0 var(--spinner-color);
|
|
63
|
+
}
|
|
64
|
+
33.333% {
|
|
65
|
+
box-shadow: 9984px 0 0 0 var(--spinner-color),
|
|
66
|
+
9999px 0 0 0 var(--spinner-color),
|
|
67
|
+
10014px 0 0 0 var(--spinner-color);
|
|
68
|
+
}
|
|
69
|
+
50% {
|
|
70
|
+
box-shadow: 9984px 0 0 0 var(--spinner-color),
|
|
71
|
+
9999px -10px 0 0 var(--spinner-color),
|
|
72
|
+
10014px 0 0 0 var(--spinner-color);
|
|
73
|
+
}
|
|
74
|
+
66.667% {
|
|
75
|
+
box-shadow: 9984px 0 0 0 var(--spinner-color),
|
|
76
|
+
9999px 0 0 0 var(--spinner-color),
|
|
77
|
+
10014px 0 0 0 var(--spinner-color);
|
|
78
|
+
}
|
|
79
|
+
83.333% {
|
|
80
|
+
box-shadow: 9984px 0 0 0 var(--spinner-color),
|
|
81
|
+
9999px 0 0 0 var(--spinner-color),
|
|
82
|
+
10014px -10px 0 0 var(--spinner-color);
|
|
83
|
+
}
|
|
84
|
+
100% {
|
|
85
|
+
box-shadow: 9984px 0 0 0 var(--spinner-color),
|
|
86
|
+
9999px 0 0 0 var(--spinner-color),
|
|
87
|
+
10014px 0 0 0 var(--spinner-color);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
class EmbeddedLoadingSpinner {
|
|
92
|
+
#root = null;
|
|
93
|
+
#eventListeners = {};
|
|
94
|
+
#listenersAttached = false;
|
|
95
|
+
dom = null;
|
|
96
|
+
constructor() {
|
|
97
|
+
// Bind methods to ensure `this` context is correct
|
|
98
|
+
this.init = this.init.bind(this);
|
|
99
|
+
this.#root = document.getElementById('mobile-wallet-adapter-embedded-root-ui');
|
|
100
|
+
}
|
|
101
|
+
async init() {
|
|
102
|
+
console.log('Injecting modal');
|
|
103
|
+
this.#injectHTML();
|
|
104
|
+
}
|
|
105
|
+
open = () => {
|
|
106
|
+
console.debug('Modal open');
|
|
107
|
+
this.#attachEventListeners();
|
|
108
|
+
if (this.#root) {
|
|
109
|
+
this.#root.style.display = 'flex';
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
close = (event = undefined) => {
|
|
113
|
+
console.debug('Modal close');
|
|
114
|
+
this.#removeEventListeners();
|
|
115
|
+
if (this.#root) {
|
|
116
|
+
this.#root.style.display = 'none';
|
|
117
|
+
}
|
|
118
|
+
this.#eventListeners['close']?.forEach((listener) => listener(event));
|
|
119
|
+
};
|
|
120
|
+
addEventListener(event, listener) {
|
|
121
|
+
this.#eventListeners[event]?.push(listener) || (this.#eventListeners[event] = [listener]);
|
|
122
|
+
return () => this.removeEventListener(event, listener);
|
|
123
|
+
}
|
|
124
|
+
removeEventListener(event, listener) {
|
|
125
|
+
this.#eventListeners[event] = this.#eventListeners[event]?.filter((existingListener) => listener !== existingListener);
|
|
126
|
+
}
|
|
127
|
+
#injectHTML() {
|
|
128
|
+
// Check if already injected by checking if shadow DOM exists
|
|
129
|
+
if (this.dom) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
// Create a container for the modal
|
|
133
|
+
this.#root = document.createElement('div');
|
|
134
|
+
this.#root.id = 'mobile-wallet-adapter-embedded-root-ui';
|
|
135
|
+
this.#root.innerHTML = modalHtml$1;
|
|
136
|
+
this.#root.style.display = 'none';
|
|
137
|
+
// Apply styles
|
|
138
|
+
const styles = document.createElement('style');
|
|
139
|
+
styles.id = 'mobile-wallet-adapter-embedded-modal-styles';
|
|
140
|
+
styles.textContent = css$6;
|
|
141
|
+
// Create a shadow DOM to encapsulate the modal
|
|
142
|
+
const host = document.createElement('div');
|
|
143
|
+
this.dom = host.attachShadow({ mode: 'closed' });
|
|
144
|
+
// Pass the CSS variable to the Shadow DOM
|
|
145
|
+
host.style.setProperty('--spinner-color', '#FFFFFF');
|
|
146
|
+
this.dom.appendChild(styles);
|
|
147
|
+
this.dom.appendChild(this.#root);
|
|
148
|
+
// Append the shadow DOM host to the body
|
|
149
|
+
document.body.appendChild(host);
|
|
150
|
+
}
|
|
151
|
+
#attachEventListeners() {
|
|
152
|
+
if (!this.#root || this.#listenersAttached)
|
|
153
|
+
return;
|
|
154
|
+
const closers = [...this.#root.querySelectorAll('[data-modal-close]')];
|
|
155
|
+
closers.forEach(closer => closer?.addEventListener('click', (event) => { this.close(event); }));
|
|
156
|
+
window.addEventListener('load', this.close);
|
|
157
|
+
document.addEventListener('keydown', this.#handleKeyDown);
|
|
158
|
+
this.#listenersAttached = true;
|
|
159
|
+
}
|
|
160
|
+
#removeEventListeners() {
|
|
161
|
+
if (!this.#listenersAttached)
|
|
162
|
+
return;
|
|
163
|
+
window.removeEventListener('load', this.close);
|
|
164
|
+
document.removeEventListener('keydown', this.#handleKeyDown);
|
|
165
|
+
if (!this.#root)
|
|
166
|
+
return;
|
|
167
|
+
const closers = [...this.#root.querySelectorAll('[data-modal-close]')];
|
|
168
|
+
closers.forEach(closer => closer?.removeEventListener('click', this.close));
|
|
169
|
+
this.#listenersAttached = false;
|
|
170
|
+
}
|
|
171
|
+
#handleKeyDown = (event) => {
|
|
172
|
+
if (event.key === 'Escape')
|
|
173
|
+
this.close(event);
|
|
174
|
+
};
|
|
53
175
|
}
|
|
54
176
|
|
|
55
|
-
var _EmbeddedModal_instances, _EmbeddedModal_root, _EmbeddedModal_eventListeners, _EmbeddedModal_listenersAttached, _EmbeddedModal_injectHTML, _EmbeddedModal_attachEventListeners, _EmbeddedModal_removeEventListeners, _EmbeddedModal_handleKeyDown;
|
|
56
177
|
const modalHtml = `
|
|
57
178
|
<div class="mobile-wallet-adapter-embedded-modal-container" role="dialog" aria-modal="true" aria-labelledby="modal-title">
|
|
58
179
|
<div data-modal-close style="position: absolute; width: 100%; height: 100%;"></div>
|
|
@@ -68,7 +189,7 @@ const modalHtml = `
|
|
|
68
189
|
</div>
|
|
69
190
|
</div>
|
|
70
191
|
`;
|
|
71
|
-
const css$
|
|
192
|
+
const css$5 = `
|
|
72
193
|
.mobile-wallet-adapter-embedded-modal-container {
|
|
73
194
|
display: flex; /* Use flexbox to center content */
|
|
74
195
|
justify-content: center; /* Center horizontally */
|
|
@@ -131,131 +252,121 @@ const fonts = `
|
|
|
131
252
|
<link href="https://fonts.googleapis.com/css2?family=Inter+Tight:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
|
|
132
253
|
`;
|
|
133
254
|
class EmbeddedModal {
|
|
255
|
+
#root = null;
|
|
256
|
+
#eventListeners = {};
|
|
257
|
+
#listenersAttached = false;
|
|
258
|
+
dom = null;
|
|
134
259
|
constructor() {
|
|
135
|
-
_EmbeddedModal_instances.add(this);
|
|
136
|
-
_EmbeddedModal_root.set(this, null);
|
|
137
|
-
_EmbeddedModal_eventListeners.set(this, {});
|
|
138
|
-
_EmbeddedModal_listenersAttached.set(this, false);
|
|
139
|
-
this.dom = null;
|
|
140
|
-
this.open = () => {
|
|
141
|
-
console.debug('Modal open');
|
|
142
|
-
__classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_attachEventListeners).call(this);
|
|
143
|
-
if (__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f")) {
|
|
144
|
-
__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'flex';
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
this.close = (event = undefined) => {
|
|
148
|
-
var _a;
|
|
149
|
-
console.debug('Modal close');
|
|
150
|
-
__classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_removeEventListeners).call(this);
|
|
151
|
-
if (__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f")) {
|
|
152
|
-
__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'none';
|
|
153
|
-
}
|
|
154
|
-
(_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")['close']) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener(event));
|
|
155
|
-
};
|
|
156
|
-
_EmbeddedModal_handleKeyDown.set(this, (event) => {
|
|
157
|
-
if (event.key === 'Escape')
|
|
158
|
-
this.close(event);
|
|
159
|
-
});
|
|
160
260
|
// Bind methods to ensure `this` context is correct
|
|
161
261
|
this.init = this.init.bind(this);
|
|
162
|
-
|
|
262
|
+
this.#root = document.getElementById('mobile-wallet-adapter-embedded-root-ui');
|
|
163
263
|
}
|
|
164
|
-
init() {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
__classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_injectHTML).call(this);
|
|
168
|
-
});
|
|
264
|
+
async init() {
|
|
265
|
+
console.log('Injecting modal');
|
|
266
|
+
this.#injectHTML();
|
|
169
267
|
}
|
|
268
|
+
open = () => {
|
|
269
|
+
console.debug('Modal open');
|
|
270
|
+
this.#attachEventListeners();
|
|
271
|
+
if (this.#root) {
|
|
272
|
+
this.#root.style.display = 'flex';
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
close = (event = undefined) => {
|
|
276
|
+
console.debug('Modal close');
|
|
277
|
+
this.#removeEventListeners();
|
|
278
|
+
if (this.#root) {
|
|
279
|
+
this.#root.style.display = 'none';
|
|
280
|
+
}
|
|
281
|
+
this.#eventListeners['close']?.forEach((listener) => listener(event));
|
|
282
|
+
};
|
|
170
283
|
addEventListener(event, listener) {
|
|
171
|
-
|
|
172
|
-
((_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event] = [listener]);
|
|
284
|
+
this.#eventListeners[event]?.push(listener) || (this.#eventListeners[event] = [listener]);
|
|
173
285
|
return () => this.removeEventListener(event, listener);
|
|
174
286
|
}
|
|
175
287
|
removeEventListener(event, listener) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
288
|
+
this.#eventListeners[event] = this.#eventListeners[event]?.filter((existingListener) => listener !== existingListener);
|
|
289
|
+
}
|
|
290
|
+
#injectHTML() {
|
|
291
|
+
// Check if the HTML has already been injected
|
|
292
|
+
if (document.getElementById('mobile-wallet-adapter-embedded-root-ui')) {
|
|
293
|
+
if (!this.#root)
|
|
294
|
+
this.#root = document.getElementById('mobile-wallet-adapter-embedded-root-ui');
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
// Create a container for the modal
|
|
298
|
+
this.#root = document.createElement('div');
|
|
299
|
+
this.#root.id = 'mobile-wallet-adapter-embedded-root-ui';
|
|
300
|
+
this.#root.innerHTML = modalHtml;
|
|
301
|
+
this.#root.style.display = 'none';
|
|
302
|
+
// Add modal content
|
|
303
|
+
const content = this.#root.querySelector('.mobile-wallet-adapter-embedded-modal-content');
|
|
304
|
+
if (content)
|
|
305
|
+
content.innerHTML = this.contentHtml;
|
|
306
|
+
// Apply styles
|
|
307
|
+
const styles = document.createElement('style');
|
|
308
|
+
styles.id = 'mobile-wallet-adapter-embedded-modal-styles';
|
|
309
|
+
styles.textContent = css$5 + this.contentStyles;
|
|
310
|
+
// Create a shadow DOM to encapsulate the modal
|
|
311
|
+
const host = document.createElement('div');
|
|
312
|
+
host.innerHTML = fonts;
|
|
313
|
+
this.dom = host.attachShadow({ mode: 'closed' });
|
|
314
|
+
this.dom.appendChild(styles);
|
|
315
|
+
this.dom.appendChild(this.#root);
|
|
316
|
+
// Append the shadow DOM host to the body
|
|
317
|
+
document.body.appendChild(host);
|
|
318
|
+
}
|
|
319
|
+
#attachEventListeners() {
|
|
320
|
+
if (!this.#root || this.#listenersAttached)
|
|
321
|
+
return;
|
|
322
|
+
const closers = [...this.#root.querySelectorAll('[data-modal-close]')];
|
|
323
|
+
closers.forEach(closer => closer?.addEventListener('click', this.close));
|
|
324
|
+
window.addEventListener('load', this.close);
|
|
325
|
+
document.addEventListener('keydown', this.#handleKeyDown);
|
|
326
|
+
this.#listenersAttached = true;
|
|
327
|
+
}
|
|
328
|
+
#removeEventListeners() {
|
|
329
|
+
if (!this.#listenersAttached)
|
|
330
|
+
return;
|
|
331
|
+
window.removeEventListener('load', this.close);
|
|
332
|
+
document.removeEventListener('keydown', this.#handleKeyDown);
|
|
333
|
+
if (!this.#root)
|
|
334
|
+
return;
|
|
335
|
+
const closers = [...this.#root.querySelectorAll('[data-modal-close]')];
|
|
336
|
+
closers.forEach(closer => closer?.removeEventListener('click', this.close));
|
|
337
|
+
this.#listenersAttached = false;
|
|
338
|
+
}
|
|
339
|
+
#handleKeyDown = (event) => {
|
|
340
|
+
if (event.key === 'Escape')
|
|
341
|
+
this.close(event);
|
|
342
|
+
};
|
|
179
343
|
}
|
|
180
|
-
_EmbeddedModal_root = new WeakMap(), _EmbeddedModal_eventListeners = new WeakMap(), _EmbeddedModal_listenersAttached = new WeakMap(), _EmbeddedModal_handleKeyDown = new WeakMap(), _EmbeddedModal_instances = new WeakSet(), _EmbeddedModal_injectHTML = function _EmbeddedModal_injectHTML() {
|
|
181
|
-
// Check if the HTML has already been injected
|
|
182
|
-
if (document.getElementById('mobile-wallet-adapter-embedded-root-ui')) {
|
|
183
|
-
if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"))
|
|
184
|
-
__classPrivateFieldSet$1(this, _EmbeddedModal_root, document.getElementById('mobile-wallet-adapter-embedded-root-ui'), "f");
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
// Create a container for the modal
|
|
188
|
-
__classPrivateFieldSet$1(this, _EmbeddedModal_root, document.createElement('div'), "f");
|
|
189
|
-
__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").id = 'mobile-wallet-adapter-embedded-root-ui';
|
|
190
|
-
__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").innerHTML = modalHtml;
|
|
191
|
-
__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'none';
|
|
192
|
-
// Add modal content
|
|
193
|
-
const content = __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelector('.mobile-wallet-adapter-embedded-modal-content');
|
|
194
|
-
if (content)
|
|
195
|
-
content.innerHTML = this.contentHtml;
|
|
196
|
-
// Apply styles
|
|
197
|
-
const styles = document.createElement('style');
|
|
198
|
-
styles.id = 'mobile-wallet-adapter-embedded-modal-styles';
|
|
199
|
-
styles.textContent = css$2 + this.contentStyles;
|
|
200
|
-
// Create a shadow DOM to encapsulate the modal
|
|
201
|
-
const host = document.createElement('div');
|
|
202
|
-
host.innerHTML = fonts;
|
|
203
|
-
this.dom = host.attachShadow({ mode: 'closed' });
|
|
204
|
-
this.dom.appendChild(styles);
|
|
205
|
-
this.dom.appendChild(__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"));
|
|
206
|
-
// Append the shadow DOM host to the body
|
|
207
|
-
document.body.appendChild(host);
|
|
208
|
-
}, _EmbeddedModal_attachEventListeners = function _EmbeddedModal_attachEventListeners() {
|
|
209
|
-
if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f") || __classPrivateFieldGet$1(this, _EmbeddedModal_listenersAttached, "f"))
|
|
210
|
-
return;
|
|
211
|
-
const closers = [...__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelectorAll('[data-modal-close]')];
|
|
212
|
-
closers.forEach(closer => closer === null || closer === void 0 ? void 0 : closer.addEventListener('click', this.close));
|
|
213
|
-
window.addEventListener('load', this.close);
|
|
214
|
-
document.addEventListener('keydown', __classPrivateFieldGet$1(this, _EmbeddedModal_handleKeyDown, "f"));
|
|
215
|
-
__classPrivateFieldSet$1(this, _EmbeddedModal_listenersAttached, true, "f");
|
|
216
|
-
}, _EmbeddedModal_removeEventListeners = function _EmbeddedModal_removeEventListeners() {
|
|
217
|
-
if (!__classPrivateFieldGet$1(this, _EmbeddedModal_listenersAttached, "f"))
|
|
218
|
-
return;
|
|
219
|
-
window.removeEventListener('load', this.close);
|
|
220
|
-
document.removeEventListener('keydown', __classPrivateFieldGet$1(this, _EmbeddedModal_handleKeyDown, "f"));
|
|
221
|
-
if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"))
|
|
222
|
-
return;
|
|
223
|
-
const closers = [...__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelectorAll('[data-modal-close]')];
|
|
224
|
-
closers.forEach(closer => closer === null || closer === void 0 ? void 0 : closer.removeEventListener('click', this.close));
|
|
225
|
-
__classPrivateFieldSet$1(this, _EmbeddedModal_listenersAttached, false, "f");
|
|
226
|
-
};
|
|
227
344
|
|
|
228
345
|
class RemoteConnectionModal extends EmbeddedModal {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
populateQRCode(qrUrl) {
|
|
244
|
-
var _a;
|
|
245
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
-
const qrcodeContainer = (_a = this.dom) === null || _a === void 0 ? void 0 : _a.getElementById('mobile-wallet-adapter-embedded-modal-qr-code-container');
|
|
247
|
-
if (qrcodeContainer) {
|
|
248
|
-
const qrCodeElement = yield QRCode__default["default"].toCanvas(qrUrl, { width: 200, margin: 0 });
|
|
249
|
-
if (qrcodeContainer.firstElementChild !== null) {
|
|
250
|
-
qrcodeContainer.replaceChild(qrCodeElement, qrcodeContainer.firstElementChild);
|
|
251
|
-
}
|
|
252
|
-
else
|
|
253
|
-
qrcodeContainer.appendChild(qrCodeElement);
|
|
346
|
+
contentStyles = css$4;
|
|
347
|
+
contentHtml = QRCodeHtml;
|
|
348
|
+
async initWithQR(qrCode) {
|
|
349
|
+
super.init();
|
|
350
|
+
this.populateQRCode(qrCode);
|
|
351
|
+
}
|
|
352
|
+
async populateQRCode(qrUrl) {
|
|
353
|
+
const qrcodeContainer = this.dom?.getElementById('mobile-wallet-adapter-embedded-modal-qr-code-container');
|
|
354
|
+
if (qrcodeContainer) {
|
|
355
|
+
const qrCodeElement = await QRCode.toCanvas(qrUrl, { width: 200, margin: 0 });
|
|
356
|
+
if (qrcodeContainer.firstElementChild !== null) {
|
|
357
|
+
qrcodeContainer.replaceChild(qrCodeElement, qrcodeContainer.firstElementChild);
|
|
254
358
|
}
|
|
255
|
-
else
|
|
256
|
-
|
|
359
|
+
else
|
|
360
|
+
qrcodeContainer.appendChild(qrCodeElement);
|
|
361
|
+
// remove the loading placeholder for cleanup
|
|
362
|
+
const qrPlaceholder = this.dom?.getElementById('mobile-wallet-adapter-embedded-modal-qr-placeholder');
|
|
363
|
+
if (qrPlaceholder) {
|
|
364
|
+
qrPlaceholder.style.display = 'none';
|
|
257
365
|
}
|
|
258
|
-
}
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
console.error('QRCode Container not found');
|
|
369
|
+
}
|
|
259
370
|
}
|
|
260
371
|
}
|
|
261
372
|
const QRCodeHtml = `
|
|
@@ -273,7 +384,9 @@ const QRCodeHtml = `
|
|
|
273
384
|
Open your wallet and scan this code
|
|
274
385
|
</h4>
|
|
275
386
|
</div>
|
|
276
|
-
<div id="mobile-wallet-adapter-embedded-modal-qr-code-container" class="mobile-wallet-adapter-embedded-modal-qr-code-container"
|
|
387
|
+
<div id="mobile-wallet-adapter-embedded-modal-qr-code-container" class="mobile-wallet-adapter-embedded-modal-qr-code-container">
|
|
388
|
+
<div id="mobile-wallet-adapter-embedded-modal-qr-placeholder" class="mobile-wallet-adapter-embedded-modal-qr-placeholder"></div>
|
|
389
|
+
</div>
|
|
277
390
|
</div>
|
|
278
391
|
</div>
|
|
279
392
|
<div class="mobile-wallet-adapter-embedded-modal-divider"><hr></div>
|
|
@@ -300,7 +413,7 @@ const QRCodeHtml = `
|
|
|
300
413
|
</div>
|
|
301
414
|
</div>
|
|
302
415
|
`;
|
|
303
|
-
const css$
|
|
416
|
+
const css$4 = `
|
|
304
417
|
.mobile-wallet-adapter-embedded-modal-qr-content {
|
|
305
418
|
display: flex;
|
|
306
419
|
margin-top: 10px;
|
|
@@ -344,6 +457,16 @@ const css$1 = `
|
|
|
344
457
|
margin-left: auto;
|
|
345
458
|
}
|
|
346
459
|
|
|
460
|
+
.mobile-wallet-adapter-embedded-modal-qr-placeholder {
|
|
461
|
+
margin-left: auto;
|
|
462
|
+
min-width: 200px;
|
|
463
|
+
min-height: 200px;
|
|
464
|
+
background: linear-gradient(-60deg, #F7F8F8 30%, #ECEEEE 50%, #F7F8F8 70%);
|
|
465
|
+
background-size: 200%;
|
|
466
|
+
animation: placeholderAnimate 2.7s linear infinite;
|
|
467
|
+
border-radius: 12px;
|
|
468
|
+
}
|
|
469
|
+
|
|
347
470
|
.mobile-wallet-adapter-embedded-modal-divider {
|
|
348
471
|
margin-top: 20px;
|
|
349
472
|
padding-left: 10px;
|
|
@@ -416,6 +539,15 @@ const css$1 = `
|
|
|
416
539
|
.mobile-wallet-adapter-embedded-modal-qr-code-container {
|
|
417
540
|
margin: auto;
|
|
418
541
|
}
|
|
542
|
+
.mobile-wallet-adapter-embedded-modal-qr-placeholder {
|
|
543
|
+
margin: auto;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/* QR Placeholder */
|
|
548
|
+
@keyframes placeholderAnimate {
|
|
549
|
+
0% { background-position: 200% 0; }
|
|
550
|
+
100% { background-position: -200% 0; }
|
|
419
551
|
}
|
|
420
552
|
|
|
421
553
|
/* Spinner */
|
|
@@ -509,721 +641,514 @@ function toUint8Array(base64EncodedByteArray) {
|
|
|
509
641
|
.map((c) => c.charCodeAt(0)));
|
|
510
642
|
}
|
|
511
643
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
_LocalSolanaMobileWalletAdapterWallet_authorizationCache.set(this, void 0);
|
|
528
|
-
_LocalSolanaMobileWalletAdapterWallet_connecting.set(this, false);
|
|
529
|
-
/**
|
|
530
|
-
* Every time the connection is recycled in some way (eg. `disconnect()` is called)
|
|
531
|
-
* increment this and use it to make sure that `transact` calls from the previous
|
|
532
|
-
* 'generation' don't continue to do work and throw exceptions.
|
|
533
|
-
*/
|
|
534
|
-
_LocalSolanaMobileWalletAdapterWallet_connectionGeneration.set(this, 0);
|
|
535
|
-
_LocalSolanaMobileWalletAdapterWallet_chains.set(this, []);
|
|
536
|
-
_LocalSolanaMobileWalletAdapterWallet_chainSelector.set(this, void 0);
|
|
537
|
-
_LocalSolanaMobileWalletAdapterWallet_optionalFeatures.set(this, void 0);
|
|
538
|
-
_LocalSolanaMobileWalletAdapterWallet_onWalletNotFound.set(this, void 0);
|
|
539
|
-
_LocalSolanaMobileWalletAdapterWallet_on.set(this, (event, listener) => {
|
|
540
|
-
var _a;
|
|
541
|
-
((_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event] = [listener]);
|
|
542
|
-
return () => __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_off).call(this, event, listener);
|
|
543
|
-
});
|
|
544
|
-
_LocalSolanaMobileWalletAdapterWallet_connect.set(this, ({ silent } = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
545
|
-
if (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, "f") || this.connected) {
|
|
546
|
-
return { accounts: this.accounts };
|
|
547
|
-
}
|
|
548
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, true, "f");
|
|
549
|
-
try {
|
|
550
|
-
if (silent) {
|
|
551
|
-
const cachedAuthorization = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
|
|
552
|
-
if (cachedAuthorization) {
|
|
553
|
-
yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, "f").call(this, cachedAuthorization.capabilities);
|
|
554
|
-
yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorization);
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
557
|
-
return { accounts: this.accounts };
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
else {
|
|
561
|
-
yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
catch (e) {
|
|
565
|
-
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
566
|
-
}
|
|
567
|
-
finally {
|
|
568
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false, "f");
|
|
569
|
-
}
|
|
570
|
-
return { accounts: this.accounts };
|
|
571
|
-
}));
|
|
572
|
-
_LocalSolanaMobileWalletAdapterWallet_performAuthorization.set(this, (signInPayload) => __awaiter(this, void 0, void 0, function* () {
|
|
573
|
-
try {
|
|
574
|
-
const cachedAuthorizationResult = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
|
|
575
|
-
if (cachedAuthorizationResult) {
|
|
576
|
-
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
577
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorizationResult);
|
|
578
|
-
return cachedAuthorizationResult;
|
|
579
|
-
}
|
|
580
|
-
const selectedChain = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chainSelector, "f").select(__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"));
|
|
581
|
-
return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
582
|
-
const [capabilities, mwaAuthorizationResult] = yield Promise.all([
|
|
583
|
-
wallet.getCapabilities(),
|
|
584
|
-
wallet.authorize({
|
|
585
|
-
chain: selectedChain,
|
|
586
|
-
identity: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, "f"),
|
|
587
|
-
sign_in_payload: signInPayload,
|
|
588
|
-
})
|
|
589
|
-
]);
|
|
590
|
-
const accounts = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
|
|
591
|
-
const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts, chain: selectedChain, capabilities: capabilities });
|
|
592
|
-
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
593
|
-
Promise.all([
|
|
594
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, "f").call(this, capabilities),
|
|
595
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
|
|
596
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
|
|
597
|
-
]);
|
|
598
|
-
return authorization;
|
|
599
|
-
}));
|
|
600
|
-
}
|
|
601
|
-
catch (e) {
|
|
602
|
-
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
603
|
-
}
|
|
604
|
-
}));
|
|
605
|
-
_LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult.set(this, (authorization) => __awaiter(this, void 0, void 0, function* () {
|
|
606
|
-
var _a;
|
|
607
|
-
const didPublicKeysChange =
|
|
608
|
-
// Case 1: We started from having no authorization.
|
|
609
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f") == null ||
|
|
610
|
-
// Case 2: The number of authorized accounts changed.
|
|
611
|
-
((_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts.length) !== authorization.accounts.length ||
|
|
612
|
-
// Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
|
|
613
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
|
|
614
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, authorization, "f");
|
|
615
|
-
if (didPublicKeysChange) {
|
|
616
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
|
|
617
|
-
}
|
|
618
|
-
}));
|
|
619
|
-
_LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult.set(this, (capabilities) => __awaiter(this, void 0, void 0, function* () {
|
|
620
|
-
// TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
|
|
621
|
-
const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
|
|
622
|
-
const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions;
|
|
623
|
-
const didCapabilitiesChange = walletStandardFeatures.SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
|
|
624
|
-
walletStandardFeatures.SolanaSignTransaction in this.features !== supportsSignTransaction;
|
|
625
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, Object.assign(Object.assign({}, ((supportsSignAndSendTransaction || (!supportsSignAndSendTransaction && !supportsSignTransaction)) && {
|
|
626
|
-
[walletStandardFeatures.SolanaSignAndSendTransaction]: {
|
|
627
|
-
version: '1.0.0',
|
|
628
|
-
supportedTransactionVersions: ['legacy', 0],
|
|
629
|
-
signAndSendTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
|
|
630
|
-
},
|
|
631
|
-
})), (supportsSignTransaction && {
|
|
632
|
-
[walletStandardFeatures.SolanaSignTransaction]: {
|
|
633
|
-
version: '1.0.0',
|
|
634
|
-
supportedTransactionVersions: ['legacy', 0],
|
|
635
|
-
signTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signTransaction, "f"),
|
|
636
|
-
},
|
|
637
|
-
})), "f");
|
|
638
|
-
if (didCapabilitiesChange) {
|
|
639
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { features: this.features });
|
|
640
|
-
}
|
|
641
|
-
}));
|
|
642
|
-
_LocalSolanaMobileWalletAdapterWallet_performReauthorization.set(this, (wallet, authToken, chain) => __awaiter(this, void 0, void 0, function* () {
|
|
643
|
-
var _b, _c;
|
|
644
|
-
try {
|
|
645
|
-
const [capabilities, mwaAuthorizationResult] = yield Promise.all([
|
|
646
|
-
(_c = (_b = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _b === void 0 ? void 0 : _b.capabilities) !== null && _c !== void 0 ? _c : yield wallet.getCapabilities(),
|
|
647
|
-
wallet.authorize({
|
|
648
|
-
auth_token: authToken,
|
|
649
|
-
identity: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, "f"),
|
|
650
|
-
chain: chain
|
|
651
|
-
})
|
|
652
|
-
]);
|
|
653
|
-
const accounts = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
|
|
654
|
-
const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts: accounts, chain: chain, capabilities: capabilities });
|
|
655
|
-
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
656
|
-
Promise.all([
|
|
657
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
|
|
658
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
|
|
659
|
-
]);
|
|
660
|
-
}
|
|
661
|
-
catch (e) {
|
|
662
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_disconnect, "f").call(this);
|
|
663
|
-
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
664
|
-
}
|
|
665
|
-
}));
|
|
666
|
-
_LocalSolanaMobileWalletAdapterWallet_disconnect.set(this, () => __awaiter(this, void 0, void 0, function* () {
|
|
667
|
-
var _d;
|
|
668
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
669
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false, "f");
|
|
670
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, (_d = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f"), _d++, _d), "f");
|
|
671
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, undefined, "f");
|
|
672
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
|
|
673
|
-
}));
|
|
674
|
-
_LocalSolanaMobileWalletAdapterWallet_transact.set(this, (callback) => __awaiter(this, void 0, void 0, function* () {
|
|
675
|
-
var _e;
|
|
676
|
-
const walletUriBase = (_e = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _e === void 0 ? void 0 : _e.wallet_uri_base;
|
|
677
|
-
const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
|
|
678
|
-
const currentConnectionGeneration = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f");
|
|
679
|
-
try {
|
|
680
|
-
return yield mobileWalletAdapterProtocol.transact(callback, config);
|
|
681
|
-
}
|
|
682
|
-
catch (e) {
|
|
683
|
-
if (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f") !== currentConnectionGeneration) {
|
|
684
|
-
yield new Promise(() => { }); // Never resolve.
|
|
685
|
-
}
|
|
686
|
-
if (e instanceof Error &&
|
|
687
|
-
e.name === 'SolanaMobileWalletAdapterError' &&
|
|
688
|
-
e.code === 'ERROR_WALLET_NOT_FOUND') {
|
|
689
|
-
yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, "f").call(this, this);
|
|
690
|
-
}
|
|
691
|
-
throw e;
|
|
692
|
-
}
|
|
693
|
-
}));
|
|
694
|
-
_LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized.set(this, () => {
|
|
695
|
-
if (!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f"))
|
|
696
|
-
throw new Error('Wallet not connected');
|
|
697
|
-
return { authToken: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").auth_token, chain: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").chain };
|
|
698
|
-
});
|
|
699
|
-
_LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts.set(this, (accounts) => {
|
|
700
|
-
return accounts.map((account) => {
|
|
701
|
-
var _a, _b;
|
|
702
|
-
const publicKey = toUint8Array(account.address);
|
|
703
|
-
return {
|
|
704
|
-
address: base58__default["default"].encode(publicKey),
|
|
705
|
-
publicKey,
|
|
706
|
-
label: account.label,
|
|
707
|
-
icon: account.icon,
|
|
708
|
-
chains: (_a = account.chains) !== null && _a !== void 0 ? _a : __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"),
|
|
709
|
-
// TODO: get supported features from getCapabilities API
|
|
710
|
-
features: (_b = account.features) !== null && _b !== void 0 ? _b : DEFAULT_FEATURES
|
|
711
|
-
};
|
|
712
|
-
});
|
|
713
|
-
});
|
|
714
|
-
_LocalSolanaMobileWalletAdapterWallet_performSignTransactions.set(this, (transactions) => __awaiter(this, void 0, void 0, function* () {
|
|
715
|
-
const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
|
|
716
|
-
try {
|
|
717
|
-
const base64Transactions = transactions.map((tx) => { return fromUint8Array(tx); });
|
|
718
|
-
return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
719
|
-
yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
|
|
720
|
-
const signedTransactions = (yield wallet.signTransactions({
|
|
721
|
-
payloads: base64Transactions,
|
|
722
|
-
})).signed_payloads.map(toUint8Array);
|
|
723
|
-
return signedTransactions;
|
|
724
|
-
}));
|
|
725
|
-
}
|
|
726
|
-
catch (e) {
|
|
727
|
-
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
728
|
-
}
|
|
729
|
-
}));
|
|
730
|
-
_LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction.set(this, (transaction, options) => __awaiter(this, void 0, void 0, function* () {
|
|
731
|
-
const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
|
|
732
|
-
try {
|
|
733
|
-
return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
734
|
-
const [capabilities, _1] = yield Promise.all([
|
|
735
|
-
wallet.getCapabilities(),
|
|
736
|
-
__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain)
|
|
737
|
-
]);
|
|
738
|
-
if (capabilities.supports_sign_and_send_transactions) {
|
|
739
|
-
const base64Transaction = fromUint8Array(transaction);
|
|
740
|
-
const signatures = (yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, options), { payloads: [base64Transaction] }))).signatures.map(toUint8Array);
|
|
741
|
-
return signatures[0];
|
|
742
|
-
}
|
|
743
|
-
else {
|
|
744
|
-
throw new Error('connected wallet does not support signAndSendTransaction');
|
|
745
|
-
}
|
|
746
|
-
}));
|
|
747
|
-
}
|
|
748
|
-
catch (e) {
|
|
749
|
-
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
750
|
-
}
|
|
751
|
-
}));
|
|
752
|
-
_LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
753
|
-
const outputs = [];
|
|
754
|
-
for (const input of inputs) {
|
|
755
|
-
const signature = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, "f").call(this, input.transaction, input.options);
|
|
756
|
-
outputs.push({ signature });
|
|
757
|
-
}
|
|
758
|
-
return outputs;
|
|
759
|
-
}));
|
|
760
|
-
_LocalSolanaMobileWalletAdapterWallet_signTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
761
|
-
return (yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignTransactions, "f").call(this, inputs.map(({ transaction }) => transaction)))
|
|
762
|
-
.map((signedTransaction) => {
|
|
763
|
-
return { signedTransaction };
|
|
764
|
-
});
|
|
765
|
-
}));
|
|
766
|
-
_LocalSolanaMobileWalletAdapterWallet_signMessage.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
767
|
-
const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
|
|
768
|
-
const addresses = inputs.map(({ account }) => fromUint8Array(account.publicKey));
|
|
769
|
-
const messages = inputs.map(({ message }) => fromUint8Array(message));
|
|
770
|
-
try {
|
|
771
|
-
return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
772
|
-
yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
|
|
773
|
-
const signedMessages = (yield wallet.signMessages({
|
|
774
|
-
addresses: addresses,
|
|
775
|
-
payloads: messages,
|
|
776
|
-
})).signed_payloads.map(toUint8Array);
|
|
777
|
-
return signedMessages.map((signedMessage) => {
|
|
778
|
-
return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
|
|
779
|
-
});
|
|
780
|
-
}));
|
|
781
|
-
}
|
|
782
|
-
catch (e) {
|
|
783
|
-
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
784
|
-
}
|
|
785
|
-
}));
|
|
786
|
-
_LocalSolanaMobileWalletAdapterWallet_signIn.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
787
|
-
const outputs = [];
|
|
788
|
-
if (inputs.length > 1) {
|
|
789
|
-
for (const input of inputs) {
|
|
790
|
-
outputs.push(yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, input));
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
else {
|
|
794
|
-
return [yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, inputs[0])];
|
|
795
|
-
}
|
|
796
|
-
return outputs;
|
|
797
|
-
}));
|
|
798
|
-
_LocalSolanaMobileWalletAdapterWallet_performSignIn.set(this, (input) => __awaiter(this, void 0, void 0, function* () {
|
|
799
|
-
var _f, _g, _h;
|
|
800
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, true, "f");
|
|
801
|
-
try {
|
|
802
|
-
const authorizationResult = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this, Object.assign(Object.assign({}, input), { domain: (_f = input === null || input === void 0 ? void 0 : input.domain) !== null && _f !== void 0 ? _f : window.location.host }));
|
|
803
|
-
if (!authorizationResult.sign_in_result) {
|
|
804
|
-
throw new Error("Sign in failed, no sign in result returned by wallet");
|
|
805
|
-
}
|
|
806
|
-
const signedInAddress = authorizationResult.sign_in_result.address;
|
|
807
|
-
const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
|
|
808
|
-
return {
|
|
809
|
-
account: Object.assign(Object.assign({}, signedInAccount !== null && signedInAccount !== void 0 ? signedInAccount : {
|
|
810
|
-
address: base58__default["default"].encode(toUint8Array(signedInAddress))
|
|
811
|
-
}), { publicKey: toUint8Array(signedInAddress), chains: (_g = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.chains) !== null && _g !== void 0 ? _g : __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"), features: (_h = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.features) !== null && _h !== void 0 ? _h : authorizationResult.capabilities.features }),
|
|
812
|
-
signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
|
|
813
|
-
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
catch (e) {
|
|
817
|
-
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
818
|
-
}
|
|
819
|
-
finally {
|
|
820
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false, "f");
|
|
821
|
-
}
|
|
822
|
-
}));
|
|
823
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, config.authorizationCache, "f");
|
|
824
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, config.appIdentity, "f");
|
|
825
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, config.chains, "f");
|
|
826
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_chainSelector, config.chainSelector, "f");
|
|
827
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, config.onWalletNotFound, "f");
|
|
828
|
-
__classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, {
|
|
829
|
-
// In MWA 1.0, signAndSend is optional and signTransaction is mandatory. Whereas in MWA 2.0+,
|
|
830
|
-
// signAndSend is mandatory and signTransaction is optional (and soft deprecated). As of mid
|
|
831
|
-
// 2025, all MWA wallets support both signAndSendTransaction and signTransaction so its safe
|
|
832
|
-
// assume both are supported here. The features will be updated based on the actual connected
|
|
833
|
-
// wallets capabilities during connection regardless, so this is safe.
|
|
834
|
-
[walletStandardFeatures.SolanaSignAndSendTransaction]: {
|
|
835
|
-
version: '1.0.0',
|
|
836
|
-
supportedTransactionVersions: ['legacy', 0],
|
|
837
|
-
signAndSendTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
|
|
838
|
-
},
|
|
839
|
-
[walletStandardFeatures.SolanaSignTransaction]: {
|
|
840
|
-
version: '1.0.0',
|
|
841
|
-
supportedTransactionVersions: ['legacy', 0],
|
|
842
|
-
signTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signTransaction, "f"),
|
|
843
|
-
},
|
|
844
|
-
}, "f");
|
|
845
|
-
}
|
|
846
|
-
get version() {
|
|
847
|
-
return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_version, "f");
|
|
848
|
-
}
|
|
849
|
-
get name() {
|
|
850
|
-
return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_name, "f");
|
|
851
|
-
}
|
|
852
|
-
get url() {
|
|
853
|
-
return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_url, "f");
|
|
854
|
-
}
|
|
855
|
-
get icon() {
|
|
856
|
-
return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_icon, "f");
|
|
857
|
-
}
|
|
858
|
-
get chains() {
|
|
859
|
-
return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f");
|
|
860
|
-
}
|
|
861
|
-
get features() {
|
|
862
|
-
return Object.assign({ [features.StandardConnect]: {
|
|
863
|
-
version: '1.0.0',
|
|
864
|
-
connect: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connect, "f"),
|
|
865
|
-
}, [features.StandardDisconnect]: {
|
|
866
|
-
version: '1.0.0',
|
|
867
|
-
disconnect: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_disconnect, "f"),
|
|
868
|
-
}, [features.StandardEvents]: {
|
|
869
|
-
version: '1.0.0',
|
|
870
|
-
on: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_on, "f"),
|
|
871
|
-
}, [walletStandardFeatures.SolanaSignMessage]: {
|
|
872
|
-
version: '1.0.0',
|
|
873
|
-
signMessage: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signMessage, "f"),
|
|
874
|
-
}, [walletStandardFeatures.SolanaSignIn]: {
|
|
875
|
-
version: '1.0.0',
|
|
876
|
-
signIn: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signIn, "f"),
|
|
877
|
-
} }, __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, "f"));
|
|
878
|
-
}
|
|
879
|
-
get accounts() {
|
|
880
|
-
var _a, _b;
|
|
881
|
-
return (_b = (_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts) !== null && _b !== void 0 ? _b : [];
|
|
882
|
-
}
|
|
883
|
-
get connected() {
|
|
884
|
-
return !!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f");
|
|
644
|
+
class LocalConnectionModal extends EmbeddedModal {
|
|
645
|
+
contentStyles = css$3;
|
|
646
|
+
contentHtml = ErrorDialogHtml$3;
|
|
647
|
+
initWithCallback(callback) {
|
|
648
|
+
super.init();
|
|
649
|
+
this.#prepareLaunchAction(callback);
|
|
650
|
+
}
|
|
651
|
+
#prepareLaunchAction(callback) {
|
|
652
|
+
const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
|
|
653
|
+
const listener = async () => {
|
|
654
|
+
launchButton?.removeEventListener('click', listener);
|
|
655
|
+
this.close();
|
|
656
|
+
callback();
|
|
657
|
+
};
|
|
658
|
+
launchButton?.addEventListener('click', listener);
|
|
885
659
|
}
|
|
886
|
-
|
|
887
|
-
|
|
660
|
+
}
|
|
661
|
+
const ErrorDialogHtml$3 = `
|
|
662
|
+
<svg class="mobile-wallet-adapter-embedded-modal-launch-icon" width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
663
|
+
<path d="M21.6 48C7.2 48 0 40.8 0 26.4V21.6C0 7.2 7.2 0 21.6 0H26.4C40.8 0 48 7.2 48 21.6V26.4C48 40.8 40.8 48 26.4 48H21.6Z" fill="#15994E"/>
|
|
664
|
+
<mask id="mask0_189_522" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="8" y="8" width="32" height="32">
|
|
665
|
+
<rect x="8" y="8" width="32" height="32" fill="#D9D9D9"/>
|
|
666
|
+
</mask>
|
|
667
|
+
<g mask="url(#mask0_189_522)">
|
|
668
|
+
<mask id="mask1_189_522" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="8" y="8" width="32" height="32">
|
|
669
|
+
<rect x="8" y="8" width="32" height="32" fill="#D9D9D9"/>
|
|
670
|
+
</mask>
|
|
671
|
+
<g mask="url(#mask1_189_522)">
|
|
672
|
+
<path d="M22.1092 26.1208L19.4498 23.4615C19.1736 23.1851 18.8253 23.0468 18.4048 23.0468C17.9846 23.0468 17.6363 23.1851 17.3598 23.4615C17.0836 23.7377 16.9468 24.0861 16.9495 24.5065C16.9522 24.9267 17.0916 25.275 17.3678 25.5512L21.0405 29.2238C21.3463 29.5276 21.7031 29.6795 22.1108 29.6795C22.5184 29.6795 22.8742 29.5276 23.1782 29.2238L30.5918 21.8098C30.8683 21.5336 31.0065 21.1867 31.0065 20.7692C31.0065 20.3514 30.8683 20.0044 30.5918 19.7282C30.3156 19.4517 29.9673 19.3135 29.5468 19.3135C29.1266 19.3135 28.7784 19.4517 28.5022 19.7282L22.1092 26.1208ZM23.9998 37.6042C22.113 37.6042 20.3425 37.2473 18.6885 36.5335C17.0343 35.8197 15.5954 34.8512 14.3718 33.6278C13.1485 32.4043 12.18 30.9654 11.4662 29.3112C10.7524 27.6572 10.3955 25.8867 10.3955 23.9998C10.3955 22.113 10.7524 20.3425 11.4662 18.6885C12.18 17.0343 13.1485 15.5954 14.3718 14.3718C15.5954 13.1485 17.0343 12.18 18.6885 11.4662C20.3425 10.7524 22.113 10.3955 23.9998 10.3955C25.8867 10.3955 27.6572 10.7524 29.3112 11.4662C30.9654 12.18 32.4043 13.1485 33.6278 14.3718C34.8512 15.5954 35.8197 17.0343 36.5335 18.6885C37.2473 20.3425 37.6042 22.113 37.6042 23.9998C37.6042 25.8867 37.2473 27.6572 36.5335 29.3112C35.8197 30.9654 34.8512 32.4043 33.6278 33.6278C32.4043 34.8512 30.9654 35.8197 29.3112 36.5335C27.6572 37.2473 25.8867 37.6042 23.9998 37.6042Z" fill="white"/>
|
|
673
|
+
</g>
|
|
674
|
+
</g>
|
|
675
|
+
</svg>
|
|
676
|
+
<div class="mobile-wallet-adapter-embedded-modal-title">Ready to connect!</div>
|
|
677
|
+
<div>
|
|
678
|
+
<button data-modal-action id="mobile-wallet-adapter-launch-action" class="mobile-wallet-adapter-embedded-modal-launch-action">
|
|
679
|
+
Connect Wallet
|
|
680
|
+
</button>
|
|
681
|
+
</div>
|
|
682
|
+
`;
|
|
683
|
+
const css$3 = `
|
|
684
|
+
.mobile-wallet-adapter-embedded-modal-close {
|
|
685
|
+
display: none;
|
|
686
|
+
}
|
|
687
|
+
.mobile-wallet-adapter-embedded-modal-content {
|
|
688
|
+
text-align: center;
|
|
689
|
+
min-width: 300px;
|
|
690
|
+
}
|
|
691
|
+
.mobile-wallet-adapter-embedded-modal-launch-icon {
|
|
692
|
+
margin-top: 24px;
|
|
693
|
+
}
|
|
694
|
+
.mobile-wallet-adapter-embedded-modal-title {
|
|
695
|
+
margin: 18px 100px 30px 100px;
|
|
696
|
+
color: #000000;
|
|
697
|
+
font-size: 2.75em;
|
|
698
|
+
font-weight: 600;
|
|
699
|
+
}
|
|
700
|
+
.mobile-wallet-adapter-embedded-modal-launch-action {
|
|
701
|
+
display: block;
|
|
702
|
+
width: 100%;
|
|
703
|
+
height: 56px;
|
|
704
|
+
font-size: 1.25em;
|
|
705
|
+
background: #000000;
|
|
706
|
+
color: #FFFFFF;
|
|
707
|
+
border-radius: 18px;
|
|
708
|
+
}
|
|
709
|
+
/* Smaller screens */
|
|
710
|
+
@media all and (max-width: 600px) {
|
|
711
|
+
.mobile-wallet-adapter-embedded-modal-title {
|
|
712
|
+
font-size: 1.5em;
|
|
713
|
+
margin-right: 12px;
|
|
714
|
+
margin-left: 12px;
|
|
888
715
|
}
|
|
889
|
-
|
|
890
|
-
|
|
716
|
+
}
|
|
717
|
+
`;
|
|
718
|
+
|
|
719
|
+
class LoopbackPermissionBlockedModal extends EmbeddedModal {
|
|
720
|
+
contentStyles = css$2;
|
|
721
|
+
get contentHtml() {
|
|
722
|
+
const instructions = getIsPwaLaunchedAsApp()
|
|
723
|
+
? 'Long press the app icon on your home screen to open site settings'
|
|
724
|
+
: 'Tap the lock or settings icon in the address bar to open site settings';
|
|
725
|
+
return ErrorDialogHtml$2.replace('{{PERMISSION_INSTRUCTION_DETAIL}}', instructions);
|
|
726
|
+
}
|
|
727
|
+
async init() {
|
|
728
|
+
super.init();
|
|
729
|
+
this.#prepareLaunchAction();
|
|
891
730
|
}
|
|
892
|
-
|
|
893
|
-
|
|
731
|
+
#prepareLaunchAction() {
|
|
732
|
+
const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
|
|
733
|
+
const listener = async (event) => {
|
|
734
|
+
launchButton?.removeEventListener('click', listener);
|
|
735
|
+
this.close(event);
|
|
736
|
+
};
|
|
737
|
+
launchButton?.addEventListener('click', listener);
|
|
894
738
|
}
|
|
895
739
|
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
740
|
+
const ErrorDialogHtml$2 = `
|
|
741
|
+
<div class="mobile-wallet-adapter-embedded-modal-header">
|
|
742
|
+
Local Wallet Connection
|
|
743
|
+
</div>
|
|
744
|
+
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
745
|
+
<path d="M21.6 48C7.2 48 0 40.8 0 26.4V21.6C0 7.2 7.2 0 21.6 0H26.4C40.8 0 48 7.2 48 21.6V26.4C48 40.8 40.8 48 26.4 48H21.6Z" fill="#ED1515"/>
|
|
746
|
+
<mask id="mask0_147_1364" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="8" y="8" width="32" height="32">
|
|
747
|
+
<rect x="8" y="8" width="32" height="32" fill="#D9D9D9"/>
|
|
748
|
+
</mask>
|
|
749
|
+
<g mask="url(#mask0_147_1364)">
|
|
750
|
+
<path d="M20.1398 36.2705C19.7363 36.2705 19.3508 36.1945 18.9835 36.0425C18.6162 35.8907 18.2916 35.674 18.0098 35.3922L12.6072 29.9895C12.3254 29.7077 12.1086 29.3832 11.9568 29.0158C11.8048 28.6485 11.7288 28.2631 11.7288 27.8595V20.1395C11.7288 19.736 11.8048 19.3505 11.9568 18.9832C12.1086 18.6158 12.3254 18.2913 12.6072 18.0095L18.0098 12.6068C18.2916 12.3251 18.6162 12.1083 18.9835 11.9565C19.3508 11.8045 19.7363 11.7285 20.1398 11.7285H27.8598C28.2634 11.7285 28.6488 11.8045 29.0162 11.9565C29.3835 12.1083 29.708 12.3251 29.9898 12.6068L35.3925 18.0095C35.6743 18.2913 35.891 18.6158 36.0428 18.9832C36.1948 19.3505 36.2708 19.736 36.2708 20.1395V27.8595C36.2708 28.2631 36.1948 28.6485 36.0428 29.0158C35.891 29.3832 35.6743 29.7077 35.3925 29.9895L29.9898 35.3922C29.708 35.674 29.3835 35.8907 29.0162 36.0425C28.6488 36.1945 28.2634 36.2705 27.8598 36.2705H20.1398ZM20.1732 33.2372H27.8265L33.2375 27.8262V20.1728L27.8265 14.7618H20.1732L14.7622 20.1728V27.8262L20.1732 33.2372ZM23.9998 25.9538L26.7868 28.7408C27.0473 29.0013 27.3729 29.1302 27.7638 29.1275C28.1549 29.1248 28.4807 28.9933 28.7412 28.7328C29.0016 28.4724 29.1318 28.1466 29.1318 27.7555C29.1318 27.3646 29.0016 27.039 28.7412 26.7785L25.9542 23.9995L28.7412 21.2125C29.0016 20.9521 29.1318 20.6264 29.1318 20.2355C29.1318 19.8444 29.0016 19.5186 28.7412 19.2582C28.4807 18.9977 28.1549 18.8675 27.7638 18.8675C27.3729 18.8675 27.0473 18.9977 26.7868 19.2582L23.9998 22.0452L21.2128 19.2582C20.9524 18.9977 20.628 18.8675 20.2398 18.8675C19.8514 18.8675 19.5269 18.9977 19.2665 19.2582C19.006 19.5186 18.8758 19.8444 18.8758 20.2355C18.8758 20.6264 19.006 20.9521 19.2665 21.2125L22.0455 23.9995L19.2585 26.7865C18.998 27.047 18.8692 27.3713 18.8718 27.7595C18.8745 28.148 19.006 28.4724 19.2665 28.7328C19.5269 28.9933 19.8527 29.1235 20.2438 29.1235C20.6347 29.1235 20.9604 28.9933 21.2208 28.7328L23.9998 25.9538Z" fill="black"/>
|
|
751
|
+
</g>
|
|
752
|
+
</svg>
|
|
753
|
+
<div class="mobile-wallet-adapter-embedded-modal-title">
|
|
754
|
+
Your wallet connection is blocked
|
|
755
|
+
</div>
|
|
756
|
+
<div id="mobile-wallet-adapter-local-launch-message" class="mobile-wallet-adapter-embedded-modal-subtitle">
|
|
757
|
+
Visit site settings in the address bar and allow "Apps on Device".
|
|
758
|
+
</div>
|
|
759
|
+
|
|
760
|
+
<div class="mobile-wallet-adapter-embedded-modal-divider"><hr></div>
|
|
761
|
+
<div class="mobile-wallet-adapter-embedded-modal-footer">
|
|
762
|
+
<div class="mobile-wallet-adapter-embedded-modal-details">
|
|
763
|
+
<!-- Clickable header (label associated with the checkbox) -->
|
|
764
|
+
<label for="collapsible-1" class="mobile-wallet-adapter-embedded-modal-details-collapsible-header">
|
|
765
|
+
<!-- Hidden checkbox to track state -->
|
|
766
|
+
<input type="checkbox" id="collapsible-1" class="mobile-wallet-adapter-embedded-modal-details-collapsible-input">
|
|
767
|
+
<span class="mobile-wallet-adapter-embedded-modal-details-collapsible-header-label">
|
|
768
|
+
See details
|
|
769
|
+
</span>
|
|
770
|
+
<svg class="mobile-wallet-adapter-embedded-modal-details-collapsible-header-icon" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
771
|
+
<mask id="mask0_147_1382" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="24" height="24">
|
|
772
|
+
<rect width="24" height="24" fill="#D9D9D9"/>
|
|
773
|
+
</mask>
|
|
774
|
+
<g mask="url(#mask0_147_1382)">
|
|
775
|
+
<path d="M11.9999 17.0811C11.8506 17.0811 11.7087 17.0563 11.5741 17.0067C11.4395 16.957 11.3162 16.8762 11.2042 16.7643L6.57924 12.1393C6.36801 11.9281 6.26656 11.667 6.27489 11.3561C6.28322 11.0453 6.39301 10.7842 6.60424 10.573C6.81547 10.3618 7.08069 10.2561 7.39989 10.2561C7.71909 10.2561 7.9843 10.3618 8.19554 10.573L11.9999 14.3773L15.8292 10.548C16.0405 10.3368 16.3015 10.2353 16.6124 10.2436C16.9233 10.252 17.1843 10.3618 17.3955 10.573C17.6068 10.7842 17.7124 11.0494 17.7124 11.3686C17.7124 11.6878 17.6068 11.9531 17.3955 12.1643L12.7955 16.7643C12.6836 16.8762 12.5603 16.957 12.4257 17.0067C12.2911 17.0563 12.1492 17.0811 11.9999 17.0811Z" fill="black"/>
|
|
776
|
+
</g>
|
|
777
|
+
</svg>
|
|
778
|
+
</label>
|
|
779
|
+
|
|
780
|
+
<!-- Content to show/hide -->
|
|
781
|
+
<ul class="mobile-wallet-adapter-embedded-modal-details-collapsible-content">
|
|
782
|
+
<li>{{PERMISSION_INSTRUCTION_DETAIL}}</li>
|
|
783
|
+
<li>Allow "Apps on Device"</li>
|
|
784
|
+
</ul>
|
|
785
|
+
</div>
|
|
786
|
+
</div>
|
|
787
|
+
<div>
|
|
788
|
+
<button data-modal-action id="mobile-wallet-adapter-launch-action" class="mobile-wallet-adapter-embedded-modal-launch-action">
|
|
789
|
+
Got it
|
|
790
|
+
</button>
|
|
791
|
+
</div>
|
|
792
|
+
`;
|
|
793
|
+
const css$2 = `
|
|
794
|
+
.mobile-wallet-adapter-embedded-modal-close {
|
|
795
|
+
display: none;
|
|
796
|
+
}
|
|
797
|
+
.mobile-wallet-adapter-embedded-modal-content {
|
|
798
|
+
text-align: center;
|
|
799
|
+
}
|
|
800
|
+
.mobile-wallet-adapter-embedded-modal-header {
|
|
801
|
+
margin: 18px auto 30px auto;
|
|
802
|
+
color: #7D9093;
|
|
803
|
+
font-size: 1.0em;
|
|
804
|
+
font-weight: 500;
|
|
805
|
+
}
|
|
806
|
+
.mobile-wallet-adapter-embedded-modal-title {
|
|
807
|
+
margin: 18px 100px auto 100px;
|
|
808
|
+
color: #000000;
|
|
809
|
+
font-size: 2.75em;
|
|
810
|
+
font-weight: 600;
|
|
811
|
+
}
|
|
812
|
+
.mobile-wallet-adapter-embedded-modal-subtitle {
|
|
813
|
+
margin: 12px 60px 30px 60px;
|
|
814
|
+
color: #7D9093;
|
|
815
|
+
font-size: 1.25em;
|
|
816
|
+
font-weight: 400;
|
|
817
|
+
}
|
|
818
|
+
.mobile-wallet-adapter-embedded-modal-details-collapsible-header {
|
|
819
|
+
display: flex;
|
|
820
|
+
flex-direction: row;
|
|
821
|
+
justify-content: space-between;
|
|
822
|
+
margin: 10px auto 10px auto;
|
|
823
|
+
color: #000000;
|
|
824
|
+
font-size: 1.5em;
|
|
825
|
+
font-weight: 600;
|
|
826
|
+
cursor: pointer; /* Show pointer on hover */
|
|
827
|
+
transition: background 0.2s ease; /* Smooth background change */
|
|
828
|
+
}
|
|
829
|
+
.mobile-wallet-adapter-embedded-modal-details-collapsible-header-icon {
|
|
830
|
+
transition: rotate 0.3s ease;
|
|
831
|
+
}
|
|
832
|
+
.mobile-wallet-adapter-embedded-modal-details-collapsible-input {
|
|
833
|
+
display: none; /* Hide the checkbox */
|
|
834
|
+
}
|
|
835
|
+
.mobile-wallet-adapter-embedded-modal-details-collapsible-content {
|
|
836
|
+
margin: 0px auto 40px auto;
|
|
837
|
+
max-height: 0px; /* Collapse content */
|
|
838
|
+
overflow: hidden; /* Hide overflow when collapsed */
|
|
839
|
+
transition: max-height 0.3s ease; /* Smooth transition */
|
|
840
|
+
}
|
|
841
|
+
.mobile-wallet-adapter-embedded-modal-details-collapsible-content li {
|
|
842
|
+
margin: 20px auto;
|
|
843
|
+
color: #000000;
|
|
844
|
+
font-size: 1.25em;
|
|
845
|
+
font-weight: 400;
|
|
846
|
+
text-align: left;
|
|
847
|
+
}
|
|
848
|
+
/* When checkbox is checked, show content */
|
|
849
|
+
.mobile-wallet-adapter-embedded-modal-details-collapsible-header:has(> input:checked) ~ .mobile-wallet-adapter-embedded-modal-details-collapsible-content {
|
|
850
|
+
max-height: 300px;
|
|
851
|
+
}
|
|
852
|
+
.mobile-wallet-adapter-embedded-modal-details-collapsible-header:has(> input:checked) > .mobile-wallet-adapter-embedded-modal-details-collapsible-header-icon {
|
|
853
|
+
rotate: 180deg;
|
|
854
|
+
}
|
|
855
|
+
.mobile-wallet-adapter-embedded-modal-launch-action {
|
|
856
|
+
display: block;
|
|
857
|
+
width: 100%;
|
|
858
|
+
height: 56px;
|
|
859
|
+
/*margin-top: 40px;*/
|
|
860
|
+
font-size: 1.25em;
|
|
861
|
+
/*line-height: 24px;*/
|
|
862
|
+
/*letter-spacing: -1%;*/
|
|
863
|
+
background: #000000;
|
|
864
|
+
color: #FFFFFF;
|
|
865
|
+
border-radius: 18px;
|
|
866
|
+
}
|
|
867
|
+
/* Smaller screens */
|
|
868
|
+
@media all and (max-width: 600px) {
|
|
869
|
+
.mobile-wallet-adapter-embedded-modal-title {
|
|
870
|
+
font-size: 1.75em;
|
|
871
|
+
margin-right: 12px;
|
|
872
|
+
margin-left: 12px;
|
|
873
|
+
}
|
|
874
|
+
.mobile-wallet-adapter-embedded-modal-subtitle {
|
|
875
|
+
margin-right: 12px;
|
|
876
|
+
margin-left: 12px;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
`;
|
|
880
|
+
|
|
881
|
+
class LoopbackPermissionModal extends EmbeddedModal {
|
|
882
|
+
contentStyles = css$1;
|
|
883
|
+
contentHtml = ErrorDialogHtml$1;
|
|
884
|
+
async init() {
|
|
885
|
+
super.init();
|
|
886
|
+
this.#prepareLaunchAction();
|
|
887
|
+
}
|
|
888
|
+
#prepareLaunchAction() {
|
|
889
|
+
const launchButton = this.dom?.getElementById("mobile-wallet-adapter-launch-action");
|
|
890
|
+
const listener = async () => {
|
|
891
|
+
launchButton?.removeEventListener('click', listener);
|
|
1024
892
|
try {
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
wallet.authorize({
|
|
1028
|
-
auth_token: authToken,
|
|
1029
|
-
identity: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, "f"),
|
|
1030
|
-
chain: chain
|
|
1031
|
-
})
|
|
1032
|
-
]);
|
|
1033
|
-
const accounts = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
|
|
1034
|
-
const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts: accounts, chain: chain, capabilities: capabilities });
|
|
1035
|
-
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
1036
|
-
Promise.all([
|
|
1037
|
-
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
|
|
1038
|
-
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
|
|
1039
|
-
]);
|
|
1040
|
-
}
|
|
1041
|
-
catch (e) {
|
|
1042
|
-
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_disconnect, "f").call(this);
|
|
1043
|
-
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
893
|
+
// Trigger LNA permission prompting
|
|
894
|
+
await fetch('http://localhost');
|
|
1044
895
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
896
|
+
catch (e) { /* Ignore errors from fetch */ }
|
|
897
|
+
this.close();
|
|
898
|
+
};
|
|
899
|
+
launchButton?.addEventListener('click', listener);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
const ErrorDialogHtml$1 = `
|
|
903
|
+
<div class="mobile-wallet-adapter-embedded-modal-title">Allow connections to your wallet</div>
|
|
904
|
+
<div id="mobile-wallet-adapter-local-launch-message" class="mobile-wallet-adapter-embedded-modal-subtitle">
|
|
905
|
+
Tap "Allow" on the next screen
|
|
906
|
+
</div>
|
|
907
|
+
<svg class="mobile-wallet-adapter-embedded-modal-permission-prompt-mock" xmlns="http://www.w3.org/2000/svg" width="281" height="83" viewBox="0 0 281 83" fill="none">
|
|
908
|
+
<rect width="281" height="83" rx="22" fill="#F0F3F5"/>
|
|
909
|
+
<path d="M254.194 64L252.626 56.657H254.047L254.866 61.452L254.985 62.278H255.02L255.146 61.452L255.993 57.497H257.4L258.254 61.431L258.373 62.278H258.415L258.534 61.431L259.346 56.657H260.718L259.143 64H257.673L256.826 59.961L256.693 59.093H256.651L256.511 59.961L255.664 64H254.194Z" fill="black"/>
|
|
910
|
+
<path d="M248.837 64.231C248.147 64.231 247.54 64.07 247.017 63.748C246.495 63.426 246.086 62.978 245.792 62.404C245.498 61.83 245.351 61.1673 245.351 60.416V60.241C245.351 59.4897 245.498 58.827 245.792 58.253C246.086 57.679 246.495 57.2333 247.017 56.916C247.54 56.594 248.147 56.433 248.837 56.433C249.528 56.433 250.135 56.594 250.657 56.916C251.18 57.2333 251.588 57.679 251.882 58.253C252.176 58.827 252.323 59.4897 252.323 60.241V60.416C252.323 61.1673 252.176 61.83 251.882 62.404C251.588 62.978 251.18 63.426 250.657 63.748C250.135 64.07 249.528 64.231 248.837 64.231ZM248.837 62.824C249.43 62.824 249.897 62.607 250.237 62.173C250.583 61.7343 250.755 61.1417 250.755 60.395V60.262C250.755 59.5107 250.583 58.918 250.237 58.484C249.897 58.05 249.43 57.833 248.837 57.833C248.249 57.833 247.783 58.05 247.437 58.484C247.092 58.918 246.919 59.5107 246.919 60.262V60.395C246.919 61.1417 247.092 61.7343 247.437 62.173C247.783 62.607 248.249 62.824 248.837 62.824Z" fill="black"/>
|
|
911
|
+
<path d="M242.298 64.231C241.467 64.231 240.814 63.993 240.338 63.517C239.866 63.0364 239.631 62.3737 239.631 61.529V53.78H241.178V61.389C241.178 62.3317 241.591 62.803 242.417 62.803C242.65 62.803 242.865 62.7587 243.061 62.67C243.257 62.5814 243.464 62.4367 243.684 62.236L244.538 63.377C244.225 63.6664 243.884 63.881 243.516 64.021C243.152 64.161 242.746 64.231 242.298 64.231ZM237.51 55.061V53.78H240.611V55.061H237.51Z" fill="black"/>
|
|
912
|
+
<path d="M234.463 64.231C233.633 64.231 232.979 63.993 232.503 63.517C232.032 63.0364 231.796 62.3737 231.796 61.529V53.78H233.343V61.389C233.343 62.3317 233.756 62.803 234.582 62.803C234.816 62.803 235.03 62.7587 235.226 62.67C235.422 62.5814 235.63 62.4367 235.849 62.236L236.703 63.377C236.391 63.6664 236.05 63.881 235.681 64.021C235.317 64.161 234.911 64.231 234.463 64.231ZM229.675 55.061V53.78H232.776V55.061H229.675Z" fill="black"/>
|
|
913
|
+
<path d="M221.442 64L224.557 53.976H226.132L229.233 64H227.581L225.642 56.972L225.341 55.761H225.299L225.005 56.972L223.073 64H221.442ZM222.835 61.634L223.255 60.29H227.371L227.805 61.634H222.835Z" fill="black"/>
|
|
914
|
+
<path d="M178.261 64L175.034 60.066V60.024L178.121 56.657H180.011L176.504 60.423V59.632L180.165 64H178.261ZM173.543 64V53.78H175.097V64H173.543Z" fill="#7D9093" fill-opacity="0.5"/>
|
|
915
|
+
<path d="M169.306 64.224C168.588 64.224 167.958 64.0653 167.416 63.748C166.88 63.426 166.462 62.9803 166.163 62.411C165.865 61.837 165.715 61.1673 165.715 60.402V60.248C165.715 59.4873 165.862 58.8223 166.156 58.253C166.45 57.679 166.863 57.2333 167.395 56.916C167.927 56.594 168.546 56.433 169.25 56.433C169.978 56.433 170.59 56.6056 171.084 56.951C171.579 57.2917 171.955 57.777 172.211 58.407L170.874 58.995C170.72 58.6123 170.508 58.323 170.237 58.127C169.967 57.9263 169.633 57.826 169.236 57.826C168.63 57.826 168.149 58.0383 167.794 58.463C167.444 58.883 167.269 59.4616 167.269 60.199V60.465C167.269 61.1837 167.454 61.7577 167.822 62.187C168.196 62.6163 168.69 62.831 169.306 62.831C169.712 62.831 170.06 62.733 170.349 62.537C170.639 62.341 170.877 62.0423 171.063 61.641L172.379 62.285C172.188 62.6957 171.941 63.0457 171.637 63.335C171.334 63.6243 170.986 63.846 170.594 64C170.202 64.1493 169.773 64.224 169.306 64.224Z" fill="#7D9093" fill-opacity="0.5"/>
|
|
916
|
+
<path d="M161.003 64.231C160.312 64.231 159.706 64.07 159.183 63.748C158.66 63.426 158.252 62.978 157.958 62.404C157.664 61.83 157.517 61.1673 157.517 60.416V60.241C157.517 59.4897 157.664 58.827 157.958 58.253C158.252 57.679 158.66 57.2333 159.183 56.916C159.706 56.594 160.312 56.433 161.003 56.433C161.694 56.433 162.3 56.594 162.823 56.916C163.346 57.2333 163.754 57.679 164.048 58.253C164.342 58.827 164.489 59.4897 164.489 60.241V60.416C164.489 61.1673 164.342 61.83 164.048 62.404C163.754 62.978 163.346 63.426 162.823 63.748C162.3 64.07 161.694 64.231 161.003 64.231ZM161.003 62.824C161.596 62.824 162.062 62.607 162.403 62.173C162.748 61.7343 162.921 61.1417 162.921 60.395V60.262C162.921 59.5107 162.748 58.918 162.403 58.484C162.062 58.05 161.596 57.833 161.003 57.833C160.415 57.833 159.948 58.05 159.603 58.484C159.258 58.918 159.085 59.5107 159.085 60.262V60.395C159.085 61.1417 159.258 61.7343 159.603 62.173C159.948 62.607 160.415 62.824 161.003 62.824Z" fill="#7D9093" fill-opacity="0.5"/>
|
|
917
|
+
<path d="M154.463 64.231C153.633 64.231 152.979 63.993 152.503 63.517C152.032 63.0364 151.796 62.3737 151.796 61.529V53.78H153.343V61.389C153.343 62.3317 153.756 62.803 154.582 62.803C154.816 62.803 155.03 62.7587 155.226 62.67C155.422 62.5814 155.63 62.4367 155.849 62.236L156.703 63.377C156.391 63.6664 156.05 63.881 155.681 64.021C155.317 64.161 154.911 64.231 154.463 64.231ZM149.675 55.061V53.78H152.776V55.061H149.675Z" fill="#7D9093" fill-opacity="0.5"/>
|
|
918
|
+
<path d="M142.24 64V53.976H145.544C146.421 53.976 147.112 54.1953 147.616 54.634C148.12 55.0726 148.372 55.6583 148.372 56.391V56.566C148.372 57.0886 148.246 57.5366 147.994 57.91C147.742 58.2833 147.38 58.5586 146.909 58.736V58.792C147.492 58.9226 147.947 59.2003 148.274 59.625C148.605 60.045 148.771 60.5606 148.771 61.172V61.361C148.771 61.893 148.645 62.3573 148.393 62.754C148.145 63.1506 147.795 63.4586 147.343 63.678C146.895 63.8926 146.365 64 145.754 64H142.24ZM143.794 62.656H145.572C146.085 62.656 146.482 62.5253 146.762 62.264C147.042 62.0026 147.182 61.6293 147.182 61.144V60.99C147.182 60.5046 147.037 60.1313 146.748 59.87C146.463 59.604 146.05 59.471 145.509 59.471H143.36V58.183H145.32C145.791 58.183 146.153 58.064 146.405 57.826C146.657 57.588 146.783 57.2496 146.783 56.811V56.685C146.783 56.2416 146.657 55.9033 146.405 55.67C146.157 55.4366 145.796 55.32 145.32 55.32H143.794V62.656Z" fill="#7D9093" fill-opacity="0.5"/>
|
|
919
|
+
<rect x="18" y="17" width="246" height="7" rx="3.5" fill="#7D9093" fill-opacity="0.26"/>
|
|
920
|
+
<rect x="18" y="33" width="82" height="7" rx="3.5" fill="#7D9093" fill-opacity="0.26"/>
|
|
921
|
+
</svg>
|
|
922
|
+
<div>
|
|
923
|
+
<button data-modal-action id="mobile-wallet-adapter-launch-action" class="mobile-wallet-adapter-embedded-modal-launch-action">
|
|
924
|
+
Continue to Allow
|
|
925
|
+
</button>
|
|
926
|
+
</div>
|
|
927
|
+
`;
|
|
928
|
+
const css$1 = `
|
|
929
|
+
.mobile-wallet-adapter-embedded-modal-close {
|
|
930
|
+
display: none;
|
|
931
|
+
}
|
|
932
|
+
.mobile-wallet-adapter-embedded-modal-content {
|
|
933
|
+
text-align: center;
|
|
934
|
+
}
|
|
935
|
+
.mobile-wallet-adapter-embedded-modal-title {
|
|
936
|
+
margin: 18px 100px auto 100px;
|
|
937
|
+
color: #000000;
|
|
938
|
+
font-size: 2.75em;
|
|
939
|
+
font-weight: 600;
|
|
940
|
+
}
|
|
941
|
+
.mobile-wallet-adapter-embedded-modal-subtitle {
|
|
942
|
+
margin: 20px 60px 40px 60px;
|
|
943
|
+
color: #7D9093;
|
|
944
|
+
font-size: 1.25em;
|
|
945
|
+
font-weight: 400;
|
|
946
|
+
}
|
|
947
|
+
.mobile-wallet-adapter-embedded-modal-permission-prompt-mock {
|
|
948
|
+
width: 90%;
|
|
949
|
+
height: auto;
|
|
950
|
+
margin: 0 auto 30px auto;
|
|
951
|
+
display: block;
|
|
952
|
+
}
|
|
953
|
+
.mobile-wallet-adapter-embedded-modal-launch-action {
|
|
954
|
+
display: block;
|
|
955
|
+
width: 100%;
|
|
956
|
+
height: 56px;
|
|
957
|
+
font-size: 1.25em;
|
|
958
|
+
background: #000000;
|
|
959
|
+
color: #FFFFFF;
|
|
960
|
+
border-radius: 18px;
|
|
961
|
+
}
|
|
962
|
+
/* Smaller screens */
|
|
963
|
+
@media all and (max-width: 600px) {
|
|
964
|
+
.mobile-wallet-adapter-embedded-modal-title {
|
|
965
|
+
font-size: 1.5em;
|
|
966
|
+
margin-right: 12px;
|
|
967
|
+
margin-left: 12px;
|
|
968
|
+
}
|
|
969
|
+
.mobile-wallet-adapter-embedded-modal-subtitle {
|
|
970
|
+
margin-right: 12px;
|
|
971
|
+
margin-left: 12px;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
`;
|
|
975
|
+
|
|
976
|
+
function getIsLocalAssociationSupported() {
|
|
977
|
+
return (typeof window !== 'undefined' &&
|
|
978
|
+
window.isSecureContext &&
|
|
979
|
+
typeof document !== 'undefined' &&
|
|
980
|
+
/android/i.test(navigator.userAgent));
|
|
981
|
+
}
|
|
982
|
+
function getIsRemoteAssociationSupported() {
|
|
983
|
+
return (typeof window !== 'undefined' &&
|
|
984
|
+
window.isSecureContext &&
|
|
985
|
+
typeof document !== 'undefined' &&
|
|
986
|
+
!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
|
|
987
|
+
}
|
|
988
|
+
// Source: https://github.com/anza-xyz/wallet-adapter/blob/master/packages/core/react/src/getEnvironment.ts#L14
|
|
989
|
+
// This is the same implementation that gated MWA in the Anza wallet-adapter-react library.
|
|
990
|
+
function isWebView(userAgentString) {
|
|
991
|
+
return /(WebView|Version\/.+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+)|; wv\).+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+))/i.test(userAgentString);
|
|
992
|
+
}
|
|
993
|
+
// Source: https://web.dev/learn/pwa/detection/
|
|
994
|
+
function getIsPwaLaunchedAsApp() {
|
|
995
|
+
// Check for Android TWA
|
|
996
|
+
const isAndroidTwa = typeof document !== 'undefined' && document.referrer.startsWith('android-app://');
|
|
997
|
+
// Check for display-mode: standalone, fullscreen, or minimal-ui
|
|
998
|
+
if (typeof window == 'undefined')
|
|
999
|
+
return isAndroidTwa;
|
|
1000
|
+
const isStandalone = window.matchMedia('(display-mode: standalone)').matches;
|
|
1001
|
+
const isFullscreen = window.matchMedia('(display-mode: fullscreen)').matches;
|
|
1002
|
+
const isMinimalUI = window.matchMedia('(display-mode: minimal-ui)').matches;
|
|
1003
|
+
// App mode if any of these conditions are true
|
|
1004
|
+
return isAndroidTwa || isStandalone || isFullscreen || isMinimalUI;
|
|
1005
|
+
}
|
|
1006
|
+
async function checkLocalNetworkAccessPermission() {
|
|
1007
|
+
try {
|
|
1008
|
+
let lnaPermission = await navigator.permissions.query({ name: "loopback-network" });
|
|
1009
|
+
if (lnaPermission.state === "granted") {
|
|
1010
|
+
// LNA permission already granted, continuing
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
else if (lnaPermission.state === "denied") {
|
|
1014
|
+
// LNA permission denied, aborting
|
|
1015
|
+
const modal = new LoopbackPermissionBlockedModal();
|
|
1016
|
+
modal.init();
|
|
1017
|
+
modal.open();
|
|
1018
|
+
throw new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, 'Local Network Access permission denied');
|
|
1019
|
+
}
|
|
1020
|
+
else if (lnaPermission.state === "prompt") {
|
|
1021
|
+
// Show permission explainer to user, and wait for the permission to change
|
|
1022
|
+
const modal = new LoopbackPermissionModal();
|
|
1023
|
+
const updatedState = await new Promise((resolve, reject) => {
|
|
1024
|
+
modal.addEventListener('close', (event) => {
|
|
1025
|
+
if (event) {
|
|
1026
|
+
reject(new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, 'Wallet connection cancelled by user', { event }));
|
|
1027
|
+
}
|
|
1072
1028
|
});
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
removeCloseListener();
|
|
1077
|
-
modal.close();
|
|
1078
|
-
return yield callback(__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f").wallet);
|
|
1079
|
-
}
|
|
1080
|
-
catch (e) {
|
|
1081
|
-
modal.close();
|
|
1082
|
-
if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, "f") !== currentConnectionGeneration) {
|
|
1083
|
-
yield new Promise(() => { }); // Never resolve.
|
|
1084
|
-
}
|
|
1085
|
-
if (e instanceof Error &&
|
|
1086
|
-
e.name === 'SolanaMobileWalletAdapterError' &&
|
|
1087
|
-
e.code === 'ERROR_WALLET_NOT_FOUND') {
|
|
1088
|
-
yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound, "f").call(this, this);
|
|
1089
|
-
}
|
|
1090
|
-
throw e;
|
|
1091
|
-
}
|
|
1092
|
-
}));
|
|
1093
|
-
_RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized.set(this, () => {
|
|
1094
|
-
if (!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f"))
|
|
1095
|
-
throw new Error('Wallet not connected');
|
|
1096
|
-
return { authToken: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").auth_token, chain: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").chain };
|
|
1097
|
-
});
|
|
1098
|
-
_RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts.set(this, (accounts) => {
|
|
1099
|
-
return accounts.map((account) => {
|
|
1100
|
-
var _a, _b;
|
|
1101
|
-
const publicKey = toUint8Array(account.address);
|
|
1102
|
-
return {
|
|
1103
|
-
address: base58__default["default"].encode(publicKey),
|
|
1104
|
-
publicKey,
|
|
1105
|
-
label: account.label,
|
|
1106
|
-
icon: account.icon,
|
|
1107
|
-
chains: (_a = account.chains) !== null && _a !== void 0 ? _a : __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f"),
|
|
1108
|
-
// TODO: get supported features from getCapabilities API
|
|
1109
|
-
features: (_b = account.features) !== null && _b !== void 0 ? _b : DEFAULT_FEATURES
|
|
1029
|
+
lnaPermission.onchange = () => {
|
|
1030
|
+
lnaPermission.onchange = null; // cleanup
|
|
1031
|
+
resolve(lnaPermission.state);
|
|
1110
1032
|
};
|
|
1033
|
+
modal.init();
|
|
1034
|
+
modal.open();
|
|
1111
1035
|
});
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
return signedTransactions;
|
|
1122
|
-
}));
|
|
1123
|
-
}
|
|
1124
|
-
catch (e) {
|
|
1125
|
-
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1126
|
-
}
|
|
1127
|
-
}));
|
|
1128
|
-
_RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction.set(this, (transaction, options) => __awaiter(this, void 0, void 0, function* () {
|
|
1129
|
-
const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
|
|
1130
|
-
try {
|
|
1131
|
-
return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
1132
|
-
const [capabilities, _1] = yield Promise.all([
|
|
1133
|
-
wallet.getCapabilities(),
|
|
1134
|
-
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain)
|
|
1135
|
-
]);
|
|
1136
|
-
if (capabilities.supports_sign_and_send_transactions) {
|
|
1137
|
-
const signatures = (yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, options), { payloads: [fromUint8Array(transaction)] }))).signatures.map(toUint8Array);
|
|
1138
|
-
return signatures[0];
|
|
1139
|
-
}
|
|
1140
|
-
else {
|
|
1141
|
-
throw new Error('connected wallet does not support signAndSendTransaction');
|
|
1142
|
-
}
|
|
1143
|
-
}));
|
|
1144
|
-
}
|
|
1145
|
-
catch (e) {
|
|
1146
|
-
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1147
|
-
}
|
|
1148
|
-
}));
|
|
1149
|
-
_RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
1150
|
-
const outputs = [];
|
|
1151
|
-
for (const input of inputs) {
|
|
1152
|
-
const signature = (yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, "f").call(this, input.transaction, input.options));
|
|
1153
|
-
outputs.push({ signature });
|
|
1154
|
-
}
|
|
1155
|
-
return outputs;
|
|
1156
|
-
}));
|
|
1157
|
-
_RemoteSolanaMobileWalletAdapterWallet_signTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
1158
|
-
return (yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions, "f").call(this, inputs.map(({ transaction }) => transaction)))
|
|
1159
|
-
.map((signedTransaction) => {
|
|
1160
|
-
return { signedTransaction };
|
|
1161
|
-
});
|
|
1162
|
-
}));
|
|
1163
|
-
_RemoteSolanaMobileWalletAdapterWallet_signMessage.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
1164
|
-
const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
|
|
1165
|
-
const addresses = inputs.map(({ account }) => fromUint8Array(account.publicKey));
|
|
1166
|
-
const messages = inputs.map(({ message }) => fromUint8Array(message));
|
|
1167
|
-
try {
|
|
1168
|
-
return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
|
|
1169
|
-
yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
|
|
1170
|
-
const signedMessages = (yield wallet.signMessages({
|
|
1171
|
-
addresses: addresses,
|
|
1172
|
-
payloads: messages,
|
|
1173
|
-
})).signed_payloads.map(toUint8Array);
|
|
1174
|
-
return signedMessages.map((signedMessage) => {
|
|
1175
|
-
return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
|
|
1036
|
+
if (updatedState === "granted") {
|
|
1037
|
+
// User has granted the permission, now we need another click to continue
|
|
1038
|
+
// Note: this is required to avoid being blocked by the browsers pop-up blocker
|
|
1039
|
+
const modal = new LocalConnectionModal();
|
|
1040
|
+
await new Promise((resolve, reject) => {
|
|
1041
|
+
modal.addEventListener('close', (event) => {
|
|
1042
|
+
if (event) {
|
|
1043
|
+
reject(new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, 'Wallet connection cancelled by user', { event }));
|
|
1044
|
+
}
|
|
1176
1045
|
});
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
_RemoteSolanaMobileWalletAdapterWallet_signIn.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
1184
|
-
const outputs = [];
|
|
1185
|
-
if (inputs.length > 1) {
|
|
1186
|
-
for (const input of inputs) {
|
|
1187
|
-
outputs.push(yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, input));
|
|
1188
|
-
}
|
|
1046
|
+
modal.initWithCallback(async () => {
|
|
1047
|
+
resolve(true);
|
|
1048
|
+
});
|
|
1049
|
+
modal.open();
|
|
1050
|
+
});
|
|
1051
|
+
return;
|
|
1189
1052
|
}
|
|
1190
1053
|
else {
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
return outputs;
|
|
1194
|
-
}));
|
|
1195
|
-
_RemoteSolanaMobileWalletAdapterWallet_performSignIn.set(this, (input) => __awaiter(this, void 0, void 0, function* () {
|
|
1196
|
-
var _g, _h, _j;
|
|
1197
|
-
__classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, true, "f");
|
|
1198
|
-
try {
|
|
1199
|
-
const authorizationResult = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this, Object.assign(Object.assign({}, input), { domain: (_g = input === null || input === void 0 ? void 0 : input.domain) !== null && _g !== void 0 ? _g : window.location.host }));
|
|
1200
|
-
if (!authorizationResult.sign_in_result) {
|
|
1201
|
-
throw new Error("Sign in failed, no sign in result returned by wallet");
|
|
1202
|
-
}
|
|
1203
|
-
const signedInAddress = authorizationResult.sign_in_result.address;
|
|
1204
|
-
const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
|
|
1205
|
-
return {
|
|
1206
|
-
account: Object.assign(Object.assign({}, signedInAccount !== null && signedInAccount !== void 0 ? signedInAccount : {
|
|
1207
|
-
address: base58__default["default"].encode(toUint8Array(signedInAddress))
|
|
1208
|
-
}), { publicKey: toUint8Array(signedInAddress), chains: (_h = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.chains) !== null && _h !== void 0 ? _h : __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f"), features: (_j = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.features) !== null && _j !== void 0 ? _j : authorizationResult.capabilities.features }),
|
|
1209
|
-
signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
|
|
1210
|
-
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
1211
|
-
};
|
|
1212
|
-
}
|
|
1213
|
-
catch (e) {
|
|
1214
|
-
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1054
|
+
// recurse, to avoid duplicating above logic
|
|
1055
|
+
return await checkLocalNetworkAccessPermission();
|
|
1215
1056
|
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1057
|
+
}
|
|
1058
|
+
// Shouldn't ever get here
|
|
1059
|
+
throw new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, 'Local Network Access permission unknown');
|
|
1060
|
+
}
|
|
1061
|
+
catch (e) {
|
|
1062
|
+
if (e instanceof TypeError &&
|
|
1063
|
+
(e.message.includes('loopback-network') ||
|
|
1064
|
+
e.message.includes('local-network-access'))) {
|
|
1065
|
+
// LNA permission API not found, continuing
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
// Re-throw existing adapter errors as-is
|
|
1069
|
+
if (e instanceof mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError) {
|
|
1070
|
+
throw e;
|
|
1071
|
+
}
|
|
1072
|
+
// An unknown error occurred, wrap it
|
|
1073
|
+
throw new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_LOOPBACK_ACCESS_BLOCKED, e instanceof Error ? e.message : 'Local Network Access permission unknown');
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
const SolanaMobileWalletAdapterWalletName = 'Mobile Wallet Adapter';
|
|
1078
|
+
const SolanaMobileWalletAdapterRemoteWalletName = 'Remote Mobile Wallet Adapter';
|
|
1079
|
+
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
1080
|
+
const DEFAULT_FEATURES = [walletStandardFeatures.SolanaSignAndSendTransaction, walletStandardFeatures.SolanaSignTransaction, walletStandardFeatures.SolanaSignMessage, walletStandardFeatures.SolanaSignIn];
|
|
1081
|
+
const WALLET_ASSOCIATION_TIMEOUT = 30_000;
|
|
1082
|
+
class LocalSolanaMobileWalletAdapterWallet {
|
|
1083
|
+
#listeners = {};
|
|
1084
|
+
#version = '1.0.0'; // wallet-standard version
|
|
1085
|
+
#name = SolanaMobileWalletAdapterWalletName;
|
|
1086
|
+
#url = 'https://solanamobile.com/wallets';
|
|
1087
|
+
#icon = icon;
|
|
1088
|
+
#appIdentity;
|
|
1089
|
+
#authorization;
|
|
1090
|
+
#authorizationCache;
|
|
1091
|
+
#connecting = false;
|
|
1092
|
+
/**
|
|
1093
|
+
* Every time the connection is recycled in some way (eg. `disconnect()` is called)
|
|
1094
|
+
* increment this and use it to make sure that `transact` calls from the previous
|
|
1095
|
+
* 'generation' don't continue to do work and throw exceptions.
|
|
1096
|
+
*/
|
|
1097
|
+
#connectionGeneration = 0;
|
|
1098
|
+
#chains = [];
|
|
1099
|
+
#chainSelector;
|
|
1100
|
+
#optionalFeatures;
|
|
1101
|
+
#onWalletNotFound;
|
|
1102
|
+
get version() {
|
|
1103
|
+
return this.#version;
|
|
1104
|
+
}
|
|
1105
|
+
get name() {
|
|
1106
|
+
return this.#name;
|
|
1107
|
+
}
|
|
1108
|
+
get url() {
|
|
1109
|
+
return this.#url;
|
|
1110
|
+
}
|
|
1111
|
+
get icon() {
|
|
1112
|
+
return this.#icon;
|
|
1113
|
+
}
|
|
1114
|
+
get chains() {
|
|
1115
|
+
return this.#chains;
|
|
1116
|
+
}
|
|
1117
|
+
get features() {
|
|
1118
|
+
return {
|
|
1119
|
+
[features.StandardConnect]: {
|
|
1120
|
+
version: '1.0.0',
|
|
1121
|
+
connect: this.#connect,
|
|
1122
|
+
},
|
|
1123
|
+
[features.StandardDisconnect]: {
|
|
1124
|
+
version: '1.0.0',
|
|
1125
|
+
disconnect: this.#disconnect,
|
|
1126
|
+
},
|
|
1127
|
+
[features.StandardEvents]: {
|
|
1128
|
+
version: '1.0.0',
|
|
1129
|
+
on: this.#on,
|
|
1130
|
+
},
|
|
1131
|
+
[walletStandardFeatures.SolanaSignMessage]: {
|
|
1132
|
+
version: '1.0.0',
|
|
1133
|
+
signMessage: this.#signMessage,
|
|
1134
|
+
},
|
|
1135
|
+
[walletStandardFeatures.SolanaSignIn]: {
|
|
1136
|
+
version: '1.0.0',
|
|
1137
|
+
signIn: this.#signIn,
|
|
1138
|
+
},
|
|
1139
|
+
...this.#optionalFeatures,
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
get accounts() {
|
|
1143
|
+
return this.#authorization?.accounts ?? [];
|
|
1144
|
+
}
|
|
1145
|
+
constructor(config) {
|
|
1146
|
+
this.#authorizationCache = config.authorizationCache;
|
|
1147
|
+
this.#appIdentity = config.appIdentity;
|
|
1148
|
+
this.#chains = config.chains;
|
|
1149
|
+
this.#chainSelector = config.chainSelector;
|
|
1150
|
+
this.#onWalletNotFound = config.onWalletNotFound;
|
|
1151
|
+
this.#optionalFeatures = {
|
|
1227
1152
|
// In MWA 1.0, signAndSend is optional and signTransaction is mandatory. Whereas in MWA 2.0+,
|
|
1228
1153
|
// signAndSend is mandatory and signTransaction is optional (and soft deprecated). As of mid
|
|
1229
1154
|
// 2025, all MWA wallets support both signAndSendTransaction and signTransaction so its safe
|
|
@@ -1232,176 +1157,772 @@ class RemoteSolanaMobileWalletAdapterWallet {
|
|
|
1232
1157
|
[walletStandardFeatures.SolanaSignAndSendTransaction]: {
|
|
1233
1158
|
version: '1.0.0',
|
|
1234
1159
|
supportedTransactionVersions: ['legacy', 0],
|
|
1235
|
-
signAndSendTransaction:
|
|
1160
|
+
signAndSendTransaction: this.#signAndSendTransaction,
|
|
1236
1161
|
},
|
|
1237
1162
|
[walletStandardFeatures.SolanaSignTransaction]: {
|
|
1238
1163
|
version: '1.0.0',
|
|
1239
1164
|
supportedTransactionVersions: ['legacy', 0],
|
|
1240
|
-
signTransaction:
|
|
1165
|
+
signTransaction: this.#signTransaction,
|
|
1241
1166
|
},
|
|
1242
|
-
}
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
get connected() {
|
|
1170
|
+
return !!this.#authorization;
|
|
1171
|
+
}
|
|
1172
|
+
get isAuthorized() {
|
|
1173
|
+
return !!this.#authorization;
|
|
1174
|
+
}
|
|
1175
|
+
get currentAuthorization() {
|
|
1176
|
+
return this.#authorization;
|
|
1177
|
+
}
|
|
1178
|
+
get cachedAuthorizationResult() {
|
|
1179
|
+
return this.#authorizationCache.get();
|
|
1180
|
+
}
|
|
1181
|
+
#on = (event, listener) => {
|
|
1182
|
+
this.#listeners[event]?.push(listener) || (this.#listeners[event] = [listener]);
|
|
1183
|
+
return () => this.#off(event, listener);
|
|
1184
|
+
};
|
|
1185
|
+
#emit(event, ...args) {
|
|
1186
|
+
// eslint-disable-next-line prefer-spread
|
|
1187
|
+
this.#listeners[event]?.forEach((listener) => listener.apply(null, args));
|
|
1188
|
+
}
|
|
1189
|
+
#off(event, listener) {
|
|
1190
|
+
this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
|
|
1243
1191
|
}
|
|
1192
|
+
#connect = async ({ silent } = {}) => {
|
|
1193
|
+
if (this.#connecting || this.connected) {
|
|
1194
|
+
return { accounts: this.accounts };
|
|
1195
|
+
}
|
|
1196
|
+
this.#connecting = true;
|
|
1197
|
+
try {
|
|
1198
|
+
if (silent) {
|
|
1199
|
+
const cachedAuthorization = await this.#authorizationCache.get();
|
|
1200
|
+
if (cachedAuthorization) {
|
|
1201
|
+
await this.#handleWalletCapabilitiesResult(cachedAuthorization.capabilities);
|
|
1202
|
+
await this.#handleAuthorizationResult(cachedAuthorization);
|
|
1203
|
+
}
|
|
1204
|
+
else {
|
|
1205
|
+
return { accounts: this.accounts };
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
else {
|
|
1209
|
+
await this.#performAuthorization();
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
catch (e) {
|
|
1213
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1214
|
+
}
|
|
1215
|
+
finally {
|
|
1216
|
+
this.#connecting = false;
|
|
1217
|
+
}
|
|
1218
|
+
return { accounts: this.accounts };
|
|
1219
|
+
};
|
|
1220
|
+
#performAuthorization = async (signInPayload) => {
|
|
1221
|
+
try {
|
|
1222
|
+
const cachedAuthorizationResult = await this.#authorizationCache.get();
|
|
1223
|
+
if (cachedAuthorizationResult) {
|
|
1224
|
+
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
1225
|
+
this.#handleAuthorizationResult(cachedAuthorizationResult);
|
|
1226
|
+
return cachedAuthorizationResult;
|
|
1227
|
+
}
|
|
1228
|
+
const selectedChain = await this.#chainSelector.select(this.#chains);
|
|
1229
|
+
return await this.#transact(async (wallet) => {
|
|
1230
|
+
const [capabilities, mwaAuthorizationResult] = await Promise.all([
|
|
1231
|
+
wallet.getCapabilities(),
|
|
1232
|
+
wallet.authorize({
|
|
1233
|
+
chain: selectedChain,
|
|
1234
|
+
identity: this.#appIdentity,
|
|
1235
|
+
sign_in_payload: signInPayload,
|
|
1236
|
+
})
|
|
1237
|
+
]);
|
|
1238
|
+
const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
|
|
1239
|
+
const authorization = { ...mwaAuthorizationResult,
|
|
1240
|
+
accounts, chain: selectedChain, capabilities: capabilities };
|
|
1241
|
+
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
1242
|
+
Promise.all([
|
|
1243
|
+
this.#handleWalletCapabilitiesResult(capabilities),
|
|
1244
|
+
this.#authorizationCache.set(authorization),
|
|
1245
|
+
this.#handleAuthorizationResult(authorization),
|
|
1246
|
+
]);
|
|
1247
|
+
return authorization;
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
catch (e) {
|
|
1251
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
#handleAuthorizationResult = async (authorization) => {
|
|
1255
|
+
const didPublicKeysChange =
|
|
1256
|
+
// Case 1: We started from having no authorization.
|
|
1257
|
+
this.#authorization == null ||
|
|
1258
|
+
// Case 2: The number of authorized accounts changed.
|
|
1259
|
+
this.#authorization?.accounts.length !== authorization.accounts.length ||
|
|
1260
|
+
// Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
|
|
1261
|
+
this.#authorization.accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
|
|
1262
|
+
this.#authorization = authorization;
|
|
1263
|
+
if (didPublicKeysChange) {
|
|
1264
|
+
this.#emit('change', { accounts: this.accounts });
|
|
1265
|
+
}
|
|
1266
|
+
};
|
|
1267
|
+
#handleWalletCapabilitiesResult = async (capabilities) => {
|
|
1268
|
+
// TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
|
|
1269
|
+
const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
|
|
1270
|
+
const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions;
|
|
1271
|
+
const didCapabilitiesChange = walletStandardFeatures.SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
|
|
1272
|
+
walletStandardFeatures.SolanaSignTransaction in this.features !== supportsSignTransaction;
|
|
1273
|
+
this.#optionalFeatures = {
|
|
1274
|
+
...((supportsSignAndSendTransaction || (!supportsSignAndSendTransaction && !supportsSignTransaction)) && {
|
|
1275
|
+
[walletStandardFeatures.SolanaSignAndSendTransaction]: {
|
|
1276
|
+
version: '1.0.0',
|
|
1277
|
+
supportedTransactionVersions: ['legacy', 0],
|
|
1278
|
+
signAndSendTransaction: this.#signAndSendTransaction,
|
|
1279
|
+
},
|
|
1280
|
+
}),
|
|
1281
|
+
...(supportsSignTransaction && {
|
|
1282
|
+
[walletStandardFeatures.SolanaSignTransaction]: {
|
|
1283
|
+
version: '1.0.0',
|
|
1284
|
+
supportedTransactionVersions: ['legacy', 0],
|
|
1285
|
+
signTransaction: this.#signTransaction,
|
|
1286
|
+
},
|
|
1287
|
+
}),
|
|
1288
|
+
};
|
|
1289
|
+
if (didCapabilitiesChange) {
|
|
1290
|
+
this.#emit('change', { features: this.features });
|
|
1291
|
+
}
|
|
1292
|
+
};
|
|
1293
|
+
#performReauthorization = async (wallet, authToken, chain) => {
|
|
1294
|
+
try {
|
|
1295
|
+
const [capabilities, mwaAuthorizationResult] = await Promise.all([
|
|
1296
|
+
this.#authorization?.capabilities ?? await wallet.getCapabilities(),
|
|
1297
|
+
wallet.authorize({
|
|
1298
|
+
auth_token: authToken,
|
|
1299
|
+
identity: this.#appIdentity,
|
|
1300
|
+
chain: chain
|
|
1301
|
+
})
|
|
1302
|
+
]);
|
|
1303
|
+
const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
|
|
1304
|
+
const authorization = { ...mwaAuthorizationResult,
|
|
1305
|
+
accounts: accounts, chain: chain, capabilities: capabilities
|
|
1306
|
+
};
|
|
1307
|
+
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
1308
|
+
Promise.all([
|
|
1309
|
+
this.#authorizationCache.set(authorization),
|
|
1310
|
+
this.#handleAuthorizationResult(authorization),
|
|
1311
|
+
]);
|
|
1312
|
+
}
|
|
1313
|
+
catch (e) {
|
|
1314
|
+
this.#disconnect();
|
|
1315
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
#disconnect = async () => {
|
|
1319
|
+
this.#authorizationCache.clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
1320
|
+
this.#connecting = false;
|
|
1321
|
+
this.#connectionGeneration++;
|
|
1322
|
+
this.#authorization = undefined;
|
|
1323
|
+
this.#emit('change', { accounts: this.accounts });
|
|
1324
|
+
};
|
|
1325
|
+
#transact = async (callback) => {
|
|
1326
|
+
const walletUriBase = this.#authorization?.wallet_uri_base;
|
|
1327
|
+
const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
|
|
1328
|
+
const currentConnectionGeneration = this.#connectionGeneration;
|
|
1329
|
+
const loadingSpinner = new EmbeddedLoadingSpinner();
|
|
1330
|
+
try {
|
|
1331
|
+
// check that we have permissions for local app connections, then run
|
|
1332
|
+
// wallet association (transact). In case the user manually cancels
|
|
1333
|
+
// the wallet association, cancel the connection after a timeout.
|
|
1334
|
+
let associating = true;
|
|
1335
|
+
let timeout = undefined;
|
|
1336
|
+
const result = await Promise.race([
|
|
1337
|
+
checkLocalNetworkAccessPermission()
|
|
1338
|
+
.then(async () => {
|
|
1339
|
+
// Begin local connection, show loading spinner while we connect
|
|
1340
|
+
loadingSpinner.init();
|
|
1341
|
+
const { wallet, close } = await mobileWalletAdapterProtocol.startScenario(config);
|
|
1342
|
+
loadingSpinner.addEventListener('close', (event) => { if (event)
|
|
1343
|
+
close(); });
|
|
1344
|
+
loadingSpinner.open();
|
|
1345
|
+
const result = await callback(await wallet);
|
|
1346
|
+
loadingSpinner.close();
|
|
1347
|
+
close();
|
|
1348
|
+
return result;
|
|
1349
|
+
}),
|
|
1350
|
+
new Promise((_, reject) => {
|
|
1351
|
+
timeout = setTimeout(() => {
|
|
1352
|
+
if (associating) { // only timeout during association
|
|
1353
|
+
reject(new mobileWalletAdapterProtocol.SolanaMobileWalletAdapterError(mobileWalletAdapterProtocol.SolanaMobileWalletAdapterErrorCode.ERROR_ASSOCIATION_CANCELLED, 'Wallet connection timed out', { event: undefined }));
|
|
1354
|
+
}
|
|
1355
|
+
}, WALLET_ASSOCIATION_TIMEOUT);
|
|
1356
|
+
})
|
|
1357
|
+
]);
|
|
1358
|
+
clearTimeout(timeout);
|
|
1359
|
+
return result;
|
|
1360
|
+
}
|
|
1361
|
+
catch (e) {
|
|
1362
|
+
loadingSpinner.close();
|
|
1363
|
+
if (this.#connectionGeneration !== currentConnectionGeneration) {
|
|
1364
|
+
await new Promise(() => { }); // Never resolve.
|
|
1365
|
+
}
|
|
1366
|
+
if (e instanceof Error &&
|
|
1367
|
+
e.name === 'SolanaMobileWalletAdapterError' &&
|
|
1368
|
+
e.code === 'ERROR_WALLET_NOT_FOUND') {
|
|
1369
|
+
await this.#onWalletNotFound(this);
|
|
1370
|
+
}
|
|
1371
|
+
throw e;
|
|
1372
|
+
}
|
|
1373
|
+
};
|
|
1374
|
+
#assertIsAuthorized = () => {
|
|
1375
|
+
if (!this.#authorization)
|
|
1376
|
+
throw new Error('Wallet not connected');
|
|
1377
|
+
return { authToken: this.#authorization.auth_token, chain: this.#authorization.chain };
|
|
1378
|
+
};
|
|
1379
|
+
#accountsToWalletStandardAccounts = (accounts) => {
|
|
1380
|
+
return accounts.map((account) => {
|
|
1381
|
+
const publicKey = toUint8Array(account.address);
|
|
1382
|
+
return {
|
|
1383
|
+
address: base58.encode(publicKey),
|
|
1384
|
+
publicKey,
|
|
1385
|
+
label: account.label,
|
|
1386
|
+
icon: account.icon,
|
|
1387
|
+
chains: account.chains ?? this.#chains,
|
|
1388
|
+
// TODO: get supported features from getCapabilities API
|
|
1389
|
+
features: account.features ?? DEFAULT_FEATURES
|
|
1390
|
+
};
|
|
1391
|
+
});
|
|
1392
|
+
};
|
|
1393
|
+
#performSignTransactions = async (transactions) => {
|
|
1394
|
+
const { authToken, chain } = this.#assertIsAuthorized();
|
|
1395
|
+
try {
|
|
1396
|
+
const base64Transactions = transactions.map((tx) => { return fromUint8Array(tx); });
|
|
1397
|
+
return await this.#transact(async (wallet) => {
|
|
1398
|
+
await this.#performReauthorization(wallet, authToken, chain);
|
|
1399
|
+
const signedTransactions = (await wallet.signTransactions({
|
|
1400
|
+
payloads: base64Transactions,
|
|
1401
|
+
})).signed_payloads.map(toUint8Array);
|
|
1402
|
+
return signedTransactions;
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
catch (e) {
|
|
1406
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
#performSignAndSendTransaction = async (transaction, options) => {
|
|
1410
|
+
const { authToken, chain } = this.#assertIsAuthorized();
|
|
1411
|
+
try {
|
|
1412
|
+
return await this.#transact(async (wallet) => {
|
|
1413
|
+
const [capabilities, _1] = await Promise.all([
|
|
1414
|
+
wallet.getCapabilities(),
|
|
1415
|
+
this.#performReauthorization(wallet, authToken, chain)
|
|
1416
|
+
]);
|
|
1417
|
+
if (capabilities.supports_sign_and_send_transactions) {
|
|
1418
|
+
const base64Transaction = fromUint8Array(transaction);
|
|
1419
|
+
const signatures = (await wallet.signAndSendTransactions({
|
|
1420
|
+
...options,
|
|
1421
|
+
payloads: [base64Transaction],
|
|
1422
|
+
})).signatures.map(toUint8Array);
|
|
1423
|
+
return signatures[0];
|
|
1424
|
+
}
|
|
1425
|
+
else {
|
|
1426
|
+
throw new Error('connected wallet does not support signAndSendTransaction');
|
|
1427
|
+
}
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
catch (e) {
|
|
1431
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
#signAndSendTransaction = async (...inputs) => {
|
|
1435
|
+
const outputs = [];
|
|
1436
|
+
for (const input of inputs) {
|
|
1437
|
+
const signature = await this.#performSignAndSendTransaction(input.transaction, input.options);
|
|
1438
|
+
outputs.push({ signature });
|
|
1439
|
+
}
|
|
1440
|
+
return outputs;
|
|
1441
|
+
};
|
|
1442
|
+
#signTransaction = async (...inputs) => {
|
|
1443
|
+
return (await this.#performSignTransactions(inputs.map(({ transaction }) => transaction)))
|
|
1444
|
+
.map((signedTransaction) => {
|
|
1445
|
+
return { signedTransaction };
|
|
1446
|
+
});
|
|
1447
|
+
};
|
|
1448
|
+
#signMessage = async (...inputs) => {
|
|
1449
|
+
const { authToken, chain } = this.#assertIsAuthorized();
|
|
1450
|
+
const addresses = inputs.map(({ account }) => fromUint8Array(new Uint8Array(account.publicKey)));
|
|
1451
|
+
const messages = inputs.map(({ message }) => fromUint8Array(message));
|
|
1452
|
+
try {
|
|
1453
|
+
return await this.#transact(async (wallet) => {
|
|
1454
|
+
await this.#performReauthorization(wallet, authToken, chain);
|
|
1455
|
+
const signedMessages = (await wallet.signMessages({
|
|
1456
|
+
addresses: addresses,
|
|
1457
|
+
payloads: messages,
|
|
1458
|
+
})).signed_payloads.map(toUint8Array);
|
|
1459
|
+
return signedMessages.map((signedMessage) => {
|
|
1460
|
+
return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
|
|
1461
|
+
});
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
catch (e) {
|
|
1465
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1466
|
+
}
|
|
1467
|
+
};
|
|
1468
|
+
#signIn = async (...inputs) => {
|
|
1469
|
+
const outputs = [];
|
|
1470
|
+
if (inputs.length > 1) {
|
|
1471
|
+
for (const input of inputs) {
|
|
1472
|
+
outputs.push(await this.#performSignIn(input));
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
else {
|
|
1476
|
+
return [await this.#performSignIn(inputs[0])];
|
|
1477
|
+
}
|
|
1478
|
+
return outputs;
|
|
1479
|
+
};
|
|
1480
|
+
#performSignIn = async (input) => {
|
|
1481
|
+
this.#connecting = true;
|
|
1482
|
+
try {
|
|
1483
|
+
const authorizationResult = await this.#performAuthorization({
|
|
1484
|
+
...input,
|
|
1485
|
+
domain: input?.domain ?? window.location.host
|
|
1486
|
+
});
|
|
1487
|
+
if (!authorizationResult.sign_in_result) {
|
|
1488
|
+
throw new Error("Sign in failed, no sign in result returned by wallet");
|
|
1489
|
+
}
|
|
1490
|
+
const signedInAddress = authorizationResult.sign_in_result.address;
|
|
1491
|
+
const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
|
|
1492
|
+
return {
|
|
1493
|
+
account: {
|
|
1494
|
+
...signedInAccount ?? {
|
|
1495
|
+
address: base58.encode(toUint8Array(signedInAddress))
|
|
1496
|
+
},
|
|
1497
|
+
publicKey: toUint8Array(signedInAddress),
|
|
1498
|
+
chains: signedInAccount?.chains ?? this.#chains,
|
|
1499
|
+
features: signedInAccount?.features ?? authorizationResult.capabilities.features
|
|
1500
|
+
},
|
|
1501
|
+
signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
|
|
1502
|
+
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
catch (e) {
|
|
1506
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1507
|
+
}
|
|
1508
|
+
finally {
|
|
1509
|
+
this.#connecting = false;
|
|
1510
|
+
}
|
|
1511
|
+
};
|
|
1512
|
+
}
|
|
1513
|
+
class RemoteSolanaMobileWalletAdapterWallet {
|
|
1514
|
+
#listeners = {};
|
|
1515
|
+
#version = '1.0.0'; // wallet-standard version
|
|
1516
|
+
#name = SolanaMobileWalletAdapterRemoteWalletName;
|
|
1517
|
+
#url = 'https://solanamobile.com/wallets';
|
|
1518
|
+
#icon = icon;
|
|
1519
|
+
#appIdentity;
|
|
1520
|
+
#authorization;
|
|
1521
|
+
#authorizationCache;
|
|
1522
|
+
#connecting = false;
|
|
1523
|
+
/**
|
|
1524
|
+
* Every time the connection is recycled in some way (eg. `disconnect()` is called)
|
|
1525
|
+
* increment this and use it to make sure that `transact` calls from the previous
|
|
1526
|
+
* 'generation' don't continue to do work and throw exceptions.
|
|
1527
|
+
*/
|
|
1528
|
+
#connectionGeneration = 0;
|
|
1529
|
+
#chains = [];
|
|
1530
|
+
#chainSelector;
|
|
1531
|
+
#optionalFeatures;
|
|
1532
|
+
#onWalletNotFound;
|
|
1533
|
+
#hostAuthority;
|
|
1534
|
+
#session;
|
|
1244
1535
|
get version() {
|
|
1245
|
-
return
|
|
1536
|
+
return this.#version;
|
|
1246
1537
|
}
|
|
1247
1538
|
get name() {
|
|
1248
|
-
return
|
|
1539
|
+
return this.#name;
|
|
1249
1540
|
}
|
|
1250
1541
|
get url() {
|
|
1251
|
-
return
|
|
1542
|
+
return this.#url;
|
|
1252
1543
|
}
|
|
1253
1544
|
get icon() {
|
|
1254
|
-
return
|
|
1545
|
+
return this.#icon;
|
|
1255
1546
|
}
|
|
1256
1547
|
get chains() {
|
|
1257
|
-
return
|
|
1548
|
+
return this.#chains;
|
|
1258
1549
|
}
|
|
1259
1550
|
get features() {
|
|
1260
|
-
return
|
|
1551
|
+
return {
|
|
1552
|
+
[features.StandardConnect]: {
|
|
1261
1553
|
version: '1.0.0',
|
|
1262
|
-
connect:
|
|
1263
|
-
},
|
|
1554
|
+
connect: this.#connect,
|
|
1555
|
+
},
|
|
1556
|
+
[features.StandardDisconnect]: {
|
|
1264
1557
|
version: '1.0.0',
|
|
1265
|
-
disconnect:
|
|
1266
|
-
},
|
|
1558
|
+
disconnect: this.#disconnect,
|
|
1559
|
+
},
|
|
1560
|
+
[features.StandardEvents]: {
|
|
1267
1561
|
version: '1.0.0',
|
|
1268
|
-
on:
|
|
1269
|
-
},
|
|
1562
|
+
on: this.#on,
|
|
1563
|
+
},
|
|
1564
|
+
[walletStandardFeatures.SolanaSignMessage]: {
|
|
1270
1565
|
version: '1.0.0',
|
|
1271
|
-
signMessage:
|
|
1272
|
-
},
|
|
1566
|
+
signMessage: this.#signMessage,
|
|
1567
|
+
},
|
|
1568
|
+
[walletStandardFeatures.SolanaSignIn]: {
|
|
1273
1569
|
version: '1.0.0',
|
|
1274
|
-
signIn:
|
|
1275
|
-
}
|
|
1570
|
+
signIn: this.#signIn,
|
|
1571
|
+
},
|
|
1572
|
+
...this.#optionalFeatures,
|
|
1573
|
+
};
|
|
1276
1574
|
}
|
|
1277
1575
|
get accounts() {
|
|
1278
|
-
|
|
1279
|
-
|
|
1576
|
+
return this.#authorization?.accounts ?? [];
|
|
1577
|
+
}
|
|
1578
|
+
constructor(config) {
|
|
1579
|
+
this.#authorizationCache = config.authorizationCache;
|
|
1580
|
+
this.#appIdentity = config.appIdentity;
|
|
1581
|
+
this.#chains = config.chains;
|
|
1582
|
+
this.#chainSelector = config.chainSelector;
|
|
1583
|
+
this.#hostAuthority = config.remoteHostAuthority;
|
|
1584
|
+
this.#onWalletNotFound = config.onWalletNotFound;
|
|
1585
|
+
this.#optionalFeatures = {
|
|
1586
|
+
// In MWA 1.0, signAndSend is optional and signTransaction is mandatory. Whereas in MWA 2.0+,
|
|
1587
|
+
// signAndSend is mandatory and signTransaction is optional (and soft deprecated). As of mid
|
|
1588
|
+
// 2025, all MWA wallets support both signAndSendTransaction and signTransaction so its safe
|
|
1589
|
+
// assume both are supported here. The features will be updated based on the actual connected
|
|
1590
|
+
// wallets capabilities during connection regardless, so this is safe.
|
|
1591
|
+
[walletStandardFeatures.SolanaSignAndSendTransaction]: {
|
|
1592
|
+
version: '1.0.0',
|
|
1593
|
+
supportedTransactionVersions: ['legacy', 0],
|
|
1594
|
+
signAndSendTransaction: this.#signAndSendTransaction,
|
|
1595
|
+
},
|
|
1596
|
+
[walletStandardFeatures.SolanaSignTransaction]: {
|
|
1597
|
+
version: '1.0.0',
|
|
1598
|
+
supportedTransactionVersions: ['legacy', 0],
|
|
1599
|
+
signTransaction: this.#signTransaction,
|
|
1600
|
+
},
|
|
1601
|
+
};
|
|
1280
1602
|
}
|
|
1281
1603
|
get connected() {
|
|
1282
|
-
return !!
|
|
1604
|
+
return !!this.#session && !!this.#authorization;
|
|
1283
1605
|
}
|
|
1284
1606
|
get isAuthorized() {
|
|
1285
|
-
return !!
|
|
1607
|
+
return !!this.#authorization;
|
|
1286
1608
|
}
|
|
1287
1609
|
get currentAuthorization() {
|
|
1288
|
-
return
|
|
1610
|
+
return this.#authorization;
|
|
1289
1611
|
}
|
|
1290
1612
|
get cachedAuthorizationResult() {
|
|
1291
|
-
return
|
|
1613
|
+
return this.#authorizationCache.get();
|
|
1292
1614
|
}
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
(
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event] = (_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
|
|
1301
|
-
};
|
|
1302
|
-
|
|
1303
|
-
var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
1304
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1305
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1306
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
1307
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
1308
|
-
};
|
|
1309
|
-
var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
1310
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1311
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
1312
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1313
|
-
};
|
|
1314
|
-
var _RegisterWalletEvent_detail;
|
|
1315
|
-
/**
|
|
1316
|
-
* Register a {@link "@wallet-standard/base".Wallet} as a Standard Wallet with the app.
|
|
1317
|
-
*
|
|
1318
|
-
* This dispatches a {@link "@wallet-standard/base".WindowRegisterWalletEvent} to notify the app that the Wallet is
|
|
1319
|
-
* ready to be registered.
|
|
1320
|
-
*
|
|
1321
|
-
* This also adds a listener for {@link "@wallet-standard/base".WindowAppReadyEvent} to listen for a notification from
|
|
1322
|
-
* the app that the app is ready to register the Wallet.
|
|
1323
|
-
*
|
|
1324
|
-
* This combination of event dispatch and listener guarantees that the Wallet will be registered synchronously as soon
|
|
1325
|
-
* as the app is ready whether the Wallet loads before or after the app.
|
|
1326
|
-
*
|
|
1327
|
-
* @param wallet Wallet to register.
|
|
1328
|
-
*
|
|
1329
|
-
* @group Wallet
|
|
1330
|
-
*/
|
|
1331
|
-
function registerWallet(wallet) {
|
|
1332
|
-
const callback = ({ register }) => register(wallet);
|
|
1333
|
-
try {
|
|
1334
|
-
window.dispatchEvent(new RegisterWalletEvent(callback));
|
|
1335
|
-
}
|
|
1336
|
-
catch (error) {
|
|
1337
|
-
console.error('wallet-standard:register-wallet event could not be dispatched\n', error);
|
|
1338
|
-
}
|
|
1339
|
-
try {
|
|
1340
|
-
window.addEventListener('wallet-standard:app-ready', ({ detail: api }) => callback(api));
|
|
1615
|
+
#on = (event, listener) => {
|
|
1616
|
+
this.#listeners[event]?.push(listener) || (this.#listeners[event] = [listener]);
|
|
1617
|
+
return () => this.#off(event, listener);
|
|
1618
|
+
};
|
|
1619
|
+
#emit(event, ...args) {
|
|
1620
|
+
// eslint-disable-next-line prefer-spread
|
|
1621
|
+
this.#listeners[event]?.forEach((listener) => listener.apply(null, args));
|
|
1341
1622
|
}
|
|
1342
|
-
|
|
1343
|
-
|
|
1623
|
+
#off(event, listener) {
|
|
1624
|
+
this.#listeners[event] = this.#listeners[event]?.filter((existingListener) => listener !== existingListener);
|
|
1344
1625
|
}
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1626
|
+
#connect = async ({ silent } = {}) => {
|
|
1627
|
+
if (this.#connecting || this.connected) {
|
|
1628
|
+
return { accounts: this.accounts };
|
|
1629
|
+
}
|
|
1630
|
+
this.#connecting = true;
|
|
1631
|
+
try {
|
|
1632
|
+
await this.#performAuthorization();
|
|
1633
|
+
}
|
|
1634
|
+
catch (e) {
|
|
1635
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1636
|
+
}
|
|
1637
|
+
finally {
|
|
1638
|
+
this.#connecting = false;
|
|
1639
|
+
}
|
|
1640
|
+
return { accounts: this.accounts };
|
|
1641
|
+
};
|
|
1642
|
+
#performAuthorization = async (signInPayload) => {
|
|
1643
|
+
try {
|
|
1644
|
+
const cachedAuthorizationResult = await this.#authorizationCache.get();
|
|
1645
|
+
if (cachedAuthorizationResult) {
|
|
1646
|
+
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
1647
|
+
this.#handleAuthorizationResult(cachedAuthorizationResult);
|
|
1648
|
+
return cachedAuthorizationResult;
|
|
1649
|
+
}
|
|
1650
|
+
if (this.#session)
|
|
1651
|
+
this.#session = undefined;
|
|
1652
|
+
const selectedChain = await this.#chainSelector.select(this.#chains);
|
|
1653
|
+
return await this.#transact(async (wallet) => {
|
|
1654
|
+
const [capabilities, mwaAuthorizationResult] = await Promise.all([
|
|
1655
|
+
wallet.getCapabilities(),
|
|
1656
|
+
wallet.authorize({
|
|
1657
|
+
chain: selectedChain,
|
|
1658
|
+
identity: this.#appIdentity,
|
|
1659
|
+
sign_in_payload: signInPayload,
|
|
1660
|
+
})
|
|
1661
|
+
]);
|
|
1662
|
+
const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
|
|
1663
|
+
const authorizationResult = { ...mwaAuthorizationResult,
|
|
1664
|
+
accounts, chain: selectedChain, capabilities: capabilities };
|
|
1665
|
+
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
1666
|
+
Promise.all([
|
|
1667
|
+
this.#handleWalletCapabilitiesResult(capabilities),
|
|
1668
|
+
this.#authorizationCache.set(authorizationResult),
|
|
1669
|
+
this.#handleAuthorizationResult(authorizationResult),
|
|
1670
|
+
]);
|
|
1671
|
+
return authorizationResult;
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1674
|
+
catch (e) {
|
|
1675
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1676
|
+
}
|
|
1677
|
+
};
|
|
1678
|
+
#handleAuthorizationResult = async (authorization) => {
|
|
1679
|
+
const didPublicKeysChange =
|
|
1680
|
+
// Case 1: We started from having no authorization.
|
|
1681
|
+
this.#authorization == null ||
|
|
1682
|
+
// Case 2: The number of authorized accounts changed.
|
|
1683
|
+
this.#authorization?.accounts.length !== authorization.accounts.length ||
|
|
1684
|
+
// Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
|
|
1685
|
+
this.#authorization.accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
|
|
1686
|
+
this.#authorization = authorization;
|
|
1687
|
+
if (didPublicKeysChange) {
|
|
1688
|
+
this.#emit('change', { accounts: this.accounts });
|
|
1689
|
+
}
|
|
1690
|
+
};
|
|
1691
|
+
#handleWalletCapabilitiesResult = async (capabilities) => {
|
|
1692
|
+
// TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
|
|
1693
|
+
const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
|
|
1694
|
+
const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions ||
|
|
1695
|
+
capabilities.features.includes('solana:signAndSendTransaction');
|
|
1696
|
+
const didCapabilitiesChange = walletStandardFeatures.SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
|
|
1697
|
+
walletStandardFeatures.SolanaSignTransaction in this.features !== supportsSignTransaction;
|
|
1698
|
+
this.#optionalFeatures = {
|
|
1699
|
+
...(supportsSignAndSendTransaction && {
|
|
1700
|
+
[walletStandardFeatures.SolanaSignAndSendTransaction]: {
|
|
1701
|
+
version: '1.0.0',
|
|
1702
|
+
supportedTransactionVersions: capabilities.supported_transaction_versions,
|
|
1703
|
+
signAndSendTransaction: this.#signAndSendTransaction,
|
|
1704
|
+
},
|
|
1705
|
+
}),
|
|
1706
|
+
...(supportsSignTransaction && {
|
|
1707
|
+
[walletStandardFeatures.SolanaSignTransaction]: {
|
|
1708
|
+
version: '1.0.0',
|
|
1709
|
+
supportedTransactionVersions: capabilities.supported_transaction_versions,
|
|
1710
|
+
signTransaction: this.#signTransaction,
|
|
1711
|
+
},
|
|
1712
|
+
}),
|
|
1713
|
+
};
|
|
1714
|
+
if (didCapabilitiesChange) {
|
|
1715
|
+
this.#emit('change', { features: this.features });
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
#performReauthorization = async (wallet, authToken, chain) => {
|
|
1719
|
+
try {
|
|
1720
|
+
const [capabilities, mwaAuthorizationResult] = await Promise.all([
|
|
1721
|
+
this.#authorization?.capabilities ?? await wallet.getCapabilities(),
|
|
1722
|
+
wallet.authorize({
|
|
1723
|
+
auth_token: authToken,
|
|
1724
|
+
identity: this.#appIdentity,
|
|
1725
|
+
chain: chain
|
|
1726
|
+
})
|
|
1727
|
+
]);
|
|
1728
|
+
const accounts = this.#accountsToWalletStandardAccounts(mwaAuthorizationResult.accounts);
|
|
1729
|
+
const authorization = { ...mwaAuthorizationResult,
|
|
1730
|
+
accounts: accounts, chain: chain, capabilities: capabilities };
|
|
1731
|
+
// TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
1732
|
+
Promise.all([
|
|
1733
|
+
this.#authorizationCache.set(authorization),
|
|
1734
|
+
this.#handleAuthorizationResult(authorization),
|
|
1735
|
+
]);
|
|
1736
|
+
}
|
|
1737
|
+
catch (e) {
|
|
1738
|
+
this.#disconnect();
|
|
1739
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
#disconnect = async () => {
|
|
1743
|
+
this.#session?.close();
|
|
1744
|
+
this.#authorizationCache.clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
|
|
1745
|
+
this.#connecting = false;
|
|
1746
|
+
this.#connectionGeneration++;
|
|
1747
|
+
this.#authorization = undefined;
|
|
1748
|
+
this.#session = undefined;
|
|
1749
|
+
this.#emit('change', { accounts: this.accounts });
|
|
1750
|
+
};
|
|
1751
|
+
#transact = async (callback) => {
|
|
1752
|
+
const walletUriBase = this.#authorization?.wallet_uri_base;
|
|
1753
|
+
const baseConfig = walletUriBase ? { baseUri: walletUriBase } : undefined;
|
|
1754
|
+
const remoteConfig = { ...baseConfig, remoteHostAuthority: this.#hostAuthority };
|
|
1755
|
+
const currentConnectionGeneration = this.#connectionGeneration;
|
|
1756
|
+
const modal = new RemoteConnectionModal();
|
|
1757
|
+
if (this.#session) {
|
|
1758
|
+
return callback(this.#session.wallet);
|
|
1759
|
+
}
|
|
1760
|
+
try {
|
|
1761
|
+
// Begin remote connection, show modal with loading anim while we connect
|
|
1762
|
+
modal.init();
|
|
1763
|
+
modal.open();
|
|
1764
|
+
const { associationUrl, close, wallet } = await mobileWalletAdapterProtocol.startRemoteScenario(remoteConfig);
|
|
1765
|
+
// Reflector is now connected, update the connection modal with qr code
|
|
1766
|
+
const removeCloseListener = modal.addEventListener('close', (event) => {
|
|
1767
|
+
if (event)
|
|
1768
|
+
close();
|
|
1769
|
+
});
|
|
1770
|
+
modal.populateQRCode(associationUrl.toString());
|
|
1771
|
+
// Wait for the wallet to be connected, then close the connection modal and proceed
|
|
1772
|
+
this.#session = { close, wallet: await wallet };
|
|
1773
|
+
removeCloseListener();
|
|
1774
|
+
modal.close();
|
|
1775
|
+
return await callback(this.#session.wallet);
|
|
1776
|
+
}
|
|
1777
|
+
catch (e) {
|
|
1778
|
+
modal.close();
|
|
1779
|
+
if (this.#connectionGeneration !== currentConnectionGeneration) {
|
|
1780
|
+
await new Promise(() => { }); // Never resolve.
|
|
1781
|
+
}
|
|
1782
|
+
if (e instanceof Error &&
|
|
1783
|
+
e.name === 'SolanaMobileWalletAdapterError' &&
|
|
1784
|
+
e.code === 'ERROR_WALLET_NOT_FOUND') {
|
|
1785
|
+
await this.#onWalletNotFound(this);
|
|
1786
|
+
}
|
|
1787
|
+
throw e;
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
#assertIsAuthorized = () => {
|
|
1791
|
+
if (!this.#authorization)
|
|
1792
|
+
throw new Error('Wallet not connected');
|
|
1793
|
+
return { authToken: this.#authorization.auth_token, chain: this.#authorization.chain };
|
|
1794
|
+
};
|
|
1795
|
+
#accountsToWalletStandardAccounts = (accounts) => {
|
|
1796
|
+
return accounts.map((account) => {
|
|
1797
|
+
const publicKey = toUint8Array(account.address);
|
|
1798
|
+
return {
|
|
1799
|
+
address: base58.encode(publicKey),
|
|
1800
|
+
publicKey,
|
|
1801
|
+
label: account.label,
|
|
1802
|
+
icon: account.icon,
|
|
1803
|
+
chains: account.chains ?? this.#chains,
|
|
1804
|
+
// TODO: get supported features from getCapabilities API
|
|
1805
|
+
features: account.features ?? DEFAULT_FEATURES
|
|
1806
|
+
};
|
|
1352
1807
|
});
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
(
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
};
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1808
|
+
};
|
|
1809
|
+
#performSignTransactions = async (transactions) => {
|
|
1810
|
+
const { authToken, chain } = this.#assertIsAuthorized();
|
|
1811
|
+
try {
|
|
1812
|
+
return await this.#transact(async (wallet) => {
|
|
1813
|
+
await this.#performReauthorization(wallet, authToken, chain);
|
|
1814
|
+
const signedTransactions = (await wallet.signTransactions({
|
|
1815
|
+
payloads: transactions.map(fromUint8Array),
|
|
1816
|
+
})).signed_payloads.map(toUint8Array);
|
|
1817
|
+
return signedTransactions;
|
|
1818
|
+
});
|
|
1819
|
+
}
|
|
1820
|
+
catch (e) {
|
|
1821
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1822
|
+
}
|
|
1823
|
+
};
|
|
1824
|
+
#performSignAndSendTransaction = async (transaction, options) => {
|
|
1825
|
+
const { authToken, chain } = this.#assertIsAuthorized();
|
|
1826
|
+
try {
|
|
1827
|
+
return await this.#transact(async (wallet) => {
|
|
1828
|
+
const [capabilities, _1] = await Promise.all([
|
|
1829
|
+
wallet.getCapabilities(),
|
|
1830
|
+
this.#performReauthorization(wallet, authToken, chain)
|
|
1831
|
+
]);
|
|
1832
|
+
if (capabilities.supports_sign_and_send_transactions) {
|
|
1833
|
+
const signatures = (await wallet.signAndSendTransactions({
|
|
1834
|
+
...options,
|
|
1835
|
+
payloads: [fromUint8Array(transaction)],
|
|
1836
|
+
})).signatures.map(toUint8Array);
|
|
1837
|
+
return signatures[0];
|
|
1838
|
+
}
|
|
1839
|
+
else {
|
|
1840
|
+
throw new Error('connected wallet does not support signAndSendTransaction');
|
|
1841
|
+
}
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
catch (e) {
|
|
1845
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1846
|
+
}
|
|
1847
|
+
};
|
|
1848
|
+
#signAndSendTransaction = async (...inputs) => {
|
|
1849
|
+
const outputs = [];
|
|
1850
|
+
for (const input of inputs) {
|
|
1851
|
+
const signature = (await this.#performSignAndSendTransaction(input.transaction, input.options));
|
|
1852
|
+
outputs.push({ signature });
|
|
1853
|
+
}
|
|
1854
|
+
return outputs;
|
|
1855
|
+
};
|
|
1856
|
+
#signTransaction = async (...inputs) => {
|
|
1857
|
+
return (await this.#performSignTransactions(inputs.map(({ transaction }) => transaction)))
|
|
1858
|
+
.map((signedTransaction) => {
|
|
1859
|
+
return { signedTransaction };
|
|
1860
|
+
});
|
|
1861
|
+
};
|
|
1862
|
+
#signMessage = async (...inputs) => {
|
|
1863
|
+
const { authToken, chain } = this.#assertIsAuthorized();
|
|
1864
|
+
const addresses = inputs.map(({ account }) => fromUint8Array(new Uint8Array(account.publicKey)));
|
|
1865
|
+
const messages = inputs.map(({ message }) => fromUint8Array(message));
|
|
1866
|
+
try {
|
|
1867
|
+
return await this.#transact(async (wallet) => {
|
|
1868
|
+
await this.#performReauthorization(wallet, authToken, chain);
|
|
1869
|
+
const signedMessages = (await wallet.signMessages({
|
|
1870
|
+
addresses: addresses,
|
|
1871
|
+
payloads: messages,
|
|
1872
|
+
})).signed_payloads.map(toUint8Array);
|
|
1873
|
+
return signedMessages.map((signedMessage) => {
|
|
1874
|
+
return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
|
|
1875
|
+
});
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1878
|
+
catch (e) {
|
|
1879
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1880
|
+
}
|
|
1881
|
+
};
|
|
1882
|
+
#signIn = async (...inputs) => {
|
|
1883
|
+
const outputs = [];
|
|
1884
|
+
if (inputs.length > 1) {
|
|
1885
|
+
for (const input of inputs) {
|
|
1886
|
+
outputs.push(await this.#performSignIn(input));
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
else {
|
|
1890
|
+
return [await this.#performSignIn(inputs[0])];
|
|
1891
|
+
}
|
|
1892
|
+
return outputs;
|
|
1893
|
+
};
|
|
1894
|
+
#performSignIn = async (input) => {
|
|
1895
|
+
this.#connecting = true;
|
|
1896
|
+
try {
|
|
1897
|
+
const authorizationResult = await this.#performAuthorization({
|
|
1898
|
+
...input,
|
|
1899
|
+
domain: input?.domain ?? window.location.host
|
|
1900
|
+
});
|
|
1901
|
+
if (!authorizationResult.sign_in_result) {
|
|
1902
|
+
throw new Error("Sign in failed, no sign in result returned by wallet");
|
|
1903
|
+
}
|
|
1904
|
+
const signedInAddress = authorizationResult.sign_in_result.address;
|
|
1905
|
+
const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
|
|
1906
|
+
return {
|
|
1907
|
+
account: {
|
|
1908
|
+
...signedInAccount ?? {
|
|
1909
|
+
address: base58.encode(toUint8Array(signedInAddress))
|
|
1910
|
+
},
|
|
1911
|
+
publicKey: toUint8Array(signedInAddress),
|
|
1912
|
+
chains: signedInAccount?.chains ?? this.#chains,
|
|
1913
|
+
features: signedInAccount?.features ?? authorizationResult.capabilities.features
|
|
1914
|
+
},
|
|
1915
|
+
signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
|
|
1916
|
+
signature: toUint8Array(authorizationResult.sign_in_result.signature)
|
|
1917
|
+
};
|
|
1918
|
+
}
|
|
1919
|
+
catch (e) {
|
|
1920
|
+
throw new Error((e instanceof Error && e.message) || 'Unknown error');
|
|
1921
|
+
}
|
|
1922
|
+
finally {
|
|
1923
|
+
this.#connecting = false;
|
|
1924
|
+
}
|
|
1925
|
+
};
|
|
1405
1926
|
}
|
|
1406
1927
|
|
|
1407
1928
|
function registerMwa(config) {
|
|
@@ -1416,10 +1937,10 @@ function registerMwa(config) {
|
|
|
1416
1937
|
// Local association technically is possible in a webview, but we prevent registration
|
|
1417
1938
|
// by default because it usually fails in the most common cases (e.g wallet browsers).
|
|
1418
1939
|
if (getIsLocalAssociationSupported() && !isWebView(navigator.userAgent)) {
|
|
1419
|
-
registerWallet(new LocalSolanaMobileWalletAdapterWallet(config));
|
|
1940
|
+
wallet.registerWallet(new LocalSolanaMobileWalletAdapterWallet(config));
|
|
1420
1941
|
}
|
|
1421
1942
|
else if (getIsRemoteAssociationSupported() && config.remoteHostAuthority !== undefined) {
|
|
1422
|
-
registerWallet(new RemoteSolanaMobileWalletAdapterWallet(
|
|
1943
|
+
wallet.registerWallet(new RemoteSolanaMobileWalletAdapterWallet({ ...config, remoteHostAuthority: config.remoteHostAuthority }));
|
|
1423
1944
|
}
|
|
1424
1945
|
else ;
|
|
1425
1946
|
}
|
|
@@ -1427,19 +1948,15 @@ function registerMwa(config) {
|
|
|
1427
1948
|
const WALLET_NOT_FOUND_ERROR_MESSAGE = 'To use mobile wallet adapter, you must have a compatible mobile wallet application installed on your device.';
|
|
1428
1949
|
const BROWSER_NOT_SUPPORTED_ERROR_MESSAGE = 'This browser appears to be incompatible with mobile wallet adapter. Open this page in a compatible mobile browser app and try again.';
|
|
1429
1950
|
class ErrorModal extends EmbeddedModal {
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
this.contentStyles = css;
|
|
1433
|
-
this.contentHtml = ErrorDialogHtml;
|
|
1434
|
-
}
|
|
1951
|
+
contentStyles = css;
|
|
1952
|
+
contentHtml = ErrorDialogHtml;
|
|
1435
1953
|
initWithError(error) {
|
|
1436
1954
|
super.init();
|
|
1437
1955
|
this.populateError(error);
|
|
1438
1956
|
}
|
|
1439
1957
|
populateError(error) {
|
|
1440
|
-
|
|
1441
|
-
const
|
|
1442
|
-
const actionBtn = (_b = this.dom) === null || _b === void 0 ? void 0 : _b.getElementById('mobile-wallet-adapter-error-action');
|
|
1958
|
+
const errorMessageElement = this.dom?.getElementById('mobile-wallet-adapter-error-message');
|
|
1959
|
+
const actionBtn = this.dom?.getElementById('mobile-wallet-adapter-error-action');
|
|
1443
1960
|
if (errorMessageElement) {
|
|
1444
1961
|
if (error.name === 'SolanaMobileWalletAdapterError') {
|
|
1445
1962
|
switch (error.code) {
|
|
@@ -1524,46 +2041,44 @@ const css = `
|
|
|
1524
2041
|
}
|
|
1525
2042
|
`;
|
|
1526
2043
|
|
|
1527
|
-
function defaultErrorModalWalletNotFoundHandler() {
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
});
|
|
1560
|
-
}
|
|
1561
|
-
errorDialog.open();
|
|
2044
|
+
async function defaultErrorModalWalletNotFoundHandler() {
|
|
2045
|
+
if (typeof window !== 'undefined') {
|
|
2046
|
+
const userAgent = window.navigator.userAgent.toLowerCase();
|
|
2047
|
+
const errorDialog = new ErrorModal();
|
|
2048
|
+
if (userAgent.includes('wv')) { // Android WebView
|
|
2049
|
+
// MWA is not supported in this browser so we inform the user
|
|
2050
|
+
// errorDialog.initWithError(
|
|
2051
|
+
// new SolanaMobileWalletAdapterError(
|
|
2052
|
+
// SolanaMobileWalletAdapterErrorCode.ERROR_BROWSER_NOT_SUPPORTED,
|
|
2053
|
+
// ''
|
|
2054
|
+
// )
|
|
2055
|
+
// );
|
|
2056
|
+
// TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
|
|
2057
|
+
errorDialog.initWithError({
|
|
2058
|
+
name: 'SolanaMobileWalletAdapterError',
|
|
2059
|
+
code: 'ERROR_BROWSER_NOT_SUPPORTED',
|
|
2060
|
+
message: ''
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
2063
|
+
else { // Browser, user does not have a wallet installed.
|
|
2064
|
+
// errorDialog.initWithError(
|
|
2065
|
+
// new SolanaMobileWalletAdapterError(
|
|
2066
|
+
// SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND,
|
|
2067
|
+
// ''
|
|
2068
|
+
// )
|
|
2069
|
+
// );
|
|
2070
|
+
// TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
|
|
2071
|
+
errorDialog.initWithError({
|
|
2072
|
+
name: 'SolanaMobileWalletAdapterError',
|
|
2073
|
+
code: 'ERROR_WALLET_NOT_FOUND',
|
|
2074
|
+
message: ''
|
|
2075
|
+
});
|
|
1562
2076
|
}
|
|
1563
|
-
|
|
2077
|
+
errorDialog.open();
|
|
2078
|
+
}
|
|
1564
2079
|
}
|
|
1565
2080
|
function createDefaultWalletNotFoundHandler() {
|
|
1566
|
-
return () =>
|
|
2081
|
+
return async () => { defaultErrorModalWalletNotFoundHandler(); };
|
|
1567
2082
|
}
|
|
1568
2083
|
|
|
1569
2084
|
const CACHE_KEY = 'SolanaMobileWalletAdapterDefaultAuthorizationCache';
|
|
@@ -1573,70 +2088,65 @@ function createDefaultAuthorizationCache() {
|
|
|
1573
2088
|
storage = window.localStorage;
|
|
1574
2089
|
// eslint-disable-next-line no-empty
|
|
1575
2090
|
}
|
|
1576
|
-
catch
|
|
2091
|
+
catch { }
|
|
1577
2092
|
return {
|
|
1578
|
-
clear() {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
catch (_a) { }
|
|
1588
|
-
});
|
|
2093
|
+
async clear() {
|
|
2094
|
+
if (!storage) {
|
|
2095
|
+
return;
|
|
2096
|
+
}
|
|
2097
|
+
try {
|
|
2098
|
+
storage.removeItem(CACHE_KEY);
|
|
2099
|
+
// eslint-disable-next-line no-empty
|
|
2100
|
+
}
|
|
2101
|
+
catch { }
|
|
1589
2102
|
},
|
|
1590
|
-
get() {
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
return parsed || undefined;
|
|
1607
|
-
// eslint-disable-next-line no-empty
|
|
2103
|
+
async get() {
|
|
2104
|
+
if (!storage) {
|
|
2105
|
+
return;
|
|
2106
|
+
}
|
|
2107
|
+
try {
|
|
2108
|
+
const parsed = JSON.parse(storage.getItem(CACHE_KEY));
|
|
2109
|
+
if (parsed && parsed.accounts) {
|
|
2110
|
+
const parsedAccounts = parsed.accounts.map((account) => {
|
|
2111
|
+
return {
|
|
2112
|
+
...account,
|
|
2113
|
+
publicKey: 'publicKey' in account
|
|
2114
|
+
? new Uint8Array(Object.values(account.publicKey)) // Rebuild publicKey for WalletAccount
|
|
2115
|
+
: base58.decode(account.address), // Fallback, get publicKey from address
|
|
2116
|
+
};
|
|
2117
|
+
});
|
|
2118
|
+
return { ...parsed, accounts: parsedAccounts };
|
|
1608
2119
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
2120
|
+
else
|
|
2121
|
+
return parsed || undefined;
|
|
2122
|
+
// eslint-disable-next-line no-empty
|
|
2123
|
+
}
|
|
2124
|
+
catch { }
|
|
1611
2125
|
},
|
|
1612
|
-
set(authorization) {
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
catch (_a) { }
|
|
1622
|
-
});
|
|
2126
|
+
async set(authorization) {
|
|
2127
|
+
if (!storage) {
|
|
2128
|
+
return;
|
|
2129
|
+
}
|
|
2130
|
+
try {
|
|
2131
|
+
storage.setItem(CACHE_KEY, JSON.stringify(authorization));
|
|
2132
|
+
// eslint-disable-next-line no-empty
|
|
2133
|
+
}
|
|
2134
|
+
catch { }
|
|
1623
2135
|
},
|
|
1624
2136
|
};
|
|
1625
2137
|
}
|
|
1626
2138
|
|
|
1627
2139
|
function createDefaultChainSelector() {
|
|
1628
2140
|
return {
|
|
1629
|
-
select(chains) {
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
return chains[0];
|
|
1639
|
-
});
|
|
2141
|
+
async select(chains) {
|
|
2142
|
+
if (chains.length === 1) {
|
|
2143
|
+
return chains[0];
|
|
2144
|
+
}
|
|
2145
|
+
else if (chains.includes(walletStandardChains.SOLANA_MAINNET_CHAIN)) {
|
|
2146
|
+
return walletStandardChains.SOLANA_MAINNET_CHAIN;
|
|
2147
|
+
}
|
|
2148
|
+
else
|
|
2149
|
+
return chains[0];
|
|
1640
2150
|
},
|
|
1641
2151
|
};
|
|
1642
2152
|
}
|