cruzo-web3 0.1.0 → 0.1.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
CHANGED
|
@@ -83,12 +83,14 @@ Without a Project ID, the **Mobile wallet (WalletConnect)** option stays disable
|
|
|
83
83
|
TON wallets (extension and mobile app) require a public `tonconnect-manifest.json`.
|
|
84
84
|
|
|
85
85
|
1. Add the manifest file to your site root (must be reachable over HTTPS in production).
|
|
86
|
-
2. Point `web3Service` to
|
|
86
|
+
2. Point `web3Service` to the absolute manifest URL at app bootstrap:
|
|
87
87
|
|
|
88
88
|
```ts
|
|
89
|
-
web3Service
|
|
90
|
-
|
|
91
|
-
);
|
|
89
|
+
import { web3Service } from "cruzo-web3";
|
|
90
|
+
|
|
91
|
+
const tonManifestUrl = new URL("/tonconnect-manifest.json", window.location.href).href;
|
|
92
|
+
|
|
93
|
+
web3Service.setTonManifestUrl(tonManifestUrl);
|
|
92
94
|
```
|
|
93
95
|
|
|
94
96
|
Example manifest:
|
|
@@ -3,7 +3,7 @@ import styles from "./web3-signing.component.module.css";
|
|
|
3
3
|
import { AbstractComponent, componentsRegistryService, routerService, RxBucket } from "cruzo";
|
|
4
4
|
import { UI_KIT } from "cruzo/ui-components/const";
|
|
5
5
|
|
|
6
|
-
import "../web3-signer/web3-signer.component";
|
|
6
|
+
import { Web3SignerComponent } from "../web3-signer/web3-signer.component";
|
|
7
7
|
import { detectInjectedWallets, getInjectedWalletLabel } from "../../providers/injected";
|
|
8
8
|
import {
|
|
9
9
|
buildSearchWithSigning,
|
|
@@ -23,7 +23,7 @@ const PAYLOAD_INPUT_ID = "payload";
|
|
|
23
23
|
export class Web3SigningComponent extends AbstractComponent {
|
|
24
24
|
static selector = "web3-signing-component";
|
|
25
25
|
|
|
26
|
-
dependencies = new Set([
|
|
26
|
+
dependencies = new Set([Web3SignerComponent.selector]);
|
|
27
27
|
|
|
28
28
|
walletHint$ = this.newRx("");
|
|
29
29
|
stateOverview$ = this.newRx("");
|
|
@@ -85,7 +85,6 @@ export class Web3SigningComponent extends AbstractComponent {
|
|
|
85
85
|
connectedCallback() {
|
|
86
86
|
componentsRegistryService.connectBucket(this.innerBucket);
|
|
87
87
|
super.connectedCallback();
|
|
88
|
-
this.ensureTonManifest();
|
|
89
88
|
this.updateWalletHint();
|
|
90
89
|
this.setupUrlSync();
|
|
91
90
|
}
|
|
@@ -218,12 +217,6 @@ export class Web3SigningComponent extends AbstractComponent {
|
|
|
218
217
|
return { pubKey: null, signed: false, wallet: null };
|
|
219
218
|
}
|
|
220
219
|
|
|
221
|
-
private ensureTonManifest() {
|
|
222
|
-
if (web3Service.getTonManifestUrl()) return;
|
|
223
|
-
|
|
224
|
-
web3Service.setTonManifestUrl(new URL("/tonconnect-manifest.json", window.location.href).href);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
220
|
private updateWalletHint() {
|
|
228
221
|
const extensions = detectInjectedWallets();
|
|
229
222
|
const hints = ["Click Connect wallet to choose a provider (extension or mobile app)."];
|
|
@@ -80,6 +80,7 @@ export class TonConnectProvider implements Web3Provider {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
async signMessage(message: string | Uint8Array) {
|
|
83
|
+
await this.ui.connectionRestored;
|
|
83
84
|
const account = this.requireAccount();
|
|
84
85
|
const text = new TextDecoder().decode(toMessageBytes(message));
|
|
85
86
|
|
package/lib/web3.service.ts
CHANGED
|
@@ -118,6 +118,7 @@ export class Web3Service extends AbstractService {
|
|
|
118
118
|
readonly setup$ = this.newRx(0);
|
|
119
119
|
|
|
120
120
|
private provider: Web3Provider | null = null;
|
|
121
|
+
private activeProviderKey: string | null = null;
|
|
121
122
|
private tonManifestUrl: string | null = null;
|
|
122
123
|
private walletConnectProjectId: string | null = null;
|
|
123
124
|
private builtinProviders: Web3WalletSlot[] | null = null;
|
|
@@ -170,11 +171,20 @@ export class Web3Service extends AbstractService {
|
|
|
170
171
|
return getWalletModeLabel(wallet.kind, wallet.transport);
|
|
171
172
|
}
|
|
172
173
|
|
|
173
|
-
useProvider(provider: Web3Provider) {
|
|
174
|
+
useProvider(provider: Web3Provider, key: string | null = null) {
|
|
174
175
|
this.provider = provider;
|
|
176
|
+
this.activeProviderKey = key;
|
|
175
177
|
return this;
|
|
176
178
|
}
|
|
177
179
|
|
|
180
|
+
private walletProviderKey(kind: WalletKind, transport: WalletTransport) {
|
|
181
|
+
return `${kind}:${transport}`;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private customProviderKey(providerId: string) {
|
|
185
|
+
return `custom:${providerId}`;
|
|
186
|
+
}
|
|
187
|
+
|
|
178
188
|
getProvider() {
|
|
179
189
|
return this.provider;
|
|
180
190
|
}
|
|
@@ -218,6 +228,12 @@ export class Web3Service extends AbstractService {
|
|
|
218
228
|
kind: InjectedWalletKind = "ethereum",
|
|
219
229
|
options: InjectedProviderOptions = {},
|
|
220
230
|
) {
|
|
231
|
+
const key = this.walletProviderKey(kind, "extension");
|
|
232
|
+
|
|
233
|
+
if (this.provider && this.activeProviderKey === key) {
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
|
|
221
237
|
const provider = createInjectedProvider(
|
|
222
238
|
kind,
|
|
223
239
|
(pubKey) => {
|
|
@@ -228,7 +244,7 @@ export class Web3Service extends AbstractService {
|
|
|
228
244
|
},
|
|
229
245
|
);
|
|
230
246
|
|
|
231
|
-
return this.useProvider(provider);
|
|
247
|
+
return this.useProvider(provider, key);
|
|
232
248
|
}
|
|
233
249
|
|
|
234
250
|
async useWalletProvider(
|
|
@@ -236,6 +252,12 @@ export class Web3Service extends AbstractService {
|
|
|
236
252
|
transport: WalletTransport = "auto",
|
|
237
253
|
options: WalletProviderOptions = {},
|
|
238
254
|
) {
|
|
255
|
+
const key = this.walletProviderKey(kind, transport);
|
|
256
|
+
|
|
257
|
+
if (this.provider && this.activeProviderKey === key) {
|
|
258
|
+
return this;
|
|
259
|
+
}
|
|
260
|
+
|
|
239
261
|
const provider = await createWalletProvider(
|
|
240
262
|
kind,
|
|
241
263
|
transport,
|
|
@@ -245,7 +267,7 @@ export class Web3Service extends AbstractService {
|
|
|
245
267
|
this.walletOptions(options),
|
|
246
268
|
);
|
|
247
269
|
|
|
248
|
-
return this.useProvider(provider);
|
|
270
|
+
return this.useProvider(provider, key);
|
|
249
271
|
}
|
|
250
272
|
|
|
251
273
|
ensureInjectedProvider(
|
|
@@ -286,6 +308,8 @@ export class Web3Service extends AbstractService {
|
|
|
286
308
|
}
|
|
287
309
|
|
|
288
310
|
await this.provider.disconnect();
|
|
311
|
+
this.provider = null;
|
|
312
|
+
this.activeProviderKey = null;
|
|
289
313
|
this.userPubKey$.update(null);
|
|
290
314
|
}
|
|
291
315
|
|
|
@@ -314,8 +338,14 @@ export class Web3Service extends AbstractService {
|
|
|
314
338
|
}
|
|
315
339
|
|
|
316
340
|
async useCustomProvider(providerId: string) {
|
|
341
|
+
const key = this.customProviderKey(providerId);
|
|
342
|
+
|
|
343
|
+
if (this.provider && this.activeProviderKey === key) {
|
|
344
|
+
return this;
|
|
345
|
+
}
|
|
346
|
+
|
|
317
347
|
const provider = await this.resolveCustomProvider(providerId);
|
|
318
|
-
return this.useProvider(provider);
|
|
348
|
+
return this.useProvider(provider, key);
|
|
319
349
|
}
|
|
320
350
|
|
|
321
351
|
async connectCustom(providerId: string) {
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cruzo-web3",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Web3 addon for cruzo: wallet providers, sign, verify",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": [
|
|
8
8
|
"*.css",
|
|
9
|
-
"*.module.css"
|
|
9
|
+
"*.module.css",
|
|
10
|
+
"lib/**/*.component.ts"
|
|
10
11
|
],
|
|
11
12
|
"files": [
|
|
12
13
|
"lib",
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
"@tonconnect/sdk": ">=3.0.0",
|
|
35
36
|
"@tonconnect/ui": ">=3.0.0",
|
|
36
37
|
"@walletconnect/ethereum-provider": ">=2.0.0",
|
|
37
|
-
"cruzo": "
|
|
38
|
+
"cruzo": "0.9.889"
|
|
38
39
|
},
|
|
39
40
|
"peerDependenciesMeta": {
|
|
40
41
|
"@tonconnect/sdk": {
|
|
@@ -52,7 +53,7 @@
|
|
|
52
53
|
"@tonconnect/ui": "^3.0.0",
|
|
53
54
|
"@types/node": "20.0.0",
|
|
54
55
|
"@walletconnect/ethereum-provider": "^2.23.9",
|
|
55
|
-
"cruzo": "
|
|
56
|
+
"cruzo": "0.9.889",
|
|
56
57
|
"typescript": "5.9.3"
|
|
57
58
|
}
|
|
58
59
|
}
|