create-partylayer-app 0.3.0 → 0.4.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/dist/templates.d.ts.map +1 -1
- package/dist/templates.js +5 -0
- package/dist/templates.js.map +1 -1
- package/package.json +1 -1
- package/templates/vanilla/README.md +36 -0
- package/templates/vanilla/_gitignore +7 -0
- package/templates/vanilla/_package.json +18 -0
- package/templates/vanilla/index.html +12 -0
- package/templates/vanilla/src/main.ts +77 -0
- package/templates/vanilla/src/style.css +45 -0
- package/templates/vanilla/tsconfig.json +19 -0
- package/templates/vanilla/vite.config.ts +4 -0
package/dist/templates.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAC;IACX,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,SAAS,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAC;IACX,uCAAuC;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,SAAS,EAAE,YAAY,EAqBnC,CAAC;AAEF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEnD"}
|
package/dist/templates.js
CHANGED
|
@@ -14,6 +14,11 @@ export const TEMPLATES = [
|
|
|
14
14
|
label: 'Vue + Nuxt + Pinia',
|
|
15
15
|
hint: 'Nuxt 3 SSR session, PartyLayer session in a Pinia store',
|
|
16
16
|
},
|
|
17
|
+
{
|
|
18
|
+
id: 'vanilla',
|
|
19
|
+
label: 'Vanilla TypeScript',
|
|
20
|
+
hint: 'No framework — Vite + the @partylayer/sdk client API',
|
|
21
|
+
},
|
|
17
22
|
];
|
|
18
23
|
export function isTemplateId(value) {
|
|
19
24
|
return TEMPLATES.some((t) => t.id === value);
|
package/dist/templates.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,MAAM,SAAS,GAAmB;IACvC;QACE,EAAE,EAAE,YAAY;QAChB,KAAK,EAAE,cAAc;QACrB,IAAI,EAAE,2CAA2C;KAClD;IACD;QACE,EAAE,EAAE,UAAU;QACd,KAAK,EAAE,eAAe;QACtB,IAAI,EAAE,mDAAmD;KAC1D;IACD;QACE,EAAE,EAAE,gBAAgB;QACpB,KAAK,EAAE,oBAAoB;QAC3B,IAAI,EAAE,yDAAyD;KAChE;CACF,CAAC;AAEF,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC;AAC/C,CAAC"}
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,MAAM,SAAS,GAAmB;IACvC;QACE,EAAE,EAAE,YAAY;QAChB,KAAK,EAAE,cAAc;QACrB,IAAI,EAAE,2CAA2C;KAClD;IACD;QACE,EAAE,EAAE,UAAU;QACd,KAAK,EAAE,eAAe;QACtB,IAAI,EAAE,mDAAmD;KAC1D;IACD;QACE,EAAE,EAAE,gBAAgB;QACpB,KAAK,EAAE,oBAAoB;QAC3B,IAAI,EAAE,yDAAyD;KAChE;IACD;QACE,EAAE,EAAE,SAAS;QACb,KAAK,EAAE,oBAAoB;QAC3B,IAAI,EAAE,sDAAsD;KAC7D;CACF,CAAC;AAEF,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC;AAC/C,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# {{PROJECT_NAME}}
|
|
2
|
+
|
|
3
|
+
A [PartyLayer](https://partylayer.xyz) dApp — vanilla TypeScript + Vite, no framework.
|
|
4
|
+
|
|
5
|
+
## Develop
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run dev
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## How it's wired
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createPartyLayer } from '@partylayer/sdk';
|
|
15
|
+
|
|
16
|
+
const client = createPartyLayer({ network: 'devnet', app: { name: '{{PROJECT_NAME}}' } });
|
|
17
|
+
|
|
18
|
+
const wallets = await client.listWallets(); // verified wallets from the registry
|
|
19
|
+
const session = await client.connect({ walletId }); // connect to one
|
|
20
|
+
client.on('session:connected', () => { /* … */ }); // react to session changes
|
|
21
|
+
client.on('session:disconnected', () => { /* … */ });
|
|
22
|
+
const active = await client.getActiveSession(); // restore on load
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`createPartyLayer` is the dApp connect API — no framework bindings needed. See `src/main.ts` for the full hand-rolled connect UI. Switch networks by changing `network` to `"testnet"` or `"mainnet"`.
|
|
26
|
+
|
|
27
|
+
## Build
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm run build && npm run preview
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Docs
|
|
34
|
+
|
|
35
|
+
- [PartyLayer docs](https://partylayer.xyz/docs/introduction)
|
|
36
|
+
- [@partylayer/sdk](https://www.npmjs.com/package/@partylayer/sdk)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{PROJECT_NAME}}",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "tsc && vite build",
|
|
9
|
+
"preview": "vite preview"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@partylayer/sdk": "^0.10.0"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"typescript": "^5.6.2",
|
|
16
|
+
"vite": "^5.4.2"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>{{PROJECT_NAME}}</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="app"></div>
|
|
10
|
+
<script type="module" src="/src/main.ts"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { createPartyLayer, type Session } from '@partylayer/sdk';
|
|
2
|
+
import './style.css';
|
|
3
|
+
|
|
4
|
+
// The PartyLayer client — the dApp connect API (listWallets / connect / session).
|
|
5
|
+
// All built-in wallet adapters are auto-registered.
|
|
6
|
+
const client = createPartyLayer({ network: 'devnet', app: { name: '{{PROJECT_NAME}}' } });
|
|
7
|
+
|
|
8
|
+
const app = document.querySelector<HTMLDivElement>('#app')!;
|
|
9
|
+
app.innerHTML = `
|
|
10
|
+
<main class="app">
|
|
11
|
+
<h1>{{PROJECT_NAME}}</h1>
|
|
12
|
+
<p class="subtitle">A PartyLayer dApp on Canton — vanilla TypeScript, no framework.</p>
|
|
13
|
+
<div id="status" class="status"></div>
|
|
14
|
+
<button id="connect" class="btn">Connect Wallet</button>
|
|
15
|
+
<ul id="wallets" class="wallets" hidden></ul>
|
|
16
|
+
</main>
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
const statusEl = document.querySelector<HTMLDivElement>('#status')!;
|
|
20
|
+
const connectBtn = document.querySelector<HTMLButtonElement>('#connect')!;
|
|
21
|
+
const walletsEl = document.querySelector<HTMLUListElement>('#wallets')!;
|
|
22
|
+
|
|
23
|
+
const truncateParty = (p: string) => (p.length <= 16 ? p : `${p.slice(0, 10)}…${p.slice(-4)}`);
|
|
24
|
+
|
|
25
|
+
function renderConnected(session: Session) {
|
|
26
|
+
walletsEl.hidden = true;
|
|
27
|
+
connectBtn.hidden = true;
|
|
28
|
+
statusEl.innerHTML = `Connected as <code>${truncateParty(session.partyId)}</code>`;
|
|
29
|
+
const disconnect = document.createElement('button');
|
|
30
|
+
disconnect.className = 'btn';
|
|
31
|
+
disconnect.textContent = 'Disconnect';
|
|
32
|
+
disconnect.addEventListener('click', () => void client.disconnect());
|
|
33
|
+
statusEl.appendChild(disconnect);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function renderDisconnected() {
|
|
37
|
+
statusEl.textContent = 'Not connected — connect a wallet to continue.';
|
|
38
|
+
connectBtn.hidden = false;
|
|
39
|
+
walletsEl.hidden = true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Connect → list the verified wallets from the registry → pick one → connect.
|
|
43
|
+
connectBtn.addEventListener('click', async () => {
|
|
44
|
+
const wallets = await client.listWallets();
|
|
45
|
+
walletsEl.innerHTML = wallets
|
|
46
|
+
.map(
|
|
47
|
+
(w, i) => `<li>
|
|
48
|
+
<button class="wallet" data-idx="${i}">
|
|
49
|
+
${w.icons?.md ? `<img src="${w.icons.md}" alt="" width="24" height="24" />` : ''}
|
|
50
|
+
<span>${w.name}</span>
|
|
51
|
+
</button>
|
|
52
|
+
</li>`,
|
|
53
|
+
)
|
|
54
|
+
.join('');
|
|
55
|
+
walletsEl.hidden = false;
|
|
56
|
+
walletsEl.querySelectorAll<HTMLButtonElement>('.wallet').forEach((btn) => {
|
|
57
|
+
btn.addEventListener('click', async () => {
|
|
58
|
+
// Pass the WalletInfo's walletId (a branded WalletId), not a raw string.
|
|
59
|
+
const wallet = wallets[Number(btn.dataset.idx)];
|
|
60
|
+
try {
|
|
61
|
+
const session = await client.connect({ walletId: wallet.walletId });
|
|
62
|
+
renderConnected(session);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
statusEl.textContent = `Connect failed: ${(err as Error).message}`;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Keep the UI in sync with external session changes (multi-tab, expiry, restore).
|
|
71
|
+
client.on('session:connected', () => {
|
|
72
|
+
void client.getActiveSession().then((s) => s && renderConnected(s));
|
|
73
|
+
});
|
|
74
|
+
client.on('session:disconnected', () => renderDisconnected());
|
|
75
|
+
|
|
76
|
+
// Initial state — restore an existing session if there is one.
|
|
77
|
+
void client.getActiveSession().then((s) => (s ? renderConnected(s) : renderDisconnected()));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
|
|
3
|
+
color-scheme: light dark;
|
|
4
|
+
background: #0b0f1a;
|
|
5
|
+
color: rgba(255, 255, 255, 0.92);
|
|
6
|
+
}
|
|
7
|
+
* { box-sizing: border-box; }
|
|
8
|
+
body { margin: 0; }
|
|
9
|
+
.app {
|
|
10
|
+
min-height: 100vh;
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
gap: 16px;
|
|
16
|
+
padding: 24px;
|
|
17
|
+
text-align: center;
|
|
18
|
+
}
|
|
19
|
+
.app h1 { font-size: 2.5rem; margin: 0; }
|
|
20
|
+
.subtitle { margin: 0 0 8px; color: rgba(255, 255, 255, 0.6); max-width: 32rem; }
|
|
21
|
+
.status { display: flex; align-items: center; gap: 12px; }
|
|
22
|
+
.status code { background: rgba(255, 255, 255, 0.08); padding: 2px 8px; border-radius: 6px; }
|
|
23
|
+
.btn {
|
|
24
|
+
padding: 10px 18px;
|
|
25
|
+
border-radius: 8px;
|
|
26
|
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
27
|
+
background: #ffcc00;
|
|
28
|
+
color: #0b0f1a;
|
|
29
|
+
font-weight: 600;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
}
|
|
32
|
+
.wallets { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 20rem; }
|
|
33
|
+
.wallet {
|
|
34
|
+
width: 100%;
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
gap: 10px;
|
|
38
|
+
padding: 10px 14px;
|
|
39
|
+
border-radius: 8px;
|
|
40
|
+
border: 1px solid rgba(255, 255, 255, 0.15);
|
|
41
|
+
background: rgba(255, 255, 255, 0.04);
|
|
42
|
+
color: inherit;
|
|
43
|
+
cursor: pointer;
|
|
44
|
+
}
|
|
45
|
+
.wallet img { border-radius: 6px; }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
"allowImportingTsExtensions": true,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"noUnusedLocals": true,
|
|
15
|
+
"noUnusedParameters": true,
|
|
16
|
+
"noFallthroughCasesInSwitch": true
|
|
17
|
+
},
|
|
18
|
+
"include": ["src"]
|
|
19
|
+
}
|