@swapper-finance/deposit-sdk 0.2.0 → 0.2.2
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 +85 -0
- package/dist/SwapperIframe.d.ts.map +1 -1
- package/dist/SwapperIframe.js +256 -1
- package/dist/SwapperIframe.js.map +1 -1
- package/dist/SwapperModal.js +175 -1
- package/dist/SwapperWalletProvider.d.ts.map +1 -1
- package/dist/SwapperWalletProvider.js +139 -1
- package/dist/SwapperWalletProvider.js.map +1 -1
- package/dist/adapters.js +136 -1
- package/dist/helpers.js +74 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/swapper-sdk.iife.js +57 -0
- package/dist/types/config.js +8 -1
- package/dist/types/events.d.ts +22 -0
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/events.js +6 -1
- package/dist/types/events.js.map +1 -1
- package/dist/types/index.js +5 -1
- package/dist/types/styles.js +2 -1
- package/dist/types/wallet.js +11 -1
- package/package.json +4 -3
- package/dist/types.d.ts +0 -53
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -1
- package/dist/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -187,6 +187,91 @@ Removes the iframe and cleans up event listeners.
|
|
|
187
187
|
swapper.destroy();
|
|
188
188
|
```
|
|
189
189
|
|
|
190
|
+
## Widget Events
|
|
191
|
+
|
|
192
|
+
The widget emits structured events via `postMessage` that you can listen to through the SDK. This lets you react to user actions like completed transactions.
|
|
193
|
+
|
|
194
|
+
### Event Envelope
|
|
195
|
+
|
|
196
|
+
Every event posted from the iframe follows this shape:
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
interface SwapperWidgetEvent {
|
|
200
|
+
type: "SWAPPER_EVENT"; // discriminator
|
|
201
|
+
version: "1.0"; // protocol version
|
|
202
|
+
name: WidgetEventName; // e.g. "transaction_success"
|
|
203
|
+
timestamp: string; // ISO 8601
|
|
204
|
+
payload: WidgetEventPayload; // event-specific data
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Listening with `on()` / `off()`
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
import { SwapperIframe, WidgetEventName } from '@swapper-finance/deposit-sdk';
|
|
212
|
+
import type { TransactionSuccessPayload } from '@swapper-finance/deposit-sdk';
|
|
213
|
+
|
|
214
|
+
const swapper = new SwapperIframe({
|
|
215
|
+
container: '#swapper-container',
|
|
216
|
+
integratorId: 'your-integrator-id',
|
|
217
|
+
dstChainId: '8453',
|
|
218
|
+
dstTokenAddr: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
219
|
+
depositWalletAddress: '0x2A018F2506acaEEE2C10632514Fc5DCa9eE2c28A',
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Listen for a specific event
|
|
223
|
+
swapper.on(WidgetEventName.TRANSACTION_SUCCESS, (event) => {
|
|
224
|
+
const payload = event.data as TransactionSuccessPayload;
|
|
225
|
+
console.log('Transaction succeeded:', payload.txHash);
|
|
226
|
+
console.log('Deposit option:', payload.depositOption); // "walletDeposit" | "transferCrypto" | "depositWithCash"
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Listen for all events with wildcard
|
|
230
|
+
swapper.on('*', (event) => {
|
|
231
|
+
console.log('Widget event:', event.type, event.data);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Remove a specific handler
|
|
235
|
+
const handler = (event) => { /* ... */ };
|
|
236
|
+
swapper.on(WidgetEventName.TRANSACTION_SUCCESS, handler);
|
|
237
|
+
swapper.off(WidgetEventName.TRANSACTION_SUCCESS, handler);
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Listening with `window.addEventListener`
|
|
241
|
+
|
|
242
|
+
You can also listen for events directly on the window. Each event is a `MessageEvent` containing a `SwapperWidgetEvent` envelope:
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
import { WIDGET_EVENT_PROTOCOL_VERSION, WidgetEventName } from '@swapper-finance/deposit-sdk';
|
|
246
|
+
import type { SwapperWidgetEvent, TransactionSuccessPayload } from '@swapper-finance/deposit-sdk';
|
|
247
|
+
|
|
248
|
+
window.addEventListener('message', (event: MessageEvent) => {
|
|
249
|
+
if (event.data?.type !== 'SWAPPER_EVENT') return;
|
|
250
|
+
|
|
251
|
+
const message = event.data as SwapperWidgetEvent;
|
|
252
|
+
|
|
253
|
+
if (message.version !== WIDGET_EVENT_PROTOCOL_VERSION) return;
|
|
254
|
+
|
|
255
|
+
if (message.name === WidgetEventName.TRANSACTION_SUCCESS) {
|
|
256
|
+
const payload = message.payload as TransactionSuccessPayload;
|
|
257
|
+
console.log('Tx hash:', payload.txHash);
|
|
258
|
+
console.log('Explorer:', payload.explorerUrl);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### `TransactionSuccessPayload`
|
|
264
|
+
|
|
265
|
+
| Field | Type | Required | Description |
|
|
266
|
+
|------------------|-------------------|----------|---------------------------------------|
|
|
267
|
+
| `depositOption` | `DepositFlowType` | Yes | `"walletDeposit"`, `"transferCrypto"`, or `"depositWithCash"` |
|
|
268
|
+
| `txHash` | `string` | No | Transaction hash |
|
|
269
|
+
| `explorerUrl` | `string` | No | Link to block explorer |
|
|
270
|
+
| `tokenSymbol` | `string` | No | Token symbol (e.g. `"USDC"`) |
|
|
271
|
+
| `tokenAddress` | `string` | No | Token contract address |
|
|
272
|
+
| `chainId` | `string` | No | Chain ID of the transaction |
|
|
273
|
+
| `amountReceived` | `string` | No | Amount received |
|
|
274
|
+
|
|
190
275
|
## Modal API Reference
|
|
191
276
|
|
|
192
277
|
### Opening a Modal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwapperIframe.d.ts","sourceRoot":"","sources":["../src/SwapperIframe.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa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,aAAa;IAS1B,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAgCxC,OAAO,IAAI,IAAI;CAmBvB"}
|
package/dist/SwapperIframe.js
CHANGED
|
@@ -1 +1,256 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { WIDGET_EVENT_PROTOCOL_VERSION, } from "./types";
|
|
2
|
+
import { SwapperWalletProvider } from "./SwapperWalletProvider";
|
|
3
|
+
import { createSwapperSigner } from "./adapters";
|
|
4
|
+
const DEFAULT_IFRAME_URL = "https://deposit.swapper.finance/";
|
|
5
|
+
export class SwapperIframe {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.eventHandlers = new Map();
|
|
8
|
+
this.validateConfig(options);
|
|
9
|
+
this.config = {
|
|
10
|
+
integratorId: options.integratorId,
|
|
11
|
+
dstChainId: options.dstChainId,
|
|
12
|
+
dstTokenAddr: options.dstTokenAddr,
|
|
13
|
+
depositWalletAddress: options.depositWalletAddress,
|
|
14
|
+
styles: options.styles,
|
|
15
|
+
customContractCalls: options.customContractCalls,
|
|
16
|
+
supportedDepositOptions: options.supportedDepositOptions,
|
|
17
|
+
webhookUrl: options.webhookUrl,
|
|
18
|
+
};
|
|
19
|
+
this.iframeUrl = options.iframeUrl || DEFAULT_IFRAME_URL;
|
|
20
|
+
this.iframe = this.createIframe(options);
|
|
21
|
+
this.setupMessageListener();
|
|
22
|
+
if (options.container) {
|
|
23
|
+
this.mount(options.container);
|
|
24
|
+
}
|
|
25
|
+
if (!!options.wallet) {
|
|
26
|
+
const iframeOrigin = new URL(this.iframeUrl).origin;
|
|
27
|
+
if ("signer" in options.wallet) {
|
|
28
|
+
const signer = createSwapperSigner(options.wallet.signer);
|
|
29
|
+
const onTransactionRequest = (tx) => signer.sendTransaction(tx);
|
|
30
|
+
const onChainSwitchRequest = (chainId) => signer.switchChain(chainId);
|
|
31
|
+
Promise.all([signer.getAddress(), signer.getChainId()])
|
|
32
|
+
.then(([address, chainId]) => {
|
|
33
|
+
this.walletProvider = new SwapperWalletProvider({
|
|
34
|
+
iframe: this.iframe,
|
|
35
|
+
iframeOrigin,
|
|
36
|
+
onTransactionRequest,
|
|
37
|
+
onChainSwitchRequest,
|
|
38
|
+
autoConnect: { address, chainId },
|
|
39
|
+
});
|
|
40
|
+
})
|
|
41
|
+
.catch((err) => {
|
|
42
|
+
console.error("[SwapperIframe] Failed to initialize wallet provider:", err);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.walletProvider = new SwapperWalletProvider({
|
|
47
|
+
iframe: this.iframe,
|
|
48
|
+
iframeOrigin,
|
|
49
|
+
onTransactionRequest: options.wallet.onTransactionRequest,
|
|
50
|
+
onChainSwitchRequest: options.wallet.onChainSwitchRequest,
|
|
51
|
+
autoConnect: options.wallet.autoConnect,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
validateConfig(config) {
|
|
57
|
+
const required = [
|
|
58
|
+
"integratorId",
|
|
59
|
+
"dstChainId",
|
|
60
|
+
"dstTokenAddr",
|
|
61
|
+
"depositWalletAddress",
|
|
62
|
+
];
|
|
63
|
+
for (const field of required) {
|
|
64
|
+
if (!config[field]) {
|
|
65
|
+
throw new Error(`Missing required parameter: ${field}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
createIframe(options) {
|
|
70
|
+
const iframe = document.createElement("iframe");
|
|
71
|
+
const url = new URL(this.iframeUrl);
|
|
72
|
+
url.searchParams.set("integratorId", this.config.integratorId);
|
|
73
|
+
url.searchParams.set("dstChainId", this.config.dstChainId);
|
|
74
|
+
url.searchParams.set("dstTokenAddr", this.config.dstTokenAddr);
|
|
75
|
+
url.searchParams.set("depositWalletAddress", this.config.depositWalletAddress);
|
|
76
|
+
if (this.config.styles) {
|
|
77
|
+
url.searchParams.set("styles", JSON.stringify(this.config.styles));
|
|
78
|
+
}
|
|
79
|
+
if (this.config.customContractCalls) {
|
|
80
|
+
url.searchParams.set("customContractCalls", JSON.stringify(this.config.customContractCalls));
|
|
81
|
+
}
|
|
82
|
+
if (this.config.supportedDepositOptions) {
|
|
83
|
+
url.searchParams.set("supportedDepositOptions", JSON.stringify(this.config.supportedDepositOptions));
|
|
84
|
+
}
|
|
85
|
+
if (this.config.webhookUrl) {
|
|
86
|
+
url.searchParams.set("webhookUrl", this.config.webhookUrl);
|
|
87
|
+
}
|
|
88
|
+
url.searchParams.set("t", Date.now().toString());
|
|
89
|
+
iframe.src = url.toString();
|
|
90
|
+
iframe.style.border = "none";
|
|
91
|
+
iframe.style.width = options.iframeAttributes?.width || "100%";
|
|
92
|
+
iframe.style.height = options.iframeAttributes?.height || "560px";
|
|
93
|
+
iframe.title = options.iframeAttributes?.title || "Swapper Deposit Widget";
|
|
94
|
+
const iframeOrigin = new URL(this.iframeUrl).origin;
|
|
95
|
+
const defaultAllow = `camera; clipboard-write self ${iframeOrigin}`;
|
|
96
|
+
const additionalAllow = options.iframeAttributes?.allow || "";
|
|
97
|
+
const allowPermissions = additionalAllow
|
|
98
|
+
? `${defaultAllow} ${additionalAllow}`
|
|
99
|
+
: defaultAllow;
|
|
100
|
+
iframe.setAttribute("allow", allowPermissions);
|
|
101
|
+
const defaultSandbox = "allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts";
|
|
102
|
+
const additionalSandbox = options.iframeAttributes?.sandbox || "";
|
|
103
|
+
const sandboxPermissions = additionalSandbox
|
|
104
|
+
? `${defaultSandbox} ${additionalSandbox}`
|
|
105
|
+
: defaultSandbox;
|
|
106
|
+
iframe.setAttribute("sandbox", sandboxPermissions);
|
|
107
|
+
if (options.iframeAttributes) {
|
|
108
|
+
Object.entries(options.iframeAttributes).forEach(([key, value]) => {
|
|
109
|
+
if (value &&
|
|
110
|
+
key !== "width" &&
|
|
111
|
+
key !== "height" &&
|
|
112
|
+
key !== "title" &&
|
|
113
|
+
key !== "allow" &&
|
|
114
|
+
key !== "sandbox") {
|
|
115
|
+
iframe.setAttribute(key, value);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return iframe;
|
|
120
|
+
}
|
|
121
|
+
setupMessageListener() {
|
|
122
|
+
this.messageListener = (event) => {
|
|
123
|
+
const iframeOrigin = new URL(this.iframeUrl).origin;
|
|
124
|
+
if (event.origin !== iframeOrigin) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (event.data &&
|
|
128
|
+
typeof event.data === "object" &&
|
|
129
|
+
event.data.type === "SWAPPER_EVENT") {
|
|
130
|
+
const envelope = event.data;
|
|
131
|
+
if (envelope.version !== WIDGET_EVENT_PROTOCOL_VERSION) {
|
|
132
|
+
console.warn(`[SwapperIframe] Received widget event with unsupported protocol version ${envelope.version} (expected ${WIDGET_EVENT_PROTOCOL_VERSION})`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const swapperEvent = {
|
|
136
|
+
type: envelope.name,
|
|
137
|
+
data: envelope.payload,
|
|
138
|
+
};
|
|
139
|
+
const handlers = this.eventHandlers.get(swapperEvent.type);
|
|
140
|
+
if (handlers) {
|
|
141
|
+
handlers.forEach((handler) => handler(swapperEvent));
|
|
142
|
+
}
|
|
143
|
+
const wildcardHandlers = this.eventHandlers.get("*");
|
|
144
|
+
if (wildcardHandlers) {
|
|
145
|
+
wildcardHandlers.forEach((handler) => handler(swapperEvent));
|
|
146
|
+
}
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (event.data && typeof event.data === "object") {
|
|
150
|
+
const swapperEvent = {
|
|
151
|
+
type: event.data.type,
|
|
152
|
+
data: event.data.data,
|
|
153
|
+
};
|
|
154
|
+
const handlers = this.eventHandlers.get(swapperEvent.type);
|
|
155
|
+
if (handlers) {
|
|
156
|
+
handlers.forEach((handler) => handler(swapperEvent));
|
|
157
|
+
}
|
|
158
|
+
const wildcardHandlers = this.eventHandlers.get("*");
|
|
159
|
+
if (wildcardHandlers) {
|
|
160
|
+
wildcardHandlers.forEach((handler) => handler(swapperEvent));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
window.addEventListener("message", this.messageListener);
|
|
165
|
+
}
|
|
166
|
+
mount(container) {
|
|
167
|
+
const containerElement = typeof container === "string"
|
|
168
|
+
? document.querySelector(container)
|
|
169
|
+
: container;
|
|
170
|
+
if (!containerElement) {
|
|
171
|
+
throw new Error(`Container not found: ${typeof container === "string" ? container : "provided element"}`);
|
|
172
|
+
}
|
|
173
|
+
containerElement.appendChild(this.iframe);
|
|
174
|
+
}
|
|
175
|
+
updateConfig(config) {
|
|
176
|
+
this.config = { ...this.config, ...config };
|
|
177
|
+
this.sendMessage({
|
|
178
|
+
type: "SWAPPER_CONFIG",
|
|
179
|
+
config: config,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
updateStyles(styles) {
|
|
183
|
+
this.updateConfig({ styles });
|
|
184
|
+
}
|
|
185
|
+
updateCustomContractCalls(customContractCalls) {
|
|
186
|
+
this.updateConfig({ customContractCalls });
|
|
187
|
+
}
|
|
188
|
+
updateSupportedDepositOptions(supportedDepositOptions) {
|
|
189
|
+
this.updateConfig({ supportedDepositOptions });
|
|
190
|
+
}
|
|
191
|
+
updateWebhookUrl(webhookUrl) {
|
|
192
|
+
this.updateConfig({ webhookUrl });
|
|
193
|
+
}
|
|
194
|
+
sendMessage(message) {
|
|
195
|
+
const iframeOrigin = new URL(this.iframeUrl).origin;
|
|
196
|
+
this.iframe.contentWindow?.postMessage(message, iframeOrigin);
|
|
197
|
+
}
|
|
198
|
+
on(eventType, handler) {
|
|
199
|
+
if (!this.eventHandlers.has(eventType)) {
|
|
200
|
+
this.eventHandlers.set(eventType, new Set());
|
|
201
|
+
}
|
|
202
|
+
this.eventHandlers.get(eventType).add(handler);
|
|
203
|
+
}
|
|
204
|
+
off(eventType, handler) {
|
|
205
|
+
const handlers = this.eventHandlers.get(eventType);
|
|
206
|
+
if (handlers) {
|
|
207
|
+
handlers.delete(handler);
|
|
208
|
+
if (handlers.size === 0) {
|
|
209
|
+
this.eventHandlers.delete(eventType);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
getIframe() {
|
|
214
|
+
return this.iframe;
|
|
215
|
+
}
|
|
216
|
+
getConfig() {
|
|
217
|
+
return { ...this.config };
|
|
218
|
+
}
|
|
219
|
+
updateSigner(rawSigner) {
|
|
220
|
+
const signer = createSwapperSigner(rawSigner);
|
|
221
|
+
if (this.walletProvider) {
|
|
222
|
+
this.walletProvider.destroy();
|
|
223
|
+
this.walletProvider = undefined;
|
|
224
|
+
}
|
|
225
|
+
const iframeOrigin = new URL(this.iframeUrl).origin;
|
|
226
|
+
const onTransactionRequest = (tx) => signer.sendTransaction(tx);
|
|
227
|
+
const onChainSwitchRequest = (chainId) => signer.switchChain(chainId);
|
|
228
|
+
Promise.all([signer.getAddress(), signer.getChainId()])
|
|
229
|
+
.then(([address, chainId]) => {
|
|
230
|
+
this.walletProvider = new SwapperWalletProvider({
|
|
231
|
+
iframe: this.iframe,
|
|
232
|
+
iframeOrigin,
|
|
233
|
+
onTransactionRequest,
|
|
234
|
+
onChainSwitchRequest,
|
|
235
|
+
autoConnect: { address, chainId },
|
|
236
|
+
});
|
|
237
|
+
})
|
|
238
|
+
.catch((err) => {
|
|
239
|
+
console.error("[SwapperIframe] Failed to update wallet provider:", err);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
destroy() {
|
|
243
|
+
if (this.walletProvider) {
|
|
244
|
+
this.walletProvider.destroy();
|
|
245
|
+
this.walletProvider = undefined;
|
|
246
|
+
}
|
|
247
|
+
if (this.messageListener) {
|
|
248
|
+
window.removeEventListener("message", this.messageListener);
|
|
249
|
+
}
|
|
250
|
+
this.eventHandlers.clear();
|
|
251
|
+
if (this.iframe.parentNode) {
|
|
252
|
+
this.iframe.parentNode.removeChild(this.iframe);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=SwapperIframe.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwapperIframe.js","sourceRoot":"","sources":["../src/SwapperIframe.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SwapperIframe.js","sourceRoot":"","sources":["../src/SwapperIframe.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,6BAA6B,GAC9B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAkB,MAAM,YAAY,CAAC;AAKjE,MAAM,kBAAkB,GAAG,kCAAkC,CAAC;AAK9D,MAAM,OAAO,aAAa;IAYxB,YAAY,OAA6B;QARjC,kBAAa,GAA0C,IAAI,GAAG,EAAE,CAAC;QASvE,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAE7B,IAAI,CAAC,MAAM,GAAG;YACZ,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;YAClD,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;YAChD,uBAAuB,EAAE,OAAO,CAAC,uBAAuB;YACxD,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC;QAEF,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,kBAAkB,CAAC;QACzD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAEzC,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAE5B,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACtB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAChC,CAAC;QAED,IAAI,CAAC,CAAC,OAAO,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AI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAC9D,CAAC;QAGD,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAG3B,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF"}
|
package/dist/SwapperModal.js
CHANGED
|
@@ -1 +1,175 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { SwapperIframe } from "./SwapperIframe";
|
|
2
|
+
export class SwapperModal {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
this.iframe = null;
|
|
5
|
+
this.overlay = null;
|
|
6
|
+
this.modalContainer = null;
|
|
7
|
+
this.iframeContainer = null;
|
|
8
|
+
this.isOpen = false;
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
open() {
|
|
12
|
+
if (this.isOpen) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.createModal();
|
|
16
|
+
this.isOpen = true;
|
|
17
|
+
}
|
|
18
|
+
close() {
|
|
19
|
+
if (!this.isOpen) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
this.destroyModal();
|
|
23
|
+
this.isOpen = false;
|
|
24
|
+
if (this.options.onClose) {
|
|
25
|
+
this.options.onClose();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
isModalOpen() {
|
|
29
|
+
return this.isOpen;
|
|
30
|
+
}
|
|
31
|
+
getIframe() {
|
|
32
|
+
return this.iframe;
|
|
33
|
+
}
|
|
34
|
+
createModal() {
|
|
35
|
+
const style = this.options.modalStyle || {};
|
|
36
|
+
const iframeStyles = this.options.styles || {};
|
|
37
|
+
this.overlay = document.createElement("div");
|
|
38
|
+
this.overlay.style.cssText = `
|
|
39
|
+
position: fixed;
|
|
40
|
+
top: 0;
|
|
41
|
+
left: 0;
|
|
42
|
+
width: 100vw;
|
|
43
|
+
height: 100vh;
|
|
44
|
+
background: ${style.overlayColor || "rgba(0, 0, 0, 0.7)"};
|
|
45
|
+
z-index: ${style.zIndex || 10000};
|
|
46
|
+
display: flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
animation: swapper-fade-in 0.2s ease-out;
|
|
50
|
+
`;
|
|
51
|
+
if (!document.getElementById("swapper-modal-styles")) {
|
|
52
|
+
const styleSheet = document.createElement("style");
|
|
53
|
+
styleSheet.id = "swapper-modal-styles";
|
|
54
|
+
styleSheet.textContent = `
|
|
55
|
+
@keyframes swapper-fade-in {
|
|
56
|
+
from { opacity: 0; }
|
|
57
|
+
to { opacity: 1; }
|
|
58
|
+
}
|
|
59
|
+
@keyframes swapper-scale-in {
|
|
60
|
+
from {
|
|
61
|
+
transform: scale(0.95);
|
|
62
|
+
opacity: 0;
|
|
63
|
+
}
|
|
64
|
+
to {
|
|
65
|
+
transform: scale(1);
|
|
66
|
+
opacity: 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
document.head.appendChild(styleSheet);
|
|
71
|
+
}
|
|
72
|
+
this.overlay.addEventListener("click", (e) => {
|
|
73
|
+
if (e.target === this.overlay) {
|
|
74
|
+
this.close();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const escapeHandler = (e) => {
|
|
78
|
+
if (e.key === "Escape") {
|
|
79
|
+
this.close();
|
|
80
|
+
document.removeEventListener("keydown", escapeHandler);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
document.addEventListener("keydown", escapeHandler);
|
|
84
|
+
this.modalContainer = document.createElement("div");
|
|
85
|
+
this.modalContainer.style.cssText = `
|
|
86
|
+
position: relative;
|
|
87
|
+
width: ${style.width || "450px"};
|
|
88
|
+
height: ${style.height || "560px"};
|
|
89
|
+
background: ${iframeStyles.themeMode === "light" ? "#ffffff" : "#111111"};
|
|
90
|
+
border-radius: 30px;
|
|
91
|
+
overflow: hidden;
|
|
92
|
+
animation: swapper-scale-in 0.3s ease-out;
|
|
93
|
+
`;
|
|
94
|
+
if (style.showCloseButton === true) {
|
|
95
|
+
const closeButton = document.createElement("button");
|
|
96
|
+
closeButton.innerHTML = "×";
|
|
97
|
+
closeButton.style.cssText = `
|
|
98
|
+
position: absolute;
|
|
99
|
+
top: 12px;
|
|
100
|
+
right: 12px;
|
|
101
|
+
width: 32px;
|
|
102
|
+
height: 32px;
|
|
103
|
+
border: none;
|
|
104
|
+
background: rgba(0, 0, 0, 0.5);
|
|
105
|
+
color: white;
|
|
106
|
+
font-size: 24px;
|
|
107
|
+
line-height: 1;
|
|
108
|
+
border-radius: 50%;
|
|
109
|
+
cursor: pointer;
|
|
110
|
+
z-index: ${(style.zIndex || 10000) + 1};
|
|
111
|
+
display: flex;
|
|
112
|
+
align-items: center;
|
|
113
|
+
justify-content: center;
|
|
114
|
+
transition: background 0.2s ease;
|
|
115
|
+
`;
|
|
116
|
+
closeButton.onmouseover = () => {
|
|
117
|
+
closeButton.style.background = "rgba(0, 0, 0, 0.7)";
|
|
118
|
+
};
|
|
119
|
+
closeButton.onmouseout = () => {
|
|
120
|
+
closeButton.style.background = "rgba(0, 0, 0, 0.5)";
|
|
121
|
+
};
|
|
122
|
+
closeButton.onclick = () => this.close();
|
|
123
|
+
this.modalContainer.appendChild(closeButton);
|
|
124
|
+
}
|
|
125
|
+
this.iframeContainer = document.createElement("div");
|
|
126
|
+
this.iframeContainer.style.cssText = `
|
|
127
|
+
width: 100%;
|
|
128
|
+
height: 100%;
|
|
129
|
+
`;
|
|
130
|
+
this.modalContainer.appendChild(this.iframeContainer);
|
|
131
|
+
this.overlay.appendChild(this.modalContainer);
|
|
132
|
+
document.body.appendChild(this.overlay);
|
|
133
|
+
document.body.style.overflow = "hidden";
|
|
134
|
+
this.iframe = new SwapperIframe({
|
|
135
|
+
container: this.iframeContainer,
|
|
136
|
+
integratorId: this.options.integratorId,
|
|
137
|
+
dstChainId: this.options.dstChainId,
|
|
138
|
+
dstTokenAddr: this.options.dstTokenAddr,
|
|
139
|
+
depositWalletAddress: this.options.depositWalletAddress,
|
|
140
|
+
styles: this.options.styles,
|
|
141
|
+
customContractCalls: this.options.customContractCalls,
|
|
142
|
+
supportedDepositOptions: this.options.supportedDepositOptions,
|
|
143
|
+
webhookUrl: this.options.webhookUrl,
|
|
144
|
+
wallet: this.options.wallet,
|
|
145
|
+
iframeUrl: this.options.iframeUrl,
|
|
146
|
+
iframeAttributes: {
|
|
147
|
+
...this.options.iframeAttributes,
|
|
148
|
+
width: "100%",
|
|
149
|
+
height: "100%",
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
destroyModal() {
|
|
154
|
+
if (this.iframe) {
|
|
155
|
+
this.iframe.destroy();
|
|
156
|
+
this.iframe = null;
|
|
157
|
+
}
|
|
158
|
+
if (this.overlay && this.overlay.parentNode) {
|
|
159
|
+
this.overlay.parentNode.removeChild(this.overlay);
|
|
160
|
+
}
|
|
161
|
+
document.body.style.overflow = "";
|
|
162
|
+
this.overlay = null;
|
|
163
|
+
this.modalContainer = null;
|
|
164
|
+
this.iframeContainer = null;
|
|
165
|
+
}
|
|
166
|
+
destroy() {
|
|
167
|
+
this.close();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export function openSwapperModal(options) {
|
|
171
|
+
const modal = new SwapperModal(options);
|
|
172
|
+
modal.open();
|
|
173
|
+
return modal;
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=SwapperModal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwapperWalletProvider.d.ts","sourceRoot":"","sources":["../src/SwapperWalletProvider.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"SwapperWalletProvider.d.ts","sourceRoot":"","sources":["../src/SwapperWalletProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAM7B,MAAM,SAAS,CAAC;AAajB,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,oBAAoB,CAA4B;IACxD,OAAO,CAAC,oBAAoB,CAA4B;IACxD,OAAO,CAAC,iBAAiB,CAAC,CAAuC;IACjE,OAAO,CAAC,eAAe,CAAgC;IAEvD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,OAAO,CAAqB;gBAExB,OAAO,EAAE,4BAA4B;IAWjD,OAAO,CAAC,aAAa;YA0BP,eAAe;YAiBf,wBAAwB;IAuBtC,OAAO,CAAC,WAAW;IAMZ,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAWrD,gBAAgB,IAAI,IAAI;IASxB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAQzC,cAAc,CACnB,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,GACvD,IAAI;IAOA,UAAU,IAAI,OAAO;IAIrB,cAAc,IAAI,OAAO;IAIzB,UAAU,IAAI,MAAM,GAAG,SAAS;IAIhC,UAAU,IAAI,MAAM,GAAG,SAAS;IAIhC,OAAO,IAAI,IAAI;CAQvB"}
|