@lukso/up-connector 0.4.0-dev.a8c9315
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/LICENSE +201 -0
- package/README.md +280 -0
- package/dist/account-modal.cjs +9 -0
- package/dist/account-modal.cjs.map +1 -0
- package/dist/account-modal.d.cts +16 -0
- package/dist/account-modal.d.ts +16 -0
- package/dist/account-modal.js +9 -0
- package/dist/account-modal.js.map +1 -0
- package/dist/auto-setup.cjs +17 -0
- package/dist/auto-setup.cjs.map +1 -0
- package/dist/auto-setup.d.cts +123 -0
- package/dist/auto-setup.d.ts +123 -0
- package/dist/auto-setup.js +17 -0
- package/dist/auto-setup.js.map +1 -0
- package/dist/avatar-CmUCtW_w.d.cts +205 -0
- package/dist/avatar-CmUCtW_w.d.ts +205 -0
- package/dist/avatar.cjs +12 -0
- package/dist/avatar.cjs.map +1 -0
- package/dist/avatar.d.cts +1 -0
- package/dist/avatar.d.ts +1 -0
- package/dist/avatar.js +12 -0
- package/dist/avatar.js.map +1 -0
- package/dist/backup-modal.cjs +9 -0
- package/dist/backup-modal.cjs.map +1 -0
- package/dist/backup-modal.d.cts +41 -0
- package/dist/backup-modal.d.ts +41 -0
- package/dist/backup-modal.js +9 -0
- package/dist/backup-modal.js.map +1 -0
- package/dist/chunk-3SGSPHOZ.js +595 -0
- package/dist/chunk-3SGSPHOZ.js.map +1 -0
- package/dist/chunk-6AYZOIFY.js +181 -0
- package/dist/chunk-6AYZOIFY.js.map +1 -0
- package/dist/chunk-6N35TCFT.js +852 -0
- package/dist/chunk-6N35TCFT.js.map +1 -0
- package/dist/chunk-7ETKG6KR.cjs +387 -0
- package/dist/chunk-7ETKG6KR.cjs.map +1 -0
- package/dist/chunk-EUXUH3YW.js +15 -0
- package/dist/chunk-EUXUH3YW.js.map +1 -0
- package/dist/chunk-GFVUWAG4.cjs +158 -0
- package/dist/chunk-GFVUWAG4.cjs.map +1 -0
- package/dist/chunk-IAKQFHFD.cjs +595 -0
- package/dist/chunk-IAKQFHFD.cjs.map +1 -0
- package/dist/chunk-MH7MP7XK.cjs +181 -0
- package/dist/chunk-MH7MP7XK.cjs.map +1 -0
- package/dist/chunk-NWCNJSG3.js +387 -0
- package/dist/chunk-NWCNJSG3.js.map +1 -0
- package/dist/chunk-NXU2DQAV.js +1128 -0
- package/dist/chunk-NXU2DQAV.js.map +1 -0
- package/dist/chunk-ORJK2YGG.cjs +852 -0
- package/dist/chunk-ORJK2YGG.cjs.map +1 -0
- package/dist/chunk-RFA6SEIS.cjs +1128 -0
- package/dist/chunk-RFA6SEIS.cjs.map +1 -0
- package/dist/chunk-XGIT7YUY.js +31 -0
- package/dist/chunk-XGIT7YUY.js.map +1 -0
- package/dist/chunk-XOKG3KIL.cjs +31 -0
- package/dist/chunk-XOKG3KIL.cjs.map +1 -0
- package/dist/chunk-YIWSPI4I.js +158 -0
- package/dist/chunk-YIWSPI4I.js.map +1 -0
- package/dist/chunk-ZBDE64SD.cjs +15 -0
- package/dist/chunk-ZBDE64SD.cjs.map +1 -0
- package/dist/connect-modal/index.cjs +20 -0
- package/dist/connect-modal/index.cjs.map +1 -0
- package/dist/connect-modal/index.d.cts +9 -0
- package/dist/connect-modal/index.d.ts +9 -0
- package/dist/connect-modal/index.js +20 -0
- package/dist/connect-modal/index.js.map +1 -0
- package/dist/index-D2orHGFi.d.cts +8 -0
- package/dist/index-D2orHGFi.d.ts +8 -0
- package/dist/index.cjs +793 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +189 -0
- package/dist/index.d.ts +189 -0
- package/dist/index.js +793 -0
- package/dist/index.js.map +1 -0
- package/dist/restore-modal.cjs +9 -0
- package/dist/restore-modal.cjs.map +1 -0
- package/dist/restore-modal.d.cts +68 -0
- package/dist/restore-modal.d.ts +68 -0
- package/dist/restore-modal.js +9 -0
- package/dist/restore-modal.js.map +1 -0
- package/dist/wagmi-CVuDs_0h.d.cts +386 -0
- package/dist/wagmi-CVuDs_0h.d.ts +386 -0
- package/package.json +158 -0
- package/src/account-modal.ts +142 -0
- package/src/auto-setup.ts +362 -0
- package/src/avatar.ts +1135 -0
- package/src/backup-modal.ts +439 -0
- package/src/connect-modal/components/connection-view.ts +398 -0
- package/src/connect-modal/components/eoa-connection-view.ts +408 -0
- package/src/connect-modal/components/qr-code-view.ts +71 -0
- package/src/connect-modal/connect-modal.base.ts +18 -0
- package/src/connect-modal/connect-modal.config.ts +27 -0
- package/src/connect-modal/connect-modal.templates.ts +21 -0
- package/src/connect-modal/connect-modal.ts +270 -0
- package/src/connect-modal/connect-modal.types.ts +104 -0
- package/src/connect-modal/images/up-cube-glass.png +0 -0
- package/src/connect-modal/index.ts +23 -0
- package/src/connect-modal/services/wagmi.ts +266 -0
- package/src/connect-modal/styles/styles.css +1 -0
- package/src/connect-modal/utils/walletConnectDeepLinkUrl.ts +43 -0
- package/src/connector.ts +544 -0
- package/src/index.ts +62 -0
- package/src/popup-instance.ts +537 -0
- package/src/restore-modal.ts +702 -0
- package/src/styles/index.ts +28 -0
- package/src/styles/styles.css +1 -0
- package/src/types/css-raw.d.ts +4 -0
- package/src/types/images.d.ts +4 -0
- package/src/types.ts +168 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,793 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkGFVUWAG4cjs = require('./chunk-GFVUWAG4.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkMH7MP7XKcjs = require('./chunk-MH7MP7XK.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkORJK2YGGcjs = require('./chunk-ORJK2YGG.cjs');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunk7ETKG6KRcjs = require('./chunk-7ETKG6KR.cjs');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var _chunkIAKQFHFDcjs = require('./chunk-IAKQFHFD.cjs');
|
|
21
|
+
require('./chunk-XOKG3KIL.cjs');
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
var _chunkRFA6SEIScjs = require('./chunk-RFA6SEIS.cjs');
|
|
32
|
+
require('./chunk-ZBDE64SD.cjs');
|
|
33
|
+
|
|
34
|
+
// src/connector.ts
|
|
35
|
+
var _transactionviewheadless = require('@lukso/transaction-view-headless');
|
|
36
|
+
var DEFAULT_CONFIG = {
|
|
37
|
+
autoConnect: false,
|
|
38
|
+
persistConnection: true,
|
|
39
|
+
storageKey: "up-connector-state",
|
|
40
|
+
chainId: 42,
|
|
41
|
+
// LUKSO mainnet
|
|
42
|
+
rpcUrl: "https://rpc.lukso.network"
|
|
43
|
+
};
|
|
44
|
+
var UPConnector = class {
|
|
45
|
+
constructor(config = {}) {
|
|
46
|
+
this.connectors = [];
|
|
47
|
+
this.connectionState = "disconnected";
|
|
48
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
49
|
+
this.init();
|
|
50
|
+
}
|
|
51
|
+
async init() {
|
|
52
|
+
await this.createAvatar();
|
|
53
|
+
this.startWagmiSync();
|
|
54
|
+
if (this.config.autoConnect && this.config.persistConnection) {
|
|
55
|
+
await this.tryAutoConnect();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Start syncing with wagmi
|
|
60
|
+
* Checks current state and subscribes to changes
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* Update global Lukso config for address resolution
|
|
64
|
+
*/
|
|
65
|
+
updateLuksoConfig(chainId) {
|
|
66
|
+
try {
|
|
67
|
+
if (chainId === 42) {
|
|
68
|
+
_transactionviewheadless.setLuksoConfig.call(void 0, {
|
|
69
|
+
chainId: 42,
|
|
70
|
+
rpcUrl: "https://rpc.lukso.network"
|
|
71
|
+
});
|
|
72
|
+
} else if (chainId === 4201) {
|
|
73
|
+
_transactionviewheadless.setLuksoConfig.call(void 0, {
|
|
74
|
+
chainId: 4201,
|
|
75
|
+
rpcUrl: "https://rpc.testnet.lukso.network"
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
_transactionviewheadless.setLuksoConfig.call(void 0, {
|
|
79
|
+
chainId,
|
|
80
|
+
rpcUrl: this.config.rpcUrl
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.warn("\u26A0\uFE0F [Connector] Failed to update Lukso config:", error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async startWagmiSync() {
|
|
88
|
+
try {
|
|
89
|
+
const account = await _chunkRFA6SEIScjs.getWagmiAccount.call(void 0, );
|
|
90
|
+
if (!account) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (account.isConnected && account.address) {
|
|
94
|
+
this.handleConnection(
|
|
95
|
+
account.address,
|
|
96
|
+
account.connector,
|
|
97
|
+
account.chainId
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
this.wagmiUnsubscribe = await _chunkRFA6SEIScjs.watchWagmiAccount.call(void 0, (account2) => {
|
|
101
|
+
if (account2.isConnected && account2.address) {
|
|
102
|
+
if (this.connectedAddress !== account2.address || this.connectedChainId !== account2.chainId) {
|
|
103
|
+
this.handleConnection(
|
|
104
|
+
account2.address,
|
|
105
|
+
account2.connector,
|
|
106
|
+
account2.chainId
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
if (this.connectionState === "connected") {
|
|
111
|
+
this.handleDisconnection();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.warn("\u26A0\uFE0F [Connector] Failed to sync with wagmi:", error);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async createAvatar() {
|
|
120
|
+
this.avatar = new (0, _chunkORJK2YGGcjs.DraggableAvatar)({
|
|
121
|
+
// Default avatar options
|
|
122
|
+
avatarSize: "medium",
|
|
123
|
+
initialPosition: "top-right",
|
|
124
|
+
fallbackText: "\u{1F464}",
|
|
125
|
+
// Override with user config
|
|
126
|
+
...this.config.avatar,
|
|
127
|
+
// Connection-specific callbacks
|
|
128
|
+
onClick: (event, data) => {
|
|
129
|
+
_optionalChain([this, 'access', _ => _.config, 'access', _2 => _2.avatar, 'optionalAccess', _3 => _3.onClick, 'optionalCall', _4 => _4(event, data)]);
|
|
130
|
+
this.handleAvatarClick(event);
|
|
131
|
+
},
|
|
132
|
+
onAddressClick: (event) => {
|
|
133
|
+
_optionalChain([this, 'access', _5 => _5.config, 'access', _6 => _6.avatar, 'optionalAccess', _7 => _7.onAddressClick, 'optionalCall', _8 => _8(event)]);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
this.updateAvatarState();
|
|
137
|
+
}
|
|
138
|
+
// TODO: Replace with Lit-based account management modal
|
|
139
|
+
// Legacy createModal() method removed - was using deprecated ConnectorModal
|
|
140
|
+
handleAvatarClick(event) {
|
|
141
|
+
if (this.connectionState === "connected") {
|
|
142
|
+
this.showAccountModal();
|
|
143
|
+
} else {
|
|
144
|
+
this.showConnectionModal();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
showConnectionModal() {
|
|
148
|
+
if (!this.connectModal) {
|
|
149
|
+
this.connectModal = document.querySelector(
|
|
150
|
+
"connect-modal"
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
if (!this.connectModal) {
|
|
154
|
+
this.connectModal = document.createElement(
|
|
155
|
+
"connect-modal"
|
|
156
|
+
);
|
|
157
|
+
document.body.appendChild(this.connectModal);
|
|
158
|
+
this.connectModal.addEventListener("connect", ((e) => {
|
|
159
|
+
const connector = e.detail.connector;
|
|
160
|
+
}));
|
|
161
|
+
this.connectModal.addEventListener("close", (() => {
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
this.connectModal.open = true;
|
|
165
|
+
}
|
|
166
|
+
showAccountModal() {
|
|
167
|
+
if (!this.connectedAddress) return;
|
|
168
|
+
if (!this.accountModal) {
|
|
169
|
+
this.accountModal = document.querySelector(
|
|
170
|
+
"account-modal"
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
if (!this.accountModal) {
|
|
174
|
+
this.accountModal = document.createElement(
|
|
175
|
+
"account-modal"
|
|
176
|
+
);
|
|
177
|
+
document.body.appendChild(this.accountModal);
|
|
178
|
+
this.accountModal.addEventListener("disconnect", () => {
|
|
179
|
+
this.handleDisconnection();
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
this.accountModal.address = this.connectedAddress;
|
|
183
|
+
this.accountModal.chainId = this.connectedChainId;
|
|
184
|
+
this.accountModal.connectorName = _optionalChain([this, 'access', _9 => _9.connectedProvider, 'optionalAccess', _10 => _10.name]) || "Unknown";
|
|
185
|
+
this.accountModal.open = true;
|
|
186
|
+
}
|
|
187
|
+
handleConnection(address, provider, chainId) {
|
|
188
|
+
this.connectedAddress = address;
|
|
189
|
+
this.connectedProvider = provider;
|
|
190
|
+
this.connectedChainId = chainId;
|
|
191
|
+
this.setConnectionState("connected");
|
|
192
|
+
if (chainId) {
|
|
193
|
+
this.updateLuksoConfig(chainId);
|
|
194
|
+
}
|
|
195
|
+
if (this.avatar) {
|
|
196
|
+
this.avatar.updateAddress(address, void 0, chainId);
|
|
197
|
+
this.avatar.setConnected(true);
|
|
198
|
+
}
|
|
199
|
+
if (this.config.persistConnection) {
|
|
200
|
+
this.saveConnectionState();
|
|
201
|
+
}
|
|
202
|
+
if (this.connectModal) {
|
|
203
|
+
this.connectModal.open = false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async handleDisconnection() {
|
|
207
|
+
await _chunkRFA6SEIScjs.disconnectWagmi.call(void 0, );
|
|
208
|
+
this.connectedAddress = void 0;
|
|
209
|
+
this.connectedProvider = void 0;
|
|
210
|
+
this.connectedChainId = void 0;
|
|
211
|
+
this.setConnectionState("disconnected");
|
|
212
|
+
if (this.avatar) {
|
|
213
|
+
this.avatar.setConnected(false);
|
|
214
|
+
this.avatar.updateAddress("");
|
|
215
|
+
}
|
|
216
|
+
if (this.config.persistConnection) {
|
|
217
|
+
this.clearConnectionState();
|
|
218
|
+
}
|
|
219
|
+
if (this.connectModal) {
|
|
220
|
+
this.connectModal.open = false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
setConnectionState(state) {
|
|
224
|
+
const prevState = this.connectionState;
|
|
225
|
+
this.connectionState = state;
|
|
226
|
+
this.updateAvatarState();
|
|
227
|
+
if (prevState !== state) {
|
|
228
|
+
_optionalChain([this, 'access', _11 => _11.config, 'access', _12 => _12.onConnectionChange, 'optionalCall', _13 => _13(state, {
|
|
229
|
+
address: this.connectedAddress,
|
|
230
|
+
provider: this.connectedProvider,
|
|
231
|
+
chainId: this.connectedChainId
|
|
232
|
+
})]);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
updateAvatarState() {
|
|
236
|
+
if (!this.avatar) return;
|
|
237
|
+
this.avatar.setConnected(this.connectionState === "connected");
|
|
238
|
+
if (this.connectionState === "connected" && this.connectedAddress) {
|
|
239
|
+
this.avatar.updateAddress(
|
|
240
|
+
this.connectedAddress,
|
|
241
|
+
void 0,
|
|
242
|
+
this.connectedChainId
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async tryAutoConnect() {
|
|
247
|
+
const savedState = this.loadConnectionState();
|
|
248
|
+
if (!_optionalChain([savedState, 'optionalAccess', _14 => _14.address])) return;
|
|
249
|
+
this.setConnectionState("connecting");
|
|
250
|
+
try {
|
|
251
|
+
setTimeout(() => {
|
|
252
|
+
if (savedState.address) {
|
|
253
|
+
this.handleConnection(savedState.address, savedState.provider);
|
|
254
|
+
} else {
|
|
255
|
+
this.setConnectionState("disconnected");
|
|
256
|
+
}
|
|
257
|
+
}, 1e3);
|
|
258
|
+
} catch (error) {
|
|
259
|
+
console.warn("Auto-connect failed:", error);
|
|
260
|
+
this.setConnectionState("disconnected");
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
saveConnectionState() {
|
|
264
|
+
if (typeof localStorage === "undefined") return;
|
|
265
|
+
try {
|
|
266
|
+
const state = {
|
|
267
|
+
address: this.connectedAddress,
|
|
268
|
+
provider: _optionalChain([this, 'access', _15 => _15.connectedProvider, 'optionalAccess', _16 => _16.constructor, 'optionalAccess', _17 => _17.name]),
|
|
269
|
+
timestamp: Date.now()
|
|
270
|
+
};
|
|
271
|
+
localStorage.setItem(this.config.storageKey, JSON.stringify(state));
|
|
272
|
+
} catch (error) {
|
|
273
|
+
console.warn("Failed to save connection state:", error);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
loadConnectionState() {
|
|
277
|
+
if (typeof localStorage === "undefined") return null;
|
|
278
|
+
try {
|
|
279
|
+
const saved = localStorage.getItem(this.config.storageKey);
|
|
280
|
+
if (!saved) return null;
|
|
281
|
+
const state = JSON.parse(saved);
|
|
282
|
+
const maxAge = 24 * 60 * 60 * 1e3;
|
|
283
|
+
if (Date.now() - state.timestamp > maxAge) {
|
|
284
|
+
this.clearConnectionState();
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
return state;
|
|
288
|
+
} catch (error) {
|
|
289
|
+
console.warn("Failed to load connection state:", error);
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
clearConnectionState() {
|
|
294
|
+
if (typeof localStorage === "undefined") return;
|
|
295
|
+
try {
|
|
296
|
+
localStorage.removeItem(this.config.storageKey);
|
|
297
|
+
} catch (error) {
|
|
298
|
+
console.warn("Failed to clear connection state:", error);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// Public API
|
|
302
|
+
getAvatar() {
|
|
303
|
+
return this.avatar;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* @deprecated Legacy modal removed. Use getConnectModal() or create account modal
|
|
307
|
+
*/
|
|
308
|
+
getModal() {
|
|
309
|
+
console.warn("getModal() is deprecated - legacy ConnectorModal removed");
|
|
310
|
+
return void 0;
|
|
311
|
+
}
|
|
312
|
+
getConnectModal() {
|
|
313
|
+
return this.connectModal;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* @deprecated Use setupConnectModal() instead to configure wagmi connectors globally
|
|
317
|
+
*/
|
|
318
|
+
setConnectors(connectors) {
|
|
319
|
+
this.connectors = connectors;
|
|
320
|
+
console.warn(
|
|
321
|
+
"setConnectors() is deprecated. Use setupConnectModal() instead."
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
async connect(providerId) {
|
|
325
|
+
this.setConnectionState("connecting");
|
|
326
|
+
if (providerId) {
|
|
327
|
+
} else {
|
|
328
|
+
this.showConnectionModal();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
disconnect() {
|
|
332
|
+
this.handleDisconnection();
|
|
333
|
+
}
|
|
334
|
+
getConnectionState() {
|
|
335
|
+
return this.connectionState;
|
|
336
|
+
}
|
|
337
|
+
getConnectedAddress() {
|
|
338
|
+
return this.connectedAddress;
|
|
339
|
+
}
|
|
340
|
+
getConnectedProvider() {
|
|
341
|
+
return this.connectedProvider;
|
|
342
|
+
}
|
|
343
|
+
isConnected() {
|
|
344
|
+
return this.connectionState === "connected";
|
|
345
|
+
}
|
|
346
|
+
showModal() {
|
|
347
|
+
if (this.isConnected()) {
|
|
348
|
+
this.showAccountModal();
|
|
349
|
+
} else {
|
|
350
|
+
this.showConnectionModal();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
hideModal() {
|
|
354
|
+
if (this.connectModal) {
|
|
355
|
+
this.connectModal.open = false;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
updateConfig(config) {
|
|
359
|
+
this.config = { ...this.config, ...config };
|
|
360
|
+
if (config.avatar && this.avatar) {
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
destroy() {
|
|
364
|
+
if (this.wagmiUnsubscribe) {
|
|
365
|
+
this.wagmiUnsubscribe();
|
|
366
|
+
this.wagmiUnsubscribe = void 0;
|
|
367
|
+
}
|
|
368
|
+
_optionalChain([this, 'access', _18 => _18.avatar, 'optionalAccess', _19 => _19.destroy, 'call', _20 => _20()]);
|
|
369
|
+
if (this.connectModal) {
|
|
370
|
+
this.connectModal.open = false;
|
|
371
|
+
if (this.connectModal.parentNode) {
|
|
372
|
+
this.connectModal.parentNode.removeChild(this.connectModal);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
this.avatar = void 0;
|
|
376
|
+
this.connectModal = void 0;
|
|
377
|
+
this.connectedAddress = void 0;
|
|
378
|
+
this.connectedProvider = void 0;
|
|
379
|
+
this.connectionState = "disconnected";
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
function createConnector(config = {}) {
|
|
383
|
+
return new UPConnector(config);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/popup-instance.ts
|
|
387
|
+
var PopupEventEmitter = class {
|
|
388
|
+
constructor() {
|
|
389
|
+
this.handlers = /* @__PURE__ */ new Map();
|
|
390
|
+
}
|
|
391
|
+
on(event, handler) {
|
|
392
|
+
if (!this.handlers.has(event)) {
|
|
393
|
+
this.handlers.set(event, /* @__PURE__ */ new Set());
|
|
394
|
+
}
|
|
395
|
+
this.handlers.get(event).add(handler);
|
|
396
|
+
}
|
|
397
|
+
off(event, handler) {
|
|
398
|
+
_optionalChain([this, 'access', _21 => _21.handlers, 'access', _22 => _22.get, 'call', _23 => _23(event), 'optionalAccess', _24 => _24.delete, 'call', _25 => _25(handler)]);
|
|
399
|
+
}
|
|
400
|
+
emit(event, ...args) {
|
|
401
|
+
_optionalChain([this, 'access', _26 => _26.handlers, 'access', _27 => _27.get, 'call', _28 => _28(event), 'optionalAccess', _29 => _29.forEach, 'call', _30 => _30((handler) => {
|
|
402
|
+
try {
|
|
403
|
+
handler(...args);
|
|
404
|
+
} catch (error) {
|
|
405
|
+
console.error("Error in popup event handler:", error);
|
|
406
|
+
}
|
|
407
|
+
})]);
|
|
408
|
+
}
|
|
409
|
+
clear() {
|
|
410
|
+
this.handlers.clear();
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
var BasePopupInstance = class {
|
|
414
|
+
constructor(request) {
|
|
415
|
+
this.request = request;
|
|
416
|
+
this.events = new PopupEventEmitter();
|
|
417
|
+
this.messageHandlers = /* @__PURE__ */ new Set();
|
|
418
|
+
this._isClosed = false;
|
|
419
|
+
this._isVisible = false;
|
|
420
|
+
}
|
|
421
|
+
get isVisible() {
|
|
422
|
+
return this._isVisible && !this._isClosed;
|
|
423
|
+
}
|
|
424
|
+
get isClosed() {
|
|
425
|
+
return this._isClosed;
|
|
426
|
+
}
|
|
427
|
+
postMessage(data) {
|
|
428
|
+
if (!this._isClosed && this.contentWindow) {
|
|
429
|
+
try {
|
|
430
|
+
this.contentWindow.postMessage(data, "*");
|
|
431
|
+
} catch (error) {
|
|
432
|
+
console.error("Failed to post message to popup:", error);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
onMessage(handler) {
|
|
437
|
+
this.messageHandlers.add(handler);
|
|
438
|
+
}
|
|
439
|
+
removeMessageHandler(handler) {
|
|
440
|
+
this.messageHandlers.delete(handler);
|
|
441
|
+
}
|
|
442
|
+
handleMessage(data) {
|
|
443
|
+
this.messageHandlers.forEach((handler) => {
|
|
444
|
+
try {
|
|
445
|
+
handler(data);
|
|
446
|
+
} catch (error) {
|
|
447
|
+
console.error("Error in popup message handler:", error);
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
this.events.emit("message", data);
|
|
451
|
+
}
|
|
452
|
+
on(event, handler) {
|
|
453
|
+
this.events.on(event, handler);
|
|
454
|
+
}
|
|
455
|
+
off(event, handler) {
|
|
456
|
+
this.events.off(event, handler);
|
|
457
|
+
}
|
|
458
|
+
cleanup() {
|
|
459
|
+
this.messageHandlers.clear();
|
|
460
|
+
this.events.clear();
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
var ModalPopupInstance = class extends BasePopupInstance {
|
|
464
|
+
async show() {
|
|
465
|
+
if (this._isClosed) {
|
|
466
|
+
throw new Error("Popup is closed");
|
|
467
|
+
}
|
|
468
|
+
if (!this.modalElement) {
|
|
469
|
+
await this.createElement();
|
|
470
|
+
}
|
|
471
|
+
return new Promise((resolve) => {
|
|
472
|
+
if (!this.modalElement) {
|
|
473
|
+
resolve();
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
if (!this.modalElement.parentNode) {
|
|
477
|
+
document.body.appendChild(this.modalElement);
|
|
478
|
+
}
|
|
479
|
+
this._isVisible = true;
|
|
480
|
+
this.modalElement.offsetHeight;
|
|
481
|
+
this.modalElement.classList.add("visible");
|
|
482
|
+
this.events.emit("show");
|
|
483
|
+
setTimeout(() => resolve(), 50);
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
hide() {
|
|
487
|
+
if (!this._isVisible || this._isClosed || !this.modalElement) return;
|
|
488
|
+
this._isVisible = false;
|
|
489
|
+
this.modalElement.classList.remove("visible");
|
|
490
|
+
this.events.emit("hide");
|
|
491
|
+
setTimeout(() => {
|
|
492
|
+
if (this.modalElement && this.modalElement.parentNode) {
|
|
493
|
+
this.modalElement.parentNode.removeChild(this.modalElement);
|
|
494
|
+
}
|
|
495
|
+
}, 300);
|
|
496
|
+
}
|
|
497
|
+
close() {
|
|
498
|
+
if (this._isClosed) return;
|
|
499
|
+
this._isClosed = true;
|
|
500
|
+
this._isVisible = false;
|
|
501
|
+
if (this.modalElement) {
|
|
502
|
+
this.modalElement.classList.remove("visible");
|
|
503
|
+
setTimeout(() => {
|
|
504
|
+
if (this.modalElement && this.modalElement.parentNode) {
|
|
505
|
+
this.modalElement.parentNode.removeChild(this.modalElement);
|
|
506
|
+
}
|
|
507
|
+
}, 300);
|
|
508
|
+
}
|
|
509
|
+
if (this.messageListener) {
|
|
510
|
+
window.removeEventListener("message", this.messageListener);
|
|
511
|
+
}
|
|
512
|
+
this.events.emit("close");
|
|
513
|
+
this.cleanup();
|
|
514
|
+
}
|
|
515
|
+
get contentWindow() {
|
|
516
|
+
return _optionalChain([this, 'access', _31 => _31.iframeElement, 'optionalAccess', _32 => _32.contentWindow]) || void 0;
|
|
517
|
+
}
|
|
518
|
+
async createElement() {
|
|
519
|
+
if (typeof document === "undefined") return;
|
|
520
|
+
await this.createStyles();
|
|
521
|
+
this.modalElement = document.createElement("div");
|
|
522
|
+
this.modalElement.className = "up-popup-modal";
|
|
523
|
+
const { width = 480, height = 640 } = this.request.size || {};
|
|
524
|
+
this.modalElement.innerHTML = `
|
|
525
|
+
<div class="up-popup-modal-content" style="width: ${width}px; height: ${height}px;">
|
|
526
|
+
<button class="up-popup-close" type="button">
|
|
527
|
+
<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor">
|
|
528
|
+
<path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" />
|
|
529
|
+
</svg>
|
|
530
|
+
</button>
|
|
531
|
+
<iframe src="${this.request.url || "about:blank"}" allow="publickey-credentials-get; publickey-credentials-create"></iframe>
|
|
532
|
+
</div>
|
|
533
|
+
`;
|
|
534
|
+
const closeButton = this.modalElement.querySelector(
|
|
535
|
+
".up-popup-close"
|
|
536
|
+
);
|
|
537
|
+
this.iframeElement = this.modalElement.querySelector(
|
|
538
|
+
"iframe"
|
|
539
|
+
);
|
|
540
|
+
closeButton.addEventListener("click", () => this.hide());
|
|
541
|
+
this.modalElement.addEventListener("click", (e) => {
|
|
542
|
+
if (e.target === this.modalElement) {
|
|
543
|
+
this.hide();
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
this.messageListener = (event) => {
|
|
547
|
+
if (event.source === _optionalChain([this, 'access', _33 => _33.iframeElement, 'optionalAccess', _34 => _34.contentWindow])) {
|
|
548
|
+
this.handleMessage(event.data);
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
window.addEventListener("message", this.messageListener);
|
|
552
|
+
}
|
|
553
|
+
async createStyles() {
|
|
554
|
+
if (typeof document === "undefined") return;
|
|
555
|
+
if (document.querySelector("#up-popup-modal-styles")) return;
|
|
556
|
+
const style = document.createElement("style");
|
|
557
|
+
style.id = "up-popup-modal-styles";
|
|
558
|
+
style.textContent = `
|
|
559
|
+
.up-popup-modal {
|
|
560
|
+
position: fixed;
|
|
561
|
+
top: 0;
|
|
562
|
+
left: 0;
|
|
563
|
+
width: 100vw;
|
|
564
|
+
height: 100vh;
|
|
565
|
+
background: rgba(0, 0, 0, 0.5);
|
|
566
|
+
backdrop-filter: blur(8px);
|
|
567
|
+
z-index: 10000;
|
|
568
|
+
display: flex;
|
|
569
|
+
align-items: center;
|
|
570
|
+
justify-content: center;
|
|
571
|
+
opacity: 0;
|
|
572
|
+
visibility: hidden;
|
|
573
|
+
transition: all 300ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
|
574
|
+
padding: 16px;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
.up-popup-modal.visible {
|
|
578
|
+
opacity: 1;
|
|
579
|
+
visibility: visible;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
.up-popup-modal-content {
|
|
583
|
+
background: white;
|
|
584
|
+
border-radius: 12px;
|
|
585
|
+
overflow: hidden;
|
|
586
|
+
position: relative;
|
|
587
|
+
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
|
|
588
|
+
transform: scale(0.95) translateY(20px);
|
|
589
|
+
transition: all 300ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
.up-popup-modal.visible .up-popup-modal-content {
|
|
593
|
+
transform: scale(1) translateY(0);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
.up-popup-close {
|
|
597
|
+
position: absolute;
|
|
598
|
+
top: 12px;
|
|
599
|
+
right: 12px;
|
|
600
|
+
z-index: 10;
|
|
601
|
+
background: rgba(255, 255, 255, 0.9);
|
|
602
|
+
border: none;
|
|
603
|
+
border-radius: 50%;
|
|
604
|
+
width: 32px;
|
|
605
|
+
height: 32px;
|
|
606
|
+
cursor: pointer;
|
|
607
|
+
display: flex;
|
|
608
|
+
align-items: center;
|
|
609
|
+
justify-content: center;
|
|
610
|
+
color: #6b7280;
|
|
611
|
+
transition: all 0.2s ease;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
.up-popup-close:hover {
|
|
615
|
+
background: rgba(255, 255, 255, 1);
|
|
616
|
+
color: #374151;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
.up-popup-modal iframe {
|
|
620
|
+
width: 100%;
|
|
621
|
+
height: 100%;
|
|
622
|
+
border: none;
|
|
623
|
+
border-radius: 12px;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
@media (max-width: 640px) {
|
|
627
|
+
.up-popup-modal {
|
|
628
|
+
padding: 0;
|
|
629
|
+
align-items: flex-end;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
.up-popup-modal-content {
|
|
633
|
+
width: 100% !important;
|
|
634
|
+
height: 85vh !important;
|
|
635
|
+
border-radius: 12px 12px 0 0;
|
|
636
|
+
transform: translateY(100%);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
.up-popup-modal.visible .up-popup-modal-content {
|
|
640
|
+
transform: translateY(0);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
.up-popup-modal iframe {
|
|
644
|
+
border-radius: 12px 12px 0 0;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
@media (max-width: 480px) {
|
|
649
|
+
.up-popup-modal {
|
|
650
|
+
align-items: stretch;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
.up-popup-modal-content {
|
|
654
|
+
height: 100vh !important;
|
|
655
|
+
border-radius: 0;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
.up-popup-modal iframe {
|
|
659
|
+
border-radius: 0;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
`;
|
|
663
|
+
document.head.appendChild(style);
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
var WindowPopupInstance = class extends BasePopupInstance {
|
|
667
|
+
constructor() {
|
|
668
|
+
super(...arguments);
|
|
669
|
+
this.popupWindow = null;
|
|
670
|
+
}
|
|
671
|
+
async show() {
|
|
672
|
+
if (this._isClosed) {
|
|
673
|
+
throw new Error("Popup is closed");
|
|
674
|
+
}
|
|
675
|
+
if (!this.popupWindow || this.popupWindow.closed) {
|
|
676
|
+
await this.createPopupWindow();
|
|
677
|
+
}
|
|
678
|
+
if (this.popupWindow && !this.popupWindow.closed) {
|
|
679
|
+
this.popupWindow.focus();
|
|
680
|
+
this._isVisible = true;
|
|
681
|
+
this.events.emit("show");
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
hide() {
|
|
685
|
+
if (this.popupWindow && !this.popupWindow.closed) {
|
|
686
|
+
this.popupWindow.blur();
|
|
687
|
+
}
|
|
688
|
+
this._isVisible = false;
|
|
689
|
+
this.events.emit("hide");
|
|
690
|
+
}
|
|
691
|
+
close() {
|
|
692
|
+
if (this._isClosed) return;
|
|
693
|
+
this._isClosed = true;
|
|
694
|
+
this._isVisible = false;
|
|
695
|
+
if (this.popupWindow && !this.popupWindow.closed) {
|
|
696
|
+
this.popupWindow.close();
|
|
697
|
+
}
|
|
698
|
+
this.popupWindow = null;
|
|
699
|
+
if (this.messageListener) {
|
|
700
|
+
window.removeEventListener("message", this.messageListener);
|
|
701
|
+
}
|
|
702
|
+
this.events.emit("close");
|
|
703
|
+
this.cleanup();
|
|
704
|
+
}
|
|
705
|
+
get contentWindow() {
|
|
706
|
+
return this.popupWindow && !this.popupWindow.closed ? this.popupWindow : void 0;
|
|
707
|
+
}
|
|
708
|
+
get isVisible() {
|
|
709
|
+
return !this._isClosed && !!(this.popupWindow && !this.popupWindow.closed);
|
|
710
|
+
}
|
|
711
|
+
async createPopupWindow() {
|
|
712
|
+
if (!this.request.url) {
|
|
713
|
+
throw new Error("URL required for popup windows");
|
|
714
|
+
}
|
|
715
|
+
const { width = 400, height = 600 } = this.request.size || {};
|
|
716
|
+
const position = this.request.position || "center";
|
|
717
|
+
const features = [
|
|
718
|
+
`width=${width}`,
|
|
719
|
+
`height=${height}`,
|
|
720
|
+
...this.getPositionFeatures(position, width, height),
|
|
721
|
+
"scrollbars=yes",
|
|
722
|
+
"resizable=yes",
|
|
723
|
+
"status=no",
|
|
724
|
+
"location=no",
|
|
725
|
+
"toolbar=no",
|
|
726
|
+
"menubar=no"
|
|
727
|
+
].join(",");
|
|
728
|
+
this.popupWindow = window.open(this.request.url, "_blank", features);
|
|
729
|
+
if (!this.popupWindow) {
|
|
730
|
+
throw new Error("Popup blocked or failed to open");
|
|
731
|
+
}
|
|
732
|
+
this.messageListener = (event) => {
|
|
733
|
+
if (event.source === this.popupWindow) {
|
|
734
|
+
this.handleMessage(event.data);
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
window.addEventListener("message", this.messageListener);
|
|
738
|
+
const checkClosed = () => {
|
|
739
|
+
if (_optionalChain([this, 'access', _35 => _35.popupWindow, 'optionalAccess', _36 => _36.closed]) && !this._isClosed) {
|
|
740
|
+
this.close();
|
|
741
|
+
} else if (!this._isClosed) {
|
|
742
|
+
setTimeout(checkClosed, 1e3);
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
setTimeout(checkClosed, 1e3);
|
|
746
|
+
}
|
|
747
|
+
getPositionFeatures(position, width, height) {
|
|
748
|
+
const screenLeft = window.screenLeft !== void 0 ? window.screenLeft : window.screenX;
|
|
749
|
+
const screenTop = window.screenTop !== void 0 ? window.screenTop : window.screenY;
|
|
750
|
+
const windowWidth = window.innerWidth || document.documentElement.clientWidth || screen.width;
|
|
751
|
+
const windowHeight = window.innerHeight || document.documentElement.clientHeight || screen.height;
|
|
752
|
+
let left;
|
|
753
|
+
let top;
|
|
754
|
+
switch (position) {
|
|
755
|
+
case "top-right":
|
|
756
|
+
left = screenLeft + windowWidth - width - 20;
|
|
757
|
+
top = screenTop + 20;
|
|
758
|
+
break;
|
|
759
|
+
case "center":
|
|
760
|
+
default:
|
|
761
|
+
left = screenLeft + (windowWidth - width) / 2;
|
|
762
|
+
top = screenTop + (windowHeight - height) / 2;
|
|
763
|
+
break;
|
|
764
|
+
}
|
|
765
|
+
return [`left=${Math.max(0, left)}`, `top=${Math.max(0, top)}`];
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
exports.AccountModal = _chunkGFVUWAG4cjs.AccountModal; exports.BackupModal = _chunk7ETKG6KRcjs.BackupModal; exports.ConnectModal = _chunkRFA6SEIScjs.ConnectModal; exports.DraggableAvatar = _chunkORJK2YGGcjs.DraggableAvatar; exports.EMBEDDED_WALLET_ID = _chunkMH7MP7XKcjs.EMBEDDED_WALLET_ID; exports.EMBEDDED_WALLET_URL_DEV = _chunkMH7MP7XKcjs.EMBEDDED_WALLET_URL_DEV; exports.EMBEDDED_WALLET_URL_PROD = _chunkMH7MP7XKcjs.EMBEDDED_WALLET_URL_PROD; exports.ModalPopupInstance = ModalPopupInstance; exports.RestoreModal = _chunkIAKQFHFDcjs.RestoreModal; exports.UPConnector = UPConnector; exports.UP_EXTENSION_ID = _chunkMH7MP7XKcjs.UP_EXTENSION_ID; exports.WindowPopupInstance = WindowPopupInstance; exports.createAvatar = _chunkORJK2YGGcjs.createAvatar; exports.createConnector = createConnector; exports.default = createConnector; exports.disconnectWagmi = _chunkRFA6SEIScjs.disconnectWagmi; exports.fromWagmiConnector = _chunkRFA6SEIScjs.fromWagmiConnector; exports.fromWagmiConnectors = _chunkRFA6SEIScjs.fromWagmiConnectors; exports.getWagmiAccount = _chunkRFA6SEIScjs.getWagmiAccount; exports.getWagmiSetup = _chunkRFA6SEIScjs.getWagmiSetup; exports.setupConnectModal = _chunkRFA6SEIScjs.setupConnectModal; exports.setupLuksoConnector = _chunkMH7MP7XKcjs.setupLuksoConnector; exports.watchWagmiAccount = _chunkRFA6SEIScjs.watchWagmiAccount;
|
|
793
|
+
//# sourceMappingURL=index.cjs.map
|