@zapodotcash/widget 0.0.0-stage → 0.1.0
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 +21 -0
- package/README.md +76 -2
- package/dist/chunk-sqektmvr.js +119 -0
- package/dist/core.d.ts +15 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +12 -0
- package/dist/origin.d.ts +6 -0
- package/dist/react.d.ts +14 -0
- package/dist/react.js +43 -0
- package/dist/types.d.ts +127 -0
- package/package.json +57 -4
- package/react.d.ts +2 -0
- package/react.js +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zapo Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,77 @@
|
|
|
1
|
-
#
|
|
1
|
+
# zapo
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Zapo deposit widget for web apps. Your users pay with the tokens they already hold, on the chain they are
|
|
4
|
+
already on; the token you want arrives in the wallet you name.
|
|
5
|
+
|
|
6
|
+
This package is the loader: it puts the widget's frame in your page, hands it your configuration and passes its
|
|
7
|
+
events back to you. The widget itself is served by Zapo, so your page never holds a secret.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @zapodotcash/widget
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
You need a project key (it starts with `zpk_`) from the [Zapo dashboard](https://zapo.cash/app).
|
|
16
|
+
|
|
17
|
+
## Use
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { mount } from '@zapodotcash/widget'
|
|
21
|
+
|
|
22
|
+
const zapo = mount('#deposit', {
|
|
23
|
+
apiKey: 'zpk_live_your_key',
|
|
24
|
+
destinations: [{ chainId: 8453, tokens: ['USDC'], recipient: usersWallet }],
|
|
25
|
+
}, {
|
|
26
|
+
onStatus: (deposit) => console.log(deposit.phase),
|
|
27
|
+
onClose: () => hideMyDialog(),
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
zapo.update(nextConfig) // for example when the user connects another wallet
|
|
31
|
+
zapo.destroy()
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### React
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { ZapoDeposit } from '@zapodotcash/widget/react'
|
|
38
|
+
|
|
39
|
+
<ZapoDeposit
|
|
40
|
+
apiKey="zpk_live_your_key"
|
|
41
|
+
destinations={[{ chainId: 8453, tokens: ['USDC'], recipient: wallet }]}
|
|
42
|
+
onStatus={(deposit) => console.log(deposit.phase)}
|
|
43
|
+
/>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
| Field | What it does |
|
|
49
|
+
| -------------- | ------------------------------------------------------------------------------------------------ |
|
|
50
|
+
| `apiKey` | Required. Your project's publishable key. |
|
|
51
|
+
| `destinations` | Required. What the user may fund: a chain id, the tokens you accept there, the wallet that receives. |
|
|
52
|
+
| `from.chains` | Chains the user may send from. Left out: every supported chain. |
|
|
53
|
+
| `refundTo` | The user's own wallet per chain family (`evm`, `svm`), for refunds. |
|
|
54
|
+
| `methods` | `['address', 'wallet']` by default. Either can be left out. |
|
|
55
|
+
| `defaults` | `fromChainId`, `toChainId`, `toToken`: choices to make for the user. |
|
|
56
|
+
| `theme` | `light`, `dark` or `auto` (the default). |
|
|
57
|
+
| `appearance` | Your look: an `accent`, `light`/`dark` colours, `radius`, `font`, `shadow`. Left out: the widget's own. |
|
|
58
|
+
| `appName` | Shown as "Deposit to ...". Left out: your project's name. |
|
|
59
|
+
| `logoUrl` | An https image shown at the top left. Left out: your project's logo, else your account's. |
|
|
60
|
+
|
|
61
|
+
## Events
|
|
62
|
+
|
|
63
|
+
| Handler | When |
|
|
64
|
+
| ---------- | --------------------------------------------------------------------------------------------------- |
|
|
65
|
+
| `onReady` | The widget has loaded. |
|
|
66
|
+
| `onStatus` | A deposit changed phase: `detected`, `confirming`, `routing`, `delivering`, `delivered`, `delayed`, `refunded`, `failed`. |
|
|
67
|
+
| `onClose` | The user pressed Done or Close. |
|
|
68
|
+
|
|
69
|
+
Events are for your interface. To credit a user, watch the chain: the delivery is an ordinary transfer to the wallet
|
|
70
|
+
you named.
|
|
71
|
+
|
|
72
|
+
Everything is typed; the full reference is in the [Zapo docs](https://zapo.cash/docs). To put your look together,
|
|
73
|
+
use the [Theme builder](https://zapo.cash/docs/theme).
|
|
74
|
+
|
|
75
|
+
## Licence
|
|
76
|
+
|
|
77
|
+
MIT
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// src/core.ts
|
|
2
|
+
var MAX_WIDTH = 496;
|
|
3
|
+
var INITIAL_HEIGHT = 512;
|
|
4
|
+
var MIN_HEIGHT = 240;
|
|
5
|
+
var MAX_HEIGHT = 2400;
|
|
6
|
+
function encodeConfig(config) {
|
|
7
|
+
const bytes = new TextEncoder().encode(JSON.stringify(config));
|
|
8
|
+
let binary = "";
|
|
9
|
+
for (const byte of bytes)
|
|
10
|
+
binary += String.fromCharCode(byte);
|
|
11
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
12
|
+
}
|
|
13
|
+
function withoutKey(config) {
|
|
14
|
+
const { apiKey: _apiKey, ...rest } = config;
|
|
15
|
+
return JSON.parse(JSON.stringify(rest));
|
|
16
|
+
}
|
|
17
|
+
function frameUrl(origin, config) {
|
|
18
|
+
const key = typeof config.apiKey === "string" ? config.apiKey.trim() : "";
|
|
19
|
+
const query = key === "" ? "" : `?key=${encodeURIComponent(key)}`;
|
|
20
|
+
return `${origin.replace(/\/+$/, "")}/embed${query}#config=${encodeConfig(withoutKey(config))}`;
|
|
21
|
+
}
|
|
22
|
+
function clampHeight(height) {
|
|
23
|
+
return Math.max(MIN_HEIGHT, Math.min(Math.ceil(height), MAX_HEIGHT));
|
|
24
|
+
}
|
|
25
|
+
function isFrameMessage(data) {
|
|
26
|
+
if (typeof data !== "object" || data === null)
|
|
27
|
+
return false;
|
|
28
|
+
const message = data;
|
|
29
|
+
return message.source === "zapo" && typeof message.type === "string";
|
|
30
|
+
}
|
|
31
|
+
function toStatusEvent(data) {
|
|
32
|
+
if (typeof data !== "object" || data === null)
|
|
33
|
+
return null;
|
|
34
|
+
const message = data;
|
|
35
|
+
if (typeof message["id"] !== "string" || typeof message["phase"] !== "string")
|
|
36
|
+
return null;
|
|
37
|
+
const chain = (value) => typeof value === "number" ? value : null;
|
|
38
|
+
const text = (value) => typeof value === "string" ? value : null;
|
|
39
|
+
return {
|
|
40
|
+
id: message["id"],
|
|
41
|
+
phase: message["phase"],
|
|
42
|
+
originChainId: chain(message["originChainId"]),
|
|
43
|
+
destinationChainId: chain(message["destinationChainId"]),
|
|
44
|
+
amountOut: text(message["amountOut"]),
|
|
45
|
+
symbolOut: text(message["symbolOut"]),
|
|
46
|
+
txHashes: Array.isArray(message["txHashes"]) ? message["txHashes"].filter((hash) => typeof hash === "string") : []
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function mountWidget(target, config, options, origin) {
|
|
50
|
+
const element = typeof target === "string" ? document.querySelector(target) : target;
|
|
51
|
+
if (element === null)
|
|
52
|
+
throw new Error("Zapo.mount: the target element was not found.");
|
|
53
|
+
const base = origin.replace(/\/+$/, "");
|
|
54
|
+
let latest = config;
|
|
55
|
+
let loaded = config;
|
|
56
|
+
let isAwaitingReady = true;
|
|
57
|
+
const makeFrame = (next) => {
|
|
58
|
+
const made = document.createElement("iframe");
|
|
59
|
+
made.src = frameUrl(base, next);
|
|
60
|
+
made.title = "Deposit";
|
|
61
|
+
made.allow = "clipboard-write";
|
|
62
|
+
made.style.cssText = `display:block;width:100%;max-width:${String(MAX_WIDTH)}px;height:${String(INITIAL_HEIGHT)}px;margin:0 auto;border:0;background:transparent;color-scheme:normal`;
|
|
63
|
+
return made;
|
|
64
|
+
};
|
|
65
|
+
let frame = makeFrame(config);
|
|
66
|
+
const post = (next) => {
|
|
67
|
+
frame.contentWindow?.postMessage({ type: "zapo:config", config: withoutKey(next) }, base);
|
|
68
|
+
};
|
|
69
|
+
const onMessage = (event) => {
|
|
70
|
+
if (event.source !== frame.contentWindow || event.origin !== base)
|
|
71
|
+
return;
|
|
72
|
+
const data = event.data;
|
|
73
|
+
if (!isFrameMessage(data))
|
|
74
|
+
return;
|
|
75
|
+
if (data.type === "resize" && typeof data.height === "number")
|
|
76
|
+
frame.style.height = `${String(clampHeight(data.height))}px`;
|
|
77
|
+
else if (data.type === "ready") {
|
|
78
|
+
isAwaitingReady = false;
|
|
79
|
+
if (latest !== loaded)
|
|
80
|
+
post(latest);
|
|
81
|
+
options.onReady?.();
|
|
82
|
+
} else if (data.type === "close")
|
|
83
|
+
options.onClose?.();
|
|
84
|
+
else if (data.type === "status") {
|
|
85
|
+
const status = toStatusEvent(data);
|
|
86
|
+
if (status !== null)
|
|
87
|
+
options.onStatus?.(status);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
window.addEventListener("message", onMessage);
|
|
91
|
+
element.appendChild(frame);
|
|
92
|
+
return {
|
|
93
|
+
get frame() {
|
|
94
|
+
return frame;
|
|
95
|
+
},
|
|
96
|
+
update: (next) => {
|
|
97
|
+
const isOtherKey = next.apiKey !== loaded.apiKey;
|
|
98
|
+
latest = next;
|
|
99
|
+
if (isOtherKey) {
|
|
100
|
+
loaded = next;
|
|
101
|
+
isAwaitingReady = true;
|
|
102
|
+
const replacement = makeFrame(next);
|
|
103
|
+
replacement.style.cssText = frame.style.cssText;
|
|
104
|
+
frame.replaceWith(replacement);
|
|
105
|
+
frame = replacement;
|
|
106
|
+
} else if (!isAwaitingReady)
|
|
107
|
+
post(next);
|
|
108
|
+
},
|
|
109
|
+
destroy: () => {
|
|
110
|
+
window.removeEventListener("message", onMessage);
|
|
111
|
+
frame.remove();
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/origin.ts
|
|
117
|
+
var DEFAULT_ORIGIN = "https://zapo.cash";
|
|
118
|
+
|
|
119
|
+
export { mountWidget, DEFAULT_ORIGIN };
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ZapoConfig, ZapoHandle, ZapoOptions, ZapoStatusEvent } from './types.js';
|
|
2
|
+
/** base64url of the UTF-8 JSON, carried in the frame URL's fragment - a fragment is never sent to any server. */
|
|
3
|
+
export declare function encodeConfig(config: object): string;
|
|
4
|
+
/**
|
|
5
|
+
* The configuration as the widget receives it: everything except the key, which travels in the frame's address.
|
|
6
|
+
* It goes through JSON, so what `update` sends is exactly what `mount` sent - a field set to `undefined` is left
|
|
7
|
+
* out rather than arriving as a key with no value, which the widget would refuse.
|
|
8
|
+
*/
|
|
9
|
+
export declare function withoutKey(config: ZapoConfig): Omit<ZapoConfig, 'apiKey'>;
|
|
10
|
+
export declare function frameUrl(origin: string, config: ZapoConfig): string;
|
|
11
|
+
/** The frame's height for a card of `height` pixels, kept within sane bounds whatever the frame reports. */
|
|
12
|
+
export declare function clampHeight(height: number): number;
|
|
13
|
+
/** A status message from the frame as the event handed to the page - fields read one by one, nothing passed through. */
|
|
14
|
+
export declare function toStatusEvent(data: unknown): ZapoStatusEvent | null;
|
|
15
|
+
export declare function mountWidget(target: string | Element, config: ZapoConfig, options: ZapoOptions, origin: string): ZapoHandle;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ZapoConfig, ZapoHandle, ZapoOptions } from './types.js';
|
|
2
|
+
export type { ZapoAppearance, ZapoColors, ZapoConfig, ZapoDestination, ZapoFont, ZapoHandle, ZapoHandlers, ZapoMethod, ZapoOptions, ZapoPhase, ZapoRadius, ZapoStatusEvent, ZapoTheme, } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Put the Zapo deposit widget in the page.
|
|
5
|
+
*
|
|
6
|
+
* @param target An element, or a selector for one. The widget is appended to it.
|
|
7
|
+
* @param config Your key, and what your user may fund.
|
|
8
|
+
* @param options Handlers for the widget's events.
|
|
9
|
+
*/
|
|
10
|
+
export declare function mount(target: string | Element, config: ZapoConfig, options?: ZapoOptions): ZapoHandle;
|
package/dist/index.js
ADDED
package/dist/origin.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where Zapo's widget is served from. The placeholder below is replaced before the package is published - the
|
|
3
|
+
* release build refuses to run while it is still here - so a published package always carries the real address.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_ORIGIN: string;
|
|
6
|
+
export declare const PLACEHOLDER_ORIGIN: string;
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ZapoConfig, ZapoHandlers } from './types.js';
|
|
2
|
+
import type { CSSProperties, ReactElement } from 'react';
|
|
3
|
+
export type { ZapoAppearance, ZapoColors, ZapoConfig, ZapoDestination, ZapoFont, ZapoHandlers, ZapoMethod, ZapoPhase, ZapoRadius, ZapoStatusEvent, ZapoTheme, } from './types.js';
|
|
4
|
+
export interface ZapoDepositProps extends ZapoConfig, ZapoHandlers {
|
|
5
|
+
/** Where the widget is served from. Only needed to point at a deployment other than Zapo's own. */
|
|
6
|
+
origin?: string | undefined;
|
|
7
|
+
className?: string | undefined;
|
|
8
|
+
style?: CSSProperties | undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The Zapo deposit widget as a React component. Pass your key and the destinations; the widget fills the width of
|
|
12
|
+
* its container up to 496px and sizes its own height.
|
|
13
|
+
*/
|
|
14
|
+
export declare function ZapoDeposit(props: ZapoDepositProps): ReactElement;
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_ORIGIN,
|
|
3
|
+
mountWidget
|
|
4
|
+
} from "./chunk-sqektmvr.js";
|
|
5
|
+
|
|
6
|
+
// src/react.ts
|
|
7
|
+
import { createElement, useEffect, useRef, useState } from "react";
|
|
8
|
+
function ZapoDeposit(props) {
|
|
9
|
+
const { origin, className, style, onReady, onStatus, onClose, ...config } = props;
|
|
10
|
+
const [element, setElement] = useState(null);
|
|
11
|
+
const handle = useRef(null);
|
|
12
|
+
const handlers = useRef({});
|
|
13
|
+
const serialised = JSON.stringify(config);
|
|
14
|
+
const latest = useRef(serialised);
|
|
15
|
+
const base = origin ?? DEFAULT_ORIGIN;
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
handlers.current = { onReady, onStatus, onClose };
|
|
18
|
+
});
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (element === null)
|
|
21
|
+
return;
|
|
22
|
+
const mounted = mountWidget(element, JSON.parse(latest.current), {
|
|
23
|
+
onReady: () => handlers.current.onReady?.(),
|
|
24
|
+
onStatus: (event) => handlers.current.onStatus?.(event),
|
|
25
|
+
onClose: () => handlers.current.onClose?.()
|
|
26
|
+
}, base);
|
|
27
|
+
handle.current = mounted;
|
|
28
|
+
return () => {
|
|
29
|
+
mounted.destroy();
|
|
30
|
+
handle.current = null;
|
|
31
|
+
};
|
|
32
|
+
}, [element, base, config.apiKey]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (latest.current === serialised)
|
|
35
|
+
return;
|
|
36
|
+
latest.current = serialised;
|
|
37
|
+
handle.current?.update(JSON.parse(serialised));
|
|
38
|
+
}, [serialised]);
|
|
39
|
+
return createElement("div", { ref: setElement, className, style });
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
ZapoDeposit
|
|
43
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/** How a user can pay: to a deposit address (any wallet or exchange), or from a wallet connected in the browser. */
|
|
2
|
+
export type ZapoMethod = 'address' | 'wallet';
|
|
3
|
+
export type ZapoTheme = 'light' | 'dark' | 'auto';
|
|
4
|
+
/** How round the corners are. `medium` is the widget's own. */
|
|
5
|
+
export type ZapoRadius = 'none' | 'small' | 'medium' | 'large';
|
|
6
|
+
/** `inter` (the default), or `system`: the font of the user's own device. */
|
|
7
|
+
export type ZapoFont = 'inter' | 'system';
|
|
8
|
+
/**
|
|
9
|
+
* Colours for one theme, as hex (`#f97316`). Every one is optional: whatever is left out keeps the widget's own.
|
|
10
|
+
* A colour that would make text hard to read on the card is ignored, with a warning in the browser console.
|
|
11
|
+
*/
|
|
12
|
+
export interface ZapoColors {
|
|
13
|
+
/** Buttons, the selected step, focus rings and highlights. */
|
|
14
|
+
accent?: string | undefined;
|
|
15
|
+
/** Text on the accent. Left out: black or white, whichever reads better on your accent. */
|
|
16
|
+
accentText?: string | undefined;
|
|
17
|
+
/** The card itself. */
|
|
18
|
+
background?: string | undefined;
|
|
19
|
+
/** Fields, menus and tiles inside the card. */
|
|
20
|
+
surface?: string | undefined;
|
|
21
|
+
/** Headings, amounts and addresses. */
|
|
22
|
+
text?: string | undefined;
|
|
23
|
+
/** Labels and secondary text. */
|
|
24
|
+
textMuted?: string | undefined;
|
|
25
|
+
/** Lines and outlines. */
|
|
26
|
+
border?: string | undefined;
|
|
27
|
+
}
|
|
28
|
+
/** Your look on the widget. Success, warning and error colours stay the widget's own: they carry meaning. */
|
|
29
|
+
export interface ZapoAppearance {
|
|
30
|
+
/** One accent for both themes. A theme's own `accent` wins over it. */
|
|
31
|
+
accent?: string | undefined;
|
|
32
|
+
/** Colours in the light theme. */
|
|
33
|
+
light?: ZapoColors | undefined;
|
|
34
|
+
/** Colours in the dark theme. */
|
|
35
|
+
dark?: ZapoColors | undefined;
|
|
36
|
+
radius?: ZapoRadius | undefined;
|
|
37
|
+
font?: ZapoFont | undefined;
|
|
38
|
+
/** `false` takes off the card's drop shadow, and the room the frame keeps around the card for it. On by default. */
|
|
39
|
+
shadow?: boolean | undefined;
|
|
40
|
+
}
|
|
41
|
+
/** One thing a user may fund: a chain, the tokens you accept there, and the wallet that receives. */
|
|
42
|
+
export interface ZapoDestination {
|
|
43
|
+
/** The chain to deliver on, by chain id (for example 8453 for Base, 792703809 for Solana). */
|
|
44
|
+
chainId: number;
|
|
45
|
+
/** Tokens you accept on that chain: symbols such as "USDC", or token addresses. */
|
|
46
|
+
tokens: string[];
|
|
47
|
+
/** The wallet that receives on that chain - your user's wallet. Funds are only ever sent to an address you name here. */
|
|
48
|
+
recipient: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ZapoConfig {
|
|
51
|
+
/** Your project's publishable key, from the Zapo dashboard. It starts with `zpk_`. */
|
|
52
|
+
apiKey: string;
|
|
53
|
+
/** What the user may fund. With one entry it is selected for them; with several they choose. */
|
|
54
|
+
destinations: ZapoDestination[];
|
|
55
|
+
/** Chains the user may send from, by chain id. Left out: every chain Zapo supports. */
|
|
56
|
+
from?: {
|
|
57
|
+
chains?: number[] | undefined;
|
|
58
|
+
} | undefined;
|
|
59
|
+
/** The user's own wallet per chain family, for refunds when a deposit cannot be delivered. */
|
|
60
|
+
refundTo?: {
|
|
61
|
+
evm?: string | undefined;
|
|
62
|
+
svm?: string | undefined;
|
|
63
|
+
} | undefined;
|
|
64
|
+
/** Which ways to pay are offered. Default: both. */
|
|
65
|
+
methods?: ZapoMethod[] | undefined;
|
|
66
|
+
/** Choices to make for the user instead of asking. */
|
|
67
|
+
defaults?: {
|
|
68
|
+
fromChainId?: number | undefined;
|
|
69
|
+
toChainId?: number | undefined;
|
|
70
|
+
toToken?: string | undefined;
|
|
71
|
+
} | undefined;
|
|
72
|
+
/** `auto` (the default) follows the user's system setting. */
|
|
73
|
+
theme?: ZapoTheme | undefined;
|
|
74
|
+
/** Your colours, corners and font. See the Appearance docs. */
|
|
75
|
+
appearance?: ZapoAppearance | undefined;
|
|
76
|
+
/** Your app's name, shown as "Deposit to ...". Left out: your project's name from the dashboard. */
|
|
77
|
+
appName?: string | undefined;
|
|
78
|
+
/** Your logo, shown at the top left: the https address of an image. Left out: your project's logo, if it has one. */
|
|
79
|
+
logoUrl?: string | undefined;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Where a deposit is. `detected` to `delivering` are in flight, in order; `delivered`, `refunded` and `failed` are
|
|
83
|
+
* final; `delayed` means it is taking longer than usual and will still resolve.
|
|
84
|
+
*/
|
|
85
|
+
export type ZapoPhase = 'detected' | 'confirming' | 'routing' | 'delivering' | 'delivered' | 'delayed' | 'refunded' | 'failed';
|
|
86
|
+
/** Sent each time a deposit changes phase. */
|
|
87
|
+
export interface ZapoStatusEvent {
|
|
88
|
+
/** The deposit's id. The same deposit keeps its id across events. */
|
|
89
|
+
id: string;
|
|
90
|
+
phase: ZapoPhase;
|
|
91
|
+
originChainId: number | null;
|
|
92
|
+
destinationChainId: number | null;
|
|
93
|
+
/**
|
|
94
|
+
* The amount in the destination token's units, as a decimal string: what the route expects to deliver while the
|
|
95
|
+
* deposit is in flight, and what was delivered once `phase` is `delivered`. Null until it is known.
|
|
96
|
+
*/
|
|
97
|
+
amountOut: string | null;
|
|
98
|
+
symbolOut: string | null;
|
|
99
|
+
/** Hashes of the delivery transactions on the destination chain - or, for a refund, of the refund on the source chain. */
|
|
100
|
+
txHashes: string[];
|
|
101
|
+
}
|
|
102
|
+
export interface ZapoHandlers {
|
|
103
|
+
/** The widget has loaded and is showing. */
|
|
104
|
+
onReady?: (() => void) | undefined;
|
|
105
|
+
/** A deposit changed phase. */
|
|
106
|
+
onStatus?: ((event: ZapoStatusEvent) => void) | undefined;
|
|
107
|
+
/** The user pressed Done or Close: hide whatever you showed the widget in. */
|
|
108
|
+
onClose?: (() => void) | undefined;
|
|
109
|
+
}
|
|
110
|
+
export interface ZapoOptions extends ZapoHandlers {
|
|
111
|
+
/** Where the widget is served from. Only needed to point at a deployment other than Zapo's own. */
|
|
112
|
+
origin?: string | undefined;
|
|
113
|
+
}
|
|
114
|
+
export interface ZapoHandle {
|
|
115
|
+
/**
|
|
116
|
+
* The frame the widget runs in. An update with a different key puts a new frame in its place, so read this again
|
|
117
|
+
* after one rather than keeping the element.
|
|
118
|
+
*/
|
|
119
|
+
readonly frame: HTMLIFrameElement;
|
|
120
|
+
/**
|
|
121
|
+
* Replace the configuration - for example when the user connects a different wallet. Passing a different key
|
|
122
|
+
* reloads the widget for that key's project.
|
|
123
|
+
*/
|
|
124
|
+
update: (config: ZapoConfig) => void;
|
|
125
|
+
/** Remove the widget and stop listening to it. */
|
|
126
|
+
destroy: () => void;
|
|
127
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zapodotcash/widget",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Zapo deposit widget: your users pay with the tokens they have, on the chain they are on, and the token you want arrives in the wallet you name.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"crypto",
|
|
7
|
+
"deposit",
|
|
8
|
+
"widget",
|
|
9
|
+
"onramp",
|
|
10
|
+
"bridge",
|
|
11
|
+
"cross-chain",
|
|
12
|
+
"web3",
|
|
13
|
+
"ethereum",
|
|
14
|
+
"solana",
|
|
15
|
+
"usdc",
|
|
16
|
+
"react"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Zapo Labs",
|
|
20
|
+
"homepage": "https://zapo.cash/docs",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"module": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./react": {
|
|
32
|
+
"types": "./dist/react.d.ts",
|
|
33
|
+
"default": "./dist/react.js"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"react.js",
|
|
40
|
+
"react.d.ts",
|
|
41
|
+
"README.md",
|
|
42
|
+
"LICENSE"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "bun scripts/build.ts",
|
|
46
|
+
"prepublishOnly": "bun scripts/build.ts --release"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": ">=17"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"react": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/react.d.ts
ADDED
package/react.js
ADDED