@notabene/javascript-sdk 2.0.0-next.15 → 2.0.0-next.17
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 +32 -27
- package/dist/notabene.cjs +1 -1
- package/dist/notabene.d.ts +37 -43
- package/dist/notabene.js +36 -23
- package/dist/tsdoc-metadata.json +1 -1
- package/package.json +21 -20
- package/src/components/EmbeddedComponent.ts +20 -22
- package/src/components/__tests__/EmbeddedComponent.test.ts +12 -32
- package/src/locales.ts +47 -0
- package/src/notabene.ts +25 -20
- package/src/types.ts +23 -28
- package/src/utils/MessageEventManager.ts +8 -8
- package/src/utils/__tests__/MessageEventManager.test.ts +3 -3
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"author": "Notabene <developers@notabene.id>",
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "2.0.0-next.
|
|
12
|
+
"version": "2.0.0-next.17",
|
|
13
13
|
"source": "src/notabene.ts",
|
|
14
14
|
"main": "dist/notabene.js",
|
|
15
15
|
"types": "dist/notabene.d.ts",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"build:clean": "rimraf dist/ ts-out",
|
|
31
31
|
"build": "yarn lint && vite build && tsc && api-extractor run && yarn docs ",
|
|
32
32
|
"lint": "eslint .",
|
|
33
|
+
"format": "prettier --write .",
|
|
33
34
|
"test": "vitest",
|
|
34
35
|
"release": "semantic-release",
|
|
35
36
|
"publish": "yarn build && npm publish --tag next"
|
|
@@ -37,32 +38,32 @@
|
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@commitlint/cli": "^19.5.0",
|
|
39
40
|
"@commitlint/config-conventional": "^19.5.0",
|
|
40
|
-
"@eslint/js": "^9.
|
|
41
|
+
"@eslint/js": "^9.13.0",
|
|
41
42
|
"@fast-check/vitest": "^0.1.3",
|
|
42
|
-
"@microsoft/api-extractor": "^7.47.
|
|
43
|
+
"@microsoft/api-extractor": "^7.47.11",
|
|
43
44
|
"@semantic-release/git": "^10.0.1",
|
|
44
|
-
"@semantic-release/gitlab": "^
|
|
45
|
-
"@semantic-release/npm": "^
|
|
46
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
47
|
-
"@typescript-eslint/parser": "^8.
|
|
48
|
-
"eslint": "^9.
|
|
45
|
+
"@semantic-release/gitlab": "^13.2.1",
|
|
46
|
+
"@semantic-release/npm": "^12.0.1",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.11.0",
|
|
48
|
+
"@typescript-eslint/parser": "^8.11.0",
|
|
49
|
+
"eslint": "^9.13.0",
|
|
49
50
|
"eslint-config-prettier": "^9.1.0",
|
|
50
51
|
"eslint-plugin-prettier": "^5.2.1",
|
|
51
52
|
"fast-check": "^3.22.0",
|
|
52
|
-
"globals": "^15.
|
|
53
|
-
"husky": "^
|
|
54
|
-
"jsdom": "^25.0.
|
|
55
|
-
"lint-staged": "^
|
|
56
|
-
"organize-imports-cli": "^0.
|
|
53
|
+
"globals": "^15.11.0",
|
|
54
|
+
"husky": "^9.1.6",
|
|
55
|
+
"jsdom": "^25.0.1",
|
|
56
|
+
"lint-staged": "^15.2.10",
|
|
57
|
+
"organize-imports-cli": "^0.10.0",
|
|
57
58
|
"prettier": "^3.3.3",
|
|
58
59
|
"rimraf": "^6.0.1",
|
|
59
|
-
"semantic-release": "^24.1.
|
|
60
|
-
"typedoc": "^0.26.
|
|
61
|
-
"typedoc-plugin-markdown": "^4.2.
|
|
62
|
-
"typescript": "^5.6.
|
|
63
|
-
"typescript-eslint": "^8.
|
|
64
|
-
"vite": "^5.4.
|
|
65
|
-
"vitest": "^2.1.
|
|
60
|
+
"semantic-release": "^24.1.3",
|
|
61
|
+
"typedoc": "^0.26.10",
|
|
62
|
+
"typedoc-plugin-markdown": "^4.2.9",
|
|
63
|
+
"typescript": "^5.6.3",
|
|
64
|
+
"typescript-eslint": "^8.11.0",
|
|
65
|
+
"vite": "^5.4.10",
|
|
66
|
+
"vitest": "^2.1.3"
|
|
66
67
|
},
|
|
67
68
|
"lint-staged": {
|
|
68
69
|
"*.ts": [
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CMType,
|
|
3
|
-
ComponentRequest,
|
|
4
3
|
HMType,
|
|
5
4
|
HostMessage,
|
|
5
|
+
TransactionResponse,
|
|
6
6
|
ValidationError,
|
|
7
7
|
} from '../types';
|
|
8
8
|
import {
|
|
@@ -15,13 +15,13 @@ import {
|
|
|
15
15
|
* @public
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
export default class EmbeddedComponent<V
|
|
18
|
+
export default class EmbeddedComponent<V> {
|
|
19
19
|
private _url: string;
|
|
20
|
-
private _value: V
|
|
20
|
+
private _value: Partial<V>;
|
|
21
21
|
private _errors: ValidationError[] = [];
|
|
22
22
|
|
|
23
23
|
private iframe?: HTMLIFrameElement;
|
|
24
|
-
private eventManager: MessageEventManager
|
|
24
|
+
private eventManager: MessageEventManager<V>;
|
|
25
25
|
private modal?: HTMLDialogElement;
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -30,10 +30,10 @@ export default class EmbeddedComponent<V, R> {
|
|
|
30
30
|
* @param value - The initial transaction value
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
|
-
constructor(url: string, value: V) {
|
|
33
|
+
constructor(url: string, value: Partial<V>) {
|
|
34
34
|
this._url = url;
|
|
35
35
|
this._value = value;
|
|
36
|
-
this.eventManager = new MessageEventManager();
|
|
36
|
+
this.eventManager = new MessageEventManager<V>();
|
|
37
37
|
this.on(CMType.INVALID, (message) => {
|
|
38
38
|
if (message.type === CMType.INVALID) {
|
|
39
39
|
this._errors = message.errors;
|
|
@@ -59,7 +59,7 @@ export default class EmbeddedComponent<V, R> {
|
|
|
59
59
|
* @returns The current transaction value
|
|
60
60
|
*/
|
|
61
61
|
|
|
62
|
-
public get value(): V {
|
|
62
|
+
public get value(): Partial<V> {
|
|
63
63
|
return this._value;
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -92,7 +92,7 @@ export default class EmbeddedComponent<V, R> {
|
|
|
92
92
|
*/
|
|
93
93
|
|
|
94
94
|
embed(parent: Element, modal: boolean = false) {
|
|
95
|
-
console.log(this.url);
|
|
95
|
+
// console.log(this.url);
|
|
96
96
|
this.iframe = document.createElement('iframe');
|
|
97
97
|
this.iframe.src = this.url + (!modal ? '&embedded=true' : '');
|
|
98
98
|
this.iframe.allow = 'web-share';
|
|
@@ -108,7 +108,7 @@ export default class EmbeddedComponent<V, R> {
|
|
|
108
108
|
if (event.source !== this.iframe?.contentWindow) {
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
|
-
console.log('received message from iframe', event.data);
|
|
111
|
+
// console.log('received message from iframe', event.data);
|
|
112
112
|
this.eventManager?.setPort(event.ports[0]);
|
|
113
113
|
});
|
|
114
114
|
|
|
@@ -119,7 +119,7 @@ export default class EmbeddedComponent<V, R> {
|
|
|
119
119
|
* Sends a message to the embedded component
|
|
120
120
|
* @param message - The message to send
|
|
121
121
|
*/
|
|
122
|
-
send(message: HostMessage): void {
|
|
122
|
+
send(message: HostMessage<V>): void {
|
|
123
123
|
this.eventManager.send(message);
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -129,7 +129,7 @@ export default class EmbeddedComponent<V, R> {
|
|
|
129
129
|
* @param callback - The callback function to execute when the message is received
|
|
130
130
|
*/
|
|
131
131
|
|
|
132
|
-
on(messageType: string, callback: MessageCallback): void {
|
|
132
|
+
on(messageType: string, callback: MessageCallback<V>): void {
|
|
133
133
|
this.eventManager.on(messageType, callback);
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -139,7 +139,7 @@ export default class EmbeddedComponent<V, R> {
|
|
|
139
139
|
* @param callback - The callback function to remove
|
|
140
140
|
*/
|
|
141
141
|
|
|
142
|
-
off(messageType: string, callback: MessageCallback): void {
|
|
142
|
+
off(messageType: string, callback: MessageCallback<V>): void {
|
|
143
143
|
this.eventManager.off(messageType, callback);
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -147,9 +147,9 @@ export default class EmbeddedComponent<V, R> {
|
|
|
147
147
|
* Updates the transaction value and sends an update message to the component
|
|
148
148
|
* @param value - The new transaction value
|
|
149
149
|
*/
|
|
150
|
-
update(value: V) {
|
|
150
|
+
update(value: Partial<V>) {
|
|
151
151
|
this._value = value;
|
|
152
|
-
this.send({ type: HMType.UPDATE, value: value
|
|
152
|
+
this.send({ type: HMType.UPDATE, value: value });
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
@@ -157,7 +157,7 @@ export default class EmbeddedComponent<V, R> {
|
|
|
157
157
|
* @returns A promise that resolves with the transaction response
|
|
158
158
|
*/
|
|
159
159
|
|
|
160
|
-
completion(): Promise<
|
|
160
|
+
completion(): Promise<TransactionResponse<V>> {
|
|
161
161
|
return new Promise((resolve, reject) => {
|
|
162
162
|
this.on(CMType.COMPLETE, (message) => {
|
|
163
163
|
resolve((message as any).response);
|
|
@@ -172,26 +172,24 @@ export default class EmbeddedComponent<V, R> {
|
|
|
172
172
|
* Opens the component in a modal dialog
|
|
173
173
|
*/
|
|
174
174
|
|
|
175
|
-
openModal(): Promise<
|
|
175
|
+
openModal(): Promise<TransactionResponse<V>> {
|
|
176
176
|
if (this.modal) {
|
|
177
177
|
this.closeModal();
|
|
178
178
|
}
|
|
179
179
|
this.modal = document.createElement('dialog');
|
|
180
180
|
this.modal.style.border = 'none';
|
|
181
|
-
this.modal.style.backgroundColor = '
|
|
181
|
+
this.modal.style.backgroundColor = 'white';
|
|
182
182
|
this.modal.style.maxWidth = '100vw';
|
|
183
183
|
this.modal.style.maxHeight = '100vh';
|
|
184
184
|
this.modal.style.width = '600px';
|
|
185
|
-
this.modal.style.height = '
|
|
185
|
+
this.modal.style.height = '600px';
|
|
186
186
|
|
|
187
187
|
document.body.appendChild(this.modal);
|
|
188
188
|
this.embed(this.modal, true);
|
|
189
189
|
this.on(CMType.CANCEL, () => {
|
|
190
190
|
this.closeModal();
|
|
191
191
|
});
|
|
192
|
-
|
|
193
|
-
this.closeModal();
|
|
194
|
-
});
|
|
192
|
+
|
|
195
193
|
this.on(CMType.COMPLETE, () => {
|
|
196
194
|
this.closeModal();
|
|
197
195
|
});
|
|
@@ -210,7 +208,7 @@ export default class EmbeddedComponent<V, R> {
|
|
|
210
208
|
|
|
211
209
|
closeModal(): void {
|
|
212
210
|
if (this.modal) {
|
|
213
|
-
console.log('closeModal');
|
|
211
|
+
// console.log('closeModal');
|
|
214
212
|
this.modal?.close();
|
|
215
213
|
this.modal.remove();
|
|
216
214
|
this.modal = undefined;
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
HMType,
|
|
5
5
|
HostMessage,
|
|
6
6
|
Transaction,
|
|
7
|
-
TransactionResponse,
|
|
8
7
|
Withdrawal,
|
|
9
8
|
} from '../../types';
|
|
10
9
|
import EmbeddedComponent from '../EmbeddedComponent';
|
|
@@ -15,15 +14,11 @@ const value: Partial<Transaction> = { amountDecimal: 100 };
|
|
|
15
14
|
|
|
16
15
|
describe('EmbeddedComponent', () => {
|
|
17
16
|
describe('creation', () => {
|
|
18
|
-
let component: EmbeddedComponent<
|
|
19
|
-
Partial<Withdrawal>,
|
|
20
|
-
TransactionResponse<Withdrawal>
|
|
21
|
-
>;
|
|
17
|
+
let component: EmbeddedComponent<Withdrawal>;
|
|
22
18
|
beforeEach(() => {
|
|
23
|
-
component = new EmbeddedComponent<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
>(url, { amountDecimal: 100 });
|
|
19
|
+
component = new EmbeddedComponent<Withdrawal>(url, {
|
|
20
|
+
amountDecimal: 100,
|
|
21
|
+
});
|
|
27
22
|
});
|
|
28
23
|
|
|
29
24
|
test('sets value', () => {
|
|
@@ -73,20 +68,14 @@ describe('EmbeddedComponent', () => {
|
|
|
73
68
|
});
|
|
74
69
|
|
|
75
70
|
test('mount', () => {
|
|
76
|
-
const component = new EmbeddedComponent<
|
|
77
|
-
Partial<Withdrawal>,
|
|
78
|
-
TransactionResponse<Withdrawal>
|
|
79
|
-
>(url, value);
|
|
71
|
+
const component = new EmbeddedComponent<Withdrawal>(url, value);
|
|
80
72
|
component.mount(parentId);
|
|
81
|
-
expect(iframe?.src).toBe(url);
|
|
73
|
+
expect(iframe?.src).toBe(url + '&embedded=true');
|
|
82
74
|
expect(parentElement.appendChild).toHaveBeenCalledWith(iframe);
|
|
83
75
|
});
|
|
84
76
|
|
|
85
77
|
test('on', () => {
|
|
86
|
-
const component = new EmbeddedComponent<
|
|
87
|
-
Partial<Withdrawal>,
|
|
88
|
-
TransactionResponse<Withdrawal>
|
|
89
|
-
>(url, value);
|
|
78
|
+
const component = new EmbeddedComponent<Withdrawal>(url, value);
|
|
90
79
|
const messageType = 'customEvent';
|
|
91
80
|
const callback = vi.fn();
|
|
92
81
|
component.on(messageType, callback);
|
|
@@ -97,10 +86,7 @@ describe('EmbeddedComponent', () => {
|
|
|
97
86
|
});
|
|
98
87
|
|
|
99
88
|
test('off', () => {
|
|
100
|
-
const component = new EmbeddedComponent<
|
|
101
|
-
Partial<Withdrawal>,
|
|
102
|
-
TransactionResponse<Withdrawal>
|
|
103
|
-
>(url, value);
|
|
89
|
+
const component = new EmbeddedComponent<Withdrawal>(url, value);
|
|
104
90
|
const messageType = 'customEvent';
|
|
105
91
|
const callback = vi.fn();
|
|
106
92
|
component.on(messageType, callback);
|
|
@@ -118,10 +104,7 @@ describe('EmbeddedComponent', () => {
|
|
|
118
104
|
let messageHandler: (event: MessageEvent) => void;
|
|
119
105
|
let port: MessagePort;
|
|
120
106
|
let handshake: MessageEvent;
|
|
121
|
-
let component: EmbeddedComponent<
|
|
122
|
-
Partial<Withdrawal>,
|
|
123
|
-
TransactionResponse<Withdrawal>
|
|
124
|
-
>;
|
|
107
|
+
let component: EmbeddedComponent<Withdrawal>;
|
|
125
108
|
|
|
126
109
|
beforeEach(() => {
|
|
127
110
|
port = {
|
|
@@ -138,10 +121,7 @@ describe('EmbeddedComponent', () => {
|
|
|
138
121
|
.mockImplementation((event, handler) => {
|
|
139
122
|
messageHandler = handler;
|
|
140
123
|
});
|
|
141
|
-
component = new EmbeddedComponent<
|
|
142
|
-
Partial<Withdrawal>,
|
|
143
|
-
TransactionResponse<Withdrawal>
|
|
144
|
-
>(url, value);
|
|
124
|
+
component = new EmbeddedComponent<Withdrawal>(url, value);
|
|
145
125
|
component.mount(parentId);
|
|
146
126
|
|
|
147
127
|
expect(messageHandler).toBeDefined();
|
|
@@ -149,7 +129,7 @@ describe('EmbeddedComponent', () => {
|
|
|
149
129
|
});
|
|
150
130
|
|
|
151
131
|
test('send', () => {
|
|
152
|
-
const message: HostMessage = {
|
|
132
|
+
const message: HostMessage<Withdrawal> = {
|
|
153
133
|
type: HMType.UPDATE,
|
|
154
134
|
value: {
|
|
155
135
|
requestId: 'id',
|
|
@@ -175,7 +155,7 @@ describe('EmbeddedComponent', () => {
|
|
|
175
155
|
// @ts-expect-error - we've already verified that port exists
|
|
176
156
|
port.onmessage({
|
|
177
157
|
data: { type: CMType.COMPLETE, response },
|
|
178
|
-
}
|
|
158
|
+
});
|
|
179
159
|
|
|
180
160
|
promise.then((result) => {
|
|
181
161
|
expect(result).toBe(response);
|
package/src/locales.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const languages = {
|
|
2
|
+
ar: 'العربية (Arabic)',
|
|
3
|
+
bg: 'български (Bulgarian)',
|
|
4
|
+
ca: 'Català (Catalan)',
|
|
5
|
+
cs: 'Čeština (Czech)',
|
|
6
|
+
da: 'Dansk (Danish)',
|
|
7
|
+
de: 'Deutsch (German)',
|
|
8
|
+
el: 'Ελληνικά (Greek)',
|
|
9
|
+
en: 'English (English)',
|
|
10
|
+
es: 'Español (Spanish)',
|
|
11
|
+
et: 'Eesti (Estonian)',
|
|
12
|
+
fa: 'فارسی (Persian)',
|
|
13
|
+
fi: 'Suomi (Finnish)',
|
|
14
|
+
fr: 'Français (French)',
|
|
15
|
+
he: 'עברית (Hebrew)',
|
|
16
|
+
hr: 'Hrvatski (Croatian)',
|
|
17
|
+
hu: 'Magyar (Hungarian)',
|
|
18
|
+
hy: 'Հայերեն (Armenian)',
|
|
19
|
+
id: 'Bahasa Indonesia (Indonesian)',
|
|
20
|
+
is: 'Íslenska (Icelandic)',
|
|
21
|
+
it: 'Italiano (Italian)',
|
|
22
|
+
ja: '日本語 (Japanese)',
|
|
23
|
+
ka: 'ქართული (Georgian)',
|
|
24
|
+
ko: '한국어 (Korean)',
|
|
25
|
+
lt: 'Lietuvių (Lithuanian)',
|
|
26
|
+
lv: 'Latviešu (Latvian)',
|
|
27
|
+
mn: 'Монгол (Mongolian)',
|
|
28
|
+
ms: 'Bahasa Melayu (Malay)',
|
|
29
|
+
mt: 'Malti (Maltese)',
|
|
30
|
+
nl: 'Nederlands (Dutch)',
|
|
31
|
+
no: 'Norsk (Norwegian)',
|
|
32
|
+
pl: 'Polski (Polish)',
|
|
33
|
+
pt: 'Português (Portuguese)',
|
|
34
|
+
ro: 'Română (Romanian)',
|
|
35
|
+
ru: 'Русский (Russian)',
|
|
36
|
+
sk: 'Slovenčina (Slovak)',
|
|
37
|
+
sl: 'Slovenščina (Slovenian)',
|
|
38
|
+
sr: 'Српски (Serbian)',
|
|
39
|
+
sv: 'Svenska (Swedish)',
|
|
40
|
+
sw: 'Kiswahili (Swahili)',
|
|
41
|
+
th: 'ไทย (Thai)',
|
|
42
|
+
tl: 'Tagalog (Tagalog)',
|
|
43
|
+
tr: 'Türkçe (Turkish)',
|
|
44
|
+
uk: 'Українська (Ukrainian)',
|
|
45
|
+
vi: 'Tiếng Việt (Vietnamese)',
|
|
46
|
+
zh: '中文 (Chinese)',
|
|
47
|
+
};
|
package/src/notabene.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type {
|
|
|
4
4
|
CallbackOptions,
|
|
5
5
|
ComponentMessage,
|
|
6
6
|
ConnectionRequest,
|
|
7
|
-
ConnectionResponse,
|
|
8
7
|
Counterparty,
|
|
9
8
|
DeclarationProof,
|
|
10
9
|
Deposit,
|
|
@@ -35,11 +34,11 @@ import {
|
|
|
35
34
|
} from './types';
|
|
36
35
|
import { encodeObjectToFragment } from './utils/urls';
|
|
37
36
|
|
|
37
|
+
// Must be exported for React Native SDK to use
|
|
38
|
+
export { default as EmbeddedComponent } from './components/EmbeddedComponent';
|
|
38
39
|
export type {
|
|
39
40
|
ComponentMessage,
|
|
40
|
-
EmbeddedComponent,
|
|
41
41
|
ConnectionRequest,
|
|
42
|
-
ConnectionResponse,
|
|
43
42
|
HostMessage,
|
|
44
43
|
Theme,
|
|
45
44
|
Counterparty,
|
|
@@ -182,13 +181,13 @@ export default class Notabene {
|
|
|
182
181
|
* @returns A new EmbeddedComponent instance
|
|
183
182
|
* @internal
|
|
184
183
|
*/
|
|
185
|
-
createComponent<V
|
|
184
|
+
createComponent<V>(
|
|
186
185
|
path: string,
|
|
187
|
-
value: V
|
|
186
|
+
value: Partial<V>,
|
|
188
187
|
options?: TransactionOptions,
|
|
189
188
|
callbacks?: CallbackOptions,
|
|
190
189
|
) {
|
|
191
|
-
return new EmbeddedComponent<V
|
|
190
|
+
return new EmbeddedComponent<V>(
|
|
192
191
|
this.componentUrl(path, value, options, callbacks),
|
|
193
192
|
value,
|
|
194
193
|
);
|
|
@@ -207,10 +206,12 @@ export default class Notabene {
|
|
|
207
206
|
options?: TransactionOptions,
|
|
208
207
|
callbacks?: CallbackOptions,
|
|
209
208
|
) {
|
|
210
|
-
return this.createComponent<
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
209
|
+
return this.createComponent<Withdrawal>(
|
|
210
|
+
'withdrawal-assist',
|
|
211
|
+
value,
|
|
212
|
+
options,
|
|
213
|
+
callbacks,
|
|
214
|
+
);
|
|
214
215
|
}
|
|
215
216
|
|
|
216
217
|
/**
|
|
@@ -227,10 +228,12 @@ export default class Notabene {
|
|
|
227
228
|
options?: TransactionOptions,
|
|
228
229
|
callbacks?: CallbackOptions,
|
|
229
230
|
) {
|
|
230
|
-
return this.createComponent<
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
return this.createComponent<Withdrawal>(
|
|
232
|
+
'wallet-assist',
|
|
233
|
+
value,
|
|
234
|
+
options,
|
|
235
|
+
callbacks,
|
|
236
|
+
);
|
|
234
237
|
}
|
|
235
238
|
|
|
236
239
|
/**
|
|
@@ -247,7 +250,7 @@ export default class Notabene {
|
|
|
247
250
|
options?: any,
|
|
248
251
|
callbacks?: CallbackOptions,
|
|
249
252
|
) {
|
|
250
|
-
return this.createComponent<
|
|
253
|
+
return this.createComponent<Deposit>(
|
|
251
254
|
'deposit-assist',
|
|
252
255
|
value,
|
|
253
256
|
options,
|
|
@@ -269,7 +272,7 @@ export default class Notabene {
|
|
|
269
272
|
options?: TransactionOptions,
|
|
270
273
|
callbacks?: CallbackOptions,
|
|
271
274
|
) {
|
|
272
|
-
return this.createComponent<ConnectionRequest
|
|
275
|
+
return this.createComponent<ConnectionRequest>(
|
|
273
276
|
'connect',
|
|
274
277
|
value,
|
|
275
278
|
options,
|
|
@@ -291,10 +294,12 @@ export default class Notabene {
|
|
|
291
294
|
options?: TransactionOptions,
|
|
292
295
|
callbacks?: CallbackOptions,
|
|
293
296
|
) {
|
|
294
|
-
return this.createComponent<
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
297
|
+
return this.createComponent<DepositRequest>(
|
|
298
|
+
'deposit-request',
|
|
299
|
+
value,
|
|
300
|
+
options,
|
|
301
|
+
callbacks,
|
|
302
|
+
);
|
|
298
303
|
}
|
|
299
304
|
|
|
300
305
|
/**
|
package/src/types.ts
CHANGED
|
@@ -355,17 +355,6 @@ export interface ConnectionRequest extends ComponentRequest {
|
|
|
355
355
|
asset: TransactionAsset;
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
/**
|
|
359
|
-
* An object representing a connection response
|
|
360
|
-
* @public
|
|
361
|
-
*/
|
|
362
|
-
export interface ConnectionResponse extends ComponentResponse {
|
|
363
|
-
value: ConnectionRequest;
|
|
364
|
-
ivms: IVMS101;
|
|
365
|
-
proof?: OwnershipProof;
|
|
366
|
-
txCreate?: V1Transaction;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
358
|
/**
|
|
370
359
|
* The verification status of a transaction
|
|
371
360
|
* @public
|
|
@@ -469,19 +458,19 @@ export const enum CMType {
|
|
|
469
458
|
RESULT = 'result',
|
|
470
459
|
READY = 'ready',
|
|
471
460
|
INVALID = 'invalid',
|
|
472
|
-
MODAL = 'openModal',
|
|
473
461
|
ERROR = 'error',
|
|
474
|
-
CLOSE = 'closeModal',
|
|
475
462
|
CANCEL = 'cancel',
|
|
476
463
|
}
|
|
477
464
|
|
|
478
465
|
/**
|
|
479
466
|
* Represents a completed component message
|
|
467
|
+
* @typeParam T - The overall Value type being returned
|
|
468
|
+
* @param response - The Response object which wraps T
|
|
480
469
|
* @public
|
|
481
470
|
*/
|
|
482
|
-
export type Completed = {
|
|
471
|
+
export type Completed<T> = {
|
|
483
472
|
type: CMType.COMPLETE;
|
|
484
|
-
response:
|
|
473
|
+
response: TransactionResponse<T>;
|
|
485
474
|
};
|
|
486
475
|
|
|
487
476
|
/**
|
|
@@ -493,8 +482,8 @@ export type Ready = {
|
|
|
493
482
|
};
|
|
494
483
|
|
|
495
484
|
/**
|
|
496
|
-
* Represents a resize request component message
|
|
497
|
-
* @
|
|
485
|
+
* Represents a resize request component message. This is handled by the library.
|
|
486
|
+
* @internal
|
|
498
487
|
*/
|
|
499
488
|
export type ResizeRequest = {
|
|
500
489
|
type: CMType.RESIZE;
|
|
@@ -503,6 +492,7 @@ export type ResizeRequest = {
|
|
|
503
492
|
|
|
504
493
|
/**
|
|
505
494
|
* Represents an error component message
|
|
495
|
+
* @param message - Error message
|
|
506
496
|
* @public
|
|
507
497
|
*/
|
|
508
498
|
export type Error = {
|
|
@@ -512,7 +502,7 @@ export type Error = {
|
|
|
512
502
|
|
|
513
503
|
/**
|
|
514
504
|
* Represents a cancel component message
|
|
515
|
-
* @
|
|
505
|
+
* @internal
|
|
516
506
|
*/
|
|
517
507
|
export type Cancel = {
|
|
518
508
|
type: CMType.CANCEL;
|
|
@@ -520,11 +510,14 @@ export type Cancel = {
|
|
|
520
510
|
|
|
521
511
|
/**
|
|
522
512
|
* Represents an invalid value component message
|
|
523
|
-
* @
|
|
513
|
+
* @typeParam T - The overall Value type being returned
|
|
514
|
+
* @param value - The current Partial value
|
|
515
|
+
* @param errors - Array of validation errors
|
|
516
|
+
* @internal
|
|
524
517
|
*/
|
|
525
|
-
export type InvalidValue = {
|
|
518
|
+
export type InvalidValue<T> = {
|
|
526
519
|
type: CMType.INVALID;
|
|
527
|
-
value:
|
|
520
|
+
value: Partial<T>;
|
|
528
521
|
errors: ValidationError[];
|
|
529
522
|
};
|
|
530
523
|
|
|
@@ -532,13 +525,13 @@ export type InvalidValue = {
|
|
|
532
525
|
* Component Message
|
|
533
526
|
* @public
|
|
534
527
|
*/
|
|
535
|
-
export type ComponentMessage =
|
|
536
|
-
| Completed
|
|
528
|
+
export type ComponentMessage<T> =
|
|
529
|
+
| Completed<T>
|
|
537
530
|
| Cancel
|
|
538
531
|
| Error
|
|
539
532
|
| Ready
|
|
540
533
|
| ResizeRequest
|
|
541
|
-
| InvalidValue
|
|
534
|
+
| InvalidValue<T>;
|
|
542
535
|
|
|
543
536
|
/**
|
|
544
537
|
* Host Message Types
|
|
@@ -551,19 +544,19 @@ export const enum HMType {
|
|
|
551
544
|
}
|
|
552
545
|
|
|
553
546
|
/**
|
|
554
|
-
* Represents an update value host message
|
|
547
|
+
* Represents an update value host message. This is sent from Host to component.
|
|
555
548
|
* @public
|
|
556
549
|
*/
|
|
557
|
-
export type UpdateValue = {
|
|
550
|
+
export type UpdateValue<T> = {
|
|
558
551
|
type: HMType.UPDATE;
|
|
559
|
-
value:
|
|
552
|
+
value: Partial<T>;
|
|
560
553
|
};
|
|
561
554
|
|
|
562
555
|
/**
|
|
563
556
|
* Host Messages
|
|
564
557
|
* @public
|
|
565
558
|
*/
|
|
566
|
-
export type HostMessage = UpdateValue
|
|
559
|
+
export type HostMessage<T> = UpdateValue<T>;
|
|
567
560
|
|
|
568
561
|
/**
|
|
569
562
|
* Options for callback and redirect URIs
|
|
@@ -592,6 +585,7 @@ export enum ProofStatus {
|
|
|
592
585
|
export enum ProofTypes {
|
|
593
586
|
SelfDeclaration = 'self-declaration',
|
|
594
587
|
PersonalSignEIP191 = 'eip-191',
|
|
588
|
+
SIWE = 'siwe',
|
|
595
589
|
PersonalSignEIP712 = 'eip-712',
|
|
596
590
|
PersonalSignBIP137 = 'bip-137',
|
|
597
591
|
PersonalSignXPUB = 'xpub',
|
|
@@ -619,6 +613,7 @@ export interface SignatureProof extends OwnershipProof {
|
|
|
619
613
|
| ProofTypes.PersonalSignEIP191
|
|
620
614
|
| ProofTypes.PersonalSignEIP712
|
|
621
615
|
| ProofTypes.PersonalSignBIP137
|
|
616
|
+
| ProofTypes.SIWE
|
|
622
617
|
| ProofTypes.PersonalSignXPUB;
|
|
623
618
|
proof: string;
|
|
624
619
|
attestation: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ComponentMessage, HostMessage } from '../types';
|
|
2
2
|
|
|
3
|
-
export type MessageCallback = (message: ComponentMessage) => void;
|
|
3
|
+
export type MessageCallback<T> = (message: ComponentMessage<T>) => void;
|
|
4
4
|
|
|
5
|
-
export class MessageEventManager {
|
|
6
|
-
private listeners: Map<string, Set<MessageCallback
|
|
5
|
+
export class MessageEventManager<T> {
|
|
6
|
+
private listeners: Map<string, Set<MessageCallback<T>>> = new Map();
|
|
7
7
|
private port?: MessagePort;
|
|
8
8
|
|
|
9
9
|
constructor() {
|
|
@@ -16,14 +16,14 @@ export class MessageEventManager {
|
|
|
16
16
|
this.port.start();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
on(messageType: string, callback: MessageCallback): void {
|
|
19
|
+
on(messageType: string, callback: MessageCallback<T>): void {
|
|
20
20
|
if (!this.listeners.has(messageType)) {
|
|
21
21
|
this.listeners.set(messageType, new Set());
|
|
22
22
|
}
|
|
23
23
|
this.listeners.get(messageType)!.add(callback);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
off(messageType: string, callback: MessageCallback): void {
|
|
26
|
+
off(messageType: string, callback: MessageCallback<T>): void {
|
|
27
27
|
const callbacks = this.listeners.get(messageType);
|
|
28
28
|
if (callbacks) {
|
|
29
29
|
callbacks.delete(callback);
|
|
@@ -33,8 +33,8 @@ export class MessageEventManager {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
private handleMessage(event: MessageEvent): void {
|
|
37
|
-
console.log('received message', event.data);
|
|
36
|
+
private handleMessage(event: MessageEvent<ComponentMessage<T>>): void {
|
|
37
|
+
// console.log('received message', event.data);
|
|
38
38
|
const message = event.data;
|
|
39
39
|
if (typeof message === 'object' && message !== null && 'type' in message) {
|
|
40
40
|
const messageType = message.type as string;
|
|
@@ -46,7 +46,7 @@ export class MessageEventManager {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// Method to send messages through the port
|
|
49
|
-
send(message: HostMessage): void {
|
|
49
|
+
send(message: HostMessage<T>): void {
|
|
50
50
|
if (this.port) {
|
|
51
51
|
this.port.postMessage(message);
|
|
52
52
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { HMType, UpdateValue } from '../../types';
|
|
2
|
+
import { HMType, UpdateValue, Withdrawal } from '../../types';
|
|
3
3
|
import { MessageEventManager } from '../MessageEventManager';
|
|
4
4
|
|
|
5
5
|
describe('MessageEventManager', () => {
|
|
6
|
-
let messageEventManager: MessageEventManager
|
|
6
|
+
let messageEventManager: MessageEventManager<Withdrawal>;
|
|
7
7
|
let mockPort: MessagePort;
|
|
8
8
|
|
|
9
9
|
beforeEach(() => {
|
|
@@ -73,7 +73,7 @@ describe('MessageEventManager', () => {
|
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
it('should send messages through the port', () => {
|
|
76
|
-
const message: UpdateValue = {
|
|
76
|
+
const message: UpdateValue<Withdrawal> = {
|
|
77
77
|
type: HMType.UPDATE,
|
|
78
78
|
value: { requestId: 'id' },
|
|
79
79
|
};
|