-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhtmlDapp.html
More file actions
1435 lines (1292 loc) · 60.6 KB
/
htmlDapp.html
File metadata and controls
1435 lines (1292 loc) · 60.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#080b17">
<title>Cardano Dapp</title>
<meta name="title" content="Cardano Dapp">
<meta name="description" content="Review the action details below and continue in GameChanger Wallet.">
<!-- Use for local deployments or for testing the library: -->
<script src="res/browser.min.js"></script>
<!-- Use library from CDN: -->
<!-- <script src="https://cdn.jsdelivr.net/npm/@gamechanger-finance/gc@latest/dist/browser.min.js"></script> -->
<style>
:root{--bg:#070b16;--bg2:#0d1330;--fg:#eef7ff;--muted:#93a6d8;--line:#2ad4ff33;--cyan:#29d7ff;--blue:#4a7cff;--violet:#8a5cff;--magenta:#ff4fd8;--panel:#0c1226cc;--panel2:#0a1022f2;--glass:#09112480;--glass2:#ffffffa8;--info:#63d5ff;--success:#7dffb0;--warn:#ffbd59;--danger:#ff7198;--mute:#93a6d8;--infoLine:#63d5ff55;--successLine:#7dffb055;--warnLine:#ffbd5955;--dangerLine:#ff719855;--muteLine:#93a6d855;--infoBg:#63d5ff14;--successBg:#7dffb014;--warnBg:#ffbd5914;--dangerBg:#ff719814;--muteBg:#93a6d814;--r:18px;--grad:linear-gradient(90deg,var(--cyan),var(--blue),var(--violet),var(--magenta));--glow:0 0 0 1px #2ad4ff2e,0 0 18px #4a7cff1f,0 0 34px #8a5cff14}
[data-theme="light"]{--bg:#eef6ff;--bg2:#dae7ff;--fg:#091126;--muted:#55648c;--line:#4a7cff2b;--panel:#ffffffcf;--panel2:#ffffffef;--info:#0a7db8;--success:#137a43;--warn:#9a6100;--danger:#b4234e;--mute:#55648c;--infoLine:#0a7db833;--successLine:#137a4333;--warnLine:#9a610033;--dangerLine:#b4234e33;--muteLine:#55648c33;--infoBg:#0a7db812;--successBg:#137a4312;--warnBg:#9a610012;--dangerBg:#b4234e12;--muteBg:#55648c12;--glow:0 0 0 1px #4a7cff26,0 14px 34px #4a7cff18}
*{box-sizing:border-box}html,body{margin:0;min-height:100%}body{font:14px/1.45 Inter,Segoe UI,Roboto,Arial,sans-serif;color:var(--fg);background:radial-gradient(circle at 14% 12%,#29d7ff20,transparent 24%),radial-gradient(circle at 84% 18%,#8a5cff22,transparent 24%),radial-gradient(circle at 70% 82%,#ff4fd81a,transparent 22%),linear-gradient(180deg,var(--bg),var(--bg2))}a,button,input,textarea,select{font:inherit}button,input,textarea,select{outline:none}pre{margin:0;white-space:pre-wrap;word-break:break-word}
.app{margin:0 auto;padding:5%}.hero,.card{border:1px solid var(--line);background:linear-gradient(180deg,var(--panel),var(--panel2));border-radius:var(--r);box-shadow:var(--glow);backdrop-filter:blur(10px)}.hero{padding:20px;margin-bottom:16px}
.hero__top,.row,.actions,.connect-widget,.connected-wallet,.checkbox{display:flex;gap:10px;align-items:center}.hero__top,.row{align-items:flex-start;justify-content:space-between}.hero__tools{display:flex;gap:10px;align-items:center;justify-content:flex-end;min-width:170px;flex-wrap:wrap}
.hero h1,.intent-meta__title{margin:0;background:var(--grad);-webkit-background-clip:text;background-clip:text;color:transparent}.hero h1{font-size:30px;line-height:1.08}.hero p,.muted,.section-copy,.hint,.connected-wallet__sub,.connected-wallet__address{color:var(--muted)}.hero p{margin:8px 0 0;max-width:70ch}
.layout{display:grid;grid-template-columns:minmax(0,1fr) 380px;gap:16px;align-items:start}.layout--single{grid-template-columns:minmax(0,1fr)}.card{padding:18px}.stack{display:grid;gap:14px}.form-grid,.mini-grid{display:grid;gap:12px;align-items:start}.form-grid{grid-template-columns:1fr}.mini-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
.control,.field input,.field textarea,.field select,.theme-select,.connected-wallet{width:100%;border:1px solid var(--line);border-radius:14px;padding:12px 13px;background:var(--glass);color:var(--fg)}.theme-select{width:auto}.connected-wallet{gap:12px;box-shadow:var(--glow);min-width:0;max-width:100%;padding:10px 12px}.connected-wallet__meta{display:grid;gap:2px;min-width:0}.connected-wallet__name,.connected-wallet__sub,.connected-wallet__address{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:240px}.connected-wallet__name{font-weight:700}
[data-theme="light"] .control,[data-theme="light"] .field input,[data-theme="light"] .field textarea,[data-theme="light"] .field select,[data-theme="light"] .theme-select,[data-theme="light"] .connected-wallet{background:var(--glass2)}
.field{display:grid;gap:6px;align-content:start;align-self:start;min-width:0}.field--full{grid-column:1/-1}.field label,.stat span{font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.08em}.field textarea{min-height:108px;resize:vertical}.checkbox{min-height:46px;padding:0 2px}.checkbox input{width:16px;height:16px}
.section-title{margin:0;font-size:15px;color:var(--cyan)}.intent-meta{padding:18px;border-radius:16px;border:1px solid #4a7cff40;background:linear-gradient(135deg,var(--bg),var(--bg2));box-shadow:inset 0 0 0 1px #ffffff05,0 0 24px #8a5cff14}.intent-meta__title{font-size:24px;line-height:1.12}.intent-meta__lead{margin:0;font-size:15px}.intent-meta__sub{margin-top:8px;font-size:13px;color:var(--muted)}
.card--info,.tone--info{border-color:var(--infoLine);background:linear-gradient(180deg,var(--infoBg),var(--panel2))}.card--success,.tone--success{border-color:var(--successLine);background:linear-gradient(180deg,var(--successBg),var(--panel2))}.card--warn,.tone--warn{border-color:var(--warnLine);background:linear-gradient(180deg,var(--warnBg),var(--panel2))}.card--danger,.tone--danger{border-color:var(--dangerLine);background:linear-gradient(180deg,var(--dangerBg),var(--panel2))}.card--mute,.tone--mute{border-color:var(--muteLine);background:linear-gradient(180deg,var(--muteBg),var(--panel2))}
.btn{display:inline-flex;align-items:center;justify-content:center;appearance:none;border:1px solid var(--line);border-radius:14px;padding:12px 14px;text-decoration:none;color:var(--fg);background:#ffffff06;cursor:pointer;transition:.15s transform,.15s opacity;min-width:0}.btn:hover{transform:translateY(-1px)}.btn--ghost{background:#ffffff03}.btn--primary{width:100%;justify-content:center;text-align:center;border-color:transparent;background:var(--grad);color:#fff;font-weight:700}.btn[disabled],.btn[aria-disabled="true"]{opacity:.55;pointer-events:none}
.actions{flex-wrap:wrap;align-items:stretch}#connect-link{display:flex;flex:0 0 100%;width:100%;max-width:100%;order:99}#connect-wallet-btn{width:auto}
.console{min-height:120px;max-height:420px;overflow:auto;padding:14px;border-radius:14px;border:1px solid var(--line);background:#060c1fcb;color:#cbf7ff}.empty{color:var(--muted)}.status{font-size:12px;min-height:18px}.status--info{color:var(--info)}.status--ok,.status--success{color:var(--success)}.status--warn{color:var(--warn)}.status--err,.status--danger{color:var(--danger)}.status--mute{color:var(--mute)}.hidden{display:none!important}.stat{padding:12px;border-radius:14px;border:1px solid var(--line);background:#ffffff04}.stat strong{display:block;margin-top:4px;font-size:15px;color:var(--cyan)}
.app-footer{padding:16px 0 0;text-align:center}.app-footer__links{display:flex;justify-content:center;gap:12px;flex-wrap:wrap;margin:0}.app-footer__links{font-size:12px}.app-footer__library{margin-top:10px;font-size:13px;font-weight:600}.app-footer a{color:var(--blue)}.app-footer a:hover{text-decoration:underline}.app-footer__text{color:var(--muted)}
@media (max-width:940px){.layout,.layout--single,.mini-grid{grid-template-columns:1fr}.hero__top{flex-direction:column}.hero__tools{width:100%;justify-content:flex-end}.connected-wallet{width:100%}.connected-wallet__name,.connected-wallet__sub,.connected-wallet__address{max-width:none}.btn--primary,#connect-link{width:100%;max-width:100%}}
</style>
</head>
<body data-theme="dark">
<div class="app">
<section class="hero">
<div class="hero__top">
<div>
<h1 id="app-title">Cardano Dapp</h1>
<p id="app-copy">Review the action details below and continue in GameChanger Wallet.</p>
</div>
<div class="hero__tools">
<div id="connect-widget" class="connect-widget hidden">
<button id="connect-wallet-btn" class="btn btn--primary hidden" type="button">Connect wallet</button>
<div id="connected-wallet" class="connected-wallet hidden">
<div class="connected-wallet__meta">
<div id="connected-wallet-name" class="connected-wallet__name"></div>
<div id="connected-wallet-sub" class="connected-wallet__sub"></div>
<div id="connected-wallet-address" class="connected-wallet__address"></div>
</div>
<button id="disconnect-wallet-btn" class="btn btn--ghost" type="button">Disconnect</button>
</div>
</div>
<select id="theme-select" class="theme-select" aria-label="Theme"><option value="dark">Dark</option><option value="light">Light</option></select>
</div>
</div>
</section>
<main id="layout" class="layout layout--single">
<section id="migration-banner" class="card stack card--warn hidden">
<div><h2 class="section-title">Stored data update available</h2><p class="section-copy status--warn">This dapp version differs from previously saved local data.</p><div class="hint status--warn">Updating will replace saved local state with the latest app version. Previously entered information may be lost.</div></div>
<div class="actions"><button id="migration-update-btn" class="btn btn--ghost" type="button">Update</button></div>
</section>
<section class="card stack">
<div class="form-grid">
<div id="intent-select-field" class="field">
<label for="intent-select">Action</label>
<select id="intent-select" class="control"></select>
</div>
</div>
<div id="intent-meta" class="intent-meta"></div>
<section id="args-section" class="stack hidden">
<div><h2 class="section-title">Details</h2></div>
<div id="args-form" class="form-grid"></div>
</section>
<div id="actions-section" class="actions">
<button id="reset-args-btn" class="btn btn--ghost" type="button">Reset</button>
<button id="toggle-options-btn" class="btn btn--ghost" type="button">Options</button>
<button id="copy-url-btn" class="btn btn--ghost" type="button">Copy link</button>
<a id="qr-link" class="btn btn--ghost" href="#" target="_blank" rel="noopener noreferrer">Open QR</a>
<a id="connect-link" class="btn btn--primary" href="#" target="gc_udc_popup" rel="noopener noreferrer">Continue</a>
</div>
<div id="action-status" class="status"></div>
<div id="field-status" class="status"></div>
<div id="options-panel" class="stack hidden">
<div><h2 class="section-title">Options</h2><p class="section-copy">Advanced settings.</p></div>
<div id="options-form" class="form-grid"></div>
<div class="actions"><button id="reset-storage-btn" class="btn btn--ghost" type="button">Reset storage</button></div>
</div>
</section>
<aside id="debug-panel" class="card stack hidden">
<div><h2 class="section-title">Persistent app state</h2></div>
<div class="mini-grid">
<div class="stat"><span>Selected intent</span><strong id="state-intent-key">-</strong></div>
<div class="stat"><span>Network</span><strong id="state-network">-</strong></div>
<div class="stat"><span>Stored intents</span><strong id="state-intent-count">-</strong></div>
<div class="stat"><span>Last result</span><strong id="state-last-result">-</strong></div>
</div>
<div><h3 class="section-title">Merged exports</h3><pre id="exports-box" class="console empty">No wallet exports captured yet.</pre></div>
<div><h3 class="section-title">Debug state</h3><pre id="state-box" class="console"></pre></div>
</aside>
</main>
<footer class="app-footer" aria-label="Relevant links">
<h6 class="app-footer__links">
<a target="_blank" rel="noopener noreferrer" href="https://twitter.com/GameChangerOk">X</a>
<a target="_blank" rel="noopener noreferrer" href="https://discord.gg/vpbfyRaDKG">Discord</a>
<a target="_blank" rel="noopener noreferrer" href="https://www.youtube.com/@gamechanger.finance">Youtube</a>
<a target="_blank" rel="noopener noreferrer" href="https://github.com/GameChangerFinance/gamechanger.wallet/">Github</a>
<a target="_blank" rel="noopener noreferrer" href="https://gamechanger.finance">Website</a>
</h6>
<div class="app-footer__library">
<span class="app-footer__text"> HTML - Auto-generated using </span>
<a target="_blank" rel="noopener noreferrer" href="https://www.npmjs.com/package/@gamechanger-finance/gc">GC NPM Library</a>
<span class="app-footer__text"> - 2026</span>
</div>
</footer>
</div>
<script>
'use strict';
/********************************************************************
* DEVELOPER CUSTOMIZATION SECTION
*
* Update this section to change defaults, UI fields, intent code,
* custom UI components, or business rules.
*
* Most integrations should only need edits here.
********************************************************************/
/**
* Global reactive app state.
*
* This is the single source of truth for the dapp runtime.
*
* Common customization examples:
* - replace or add intents in app.defaultIntents
* - override generated fields in app.config.ui.currentFields
* - extend business rules inside app.config.logic(app)
* - add custom UI behavior inside app.config.render(app)
* - add custom event bindings inside app.config.bind(app)
*/
const app = createApp({
config: {
id: 'gc-dapp-connect-with-dapp',
version: '0.0.1',
title: 'Cardano Dapp',
description: 'Review the action details below and continue in GameChanger Wallet.',
/**
* Default runtime values before persisted overrides are applied.
*
* These values also act as the reset source later on.
*
* When app version changes, the runtime can request a manual local
* state migration before replacing previously persisted data.
*/
defaults: {
options: {
network: "mainnet",
encoding: "gzip",
walletBaseUrl: "",
refAddress: undefined,
disableNetworkRouter: false,
usePopup: true,
useDebug: false,
useConnect: true,
useIntentSelect: true,
useThemeSelect: true,
useAction: true,
useQR: true,
useActionSection: true,
useOptions: true,
theme: 'dark',
popupFeatures: 'noopener,width=480,height=720',
manualResponse: ''
},
custom: {}
},
/**
* Field schema used to customize automatically generated controls.
*
* Useful examples:
* - change an inferred text field into a select field
* - add a custom button that reads or updates app state
* - add custom HTML blocks that consume app state
* - add a manual wallet response decoder for air-gapped QR flows
* - enable or disable URL, QR, and action-section controls by option flag
*/
ui: {
currentFields: {
options: {
network: { kind: 'select', options: [{ value: 'mainnet', label: 'Mainnet' }, { value: 'preprod', label: 'Preprod' }] },
encoding: { kind: 'select', options: [{ value: 'gzip', label: 'gzip' }, { value: 'base64url', label: 'base64url' }] },
theme: { kind: 'select', options: [{ value: 'dark', label: 'Dark' }, { value: 'light', label: 'Light' }] },
usePopup: { kind: 'checkbox' },
useDebug: { kind: 'checkbox' },
useConnect: { kind: 'checkbox' },
useIntentSelect: { kind: 'checkbox' },
useThemeSelect: { kind: 'checkbox' },
useAction: { kind: 'checkbox' },
useQR: { kind: 'checkbox' },
useActionSection: { kind: 'checkbox' },
useOptions: { kind: 'checkbox' },
disableNetworkRouter: { kind: 'checkbox' },
popupFeatures: { kind: 'text' },
walletBaseUrl: { kind: 'text' },
refAddress: { kind: 'text' },
manualResponse: { kind: 'textarea', full: true, label: 'Manual wallet response' },
manualResponseSubmit: {
kind: 'button',
label: 'Decode wallet response',
action: async ({ app }) => {
const responseUrl = text(app.options.manualResponse).trim();
if (!responseUrl) {
app.status = 'Paste a wallet URL response before decoding.';
app.ui.actionStatusLevel = 'warn';
return;
}
try {
const url = new URL(responseUrl);
const resultValue = url.searchParams.get('result');
if (!resultValue || !window.gc?.encodings?.msg?.decoder) return false;
await decodeWalletResultValue({ app, resultValue });
app.options.manualResponse = '';
app.status = 'Wallet response decoded successfully.';
app.ui.actionStatusLevel = 'success';
app.dirty = true;
} catch (error) {
app.status = error.message || 'Failed to decode wallet response';
app.ui.actionStatusLevel = 'err';
}
}
}
},
intents: {
// Intent UI customization examples:
// payment: {
// title: { kind: 'text' },
// message: { kind: 'textarea', full: true },
// 'return-URL': { kind: 'text' },
// 'to-address': { kind: 'text', full: true },
// 'policy-id': { kind: 'text' },
// 'asset-name': { kind: 'text' },
// decimals: { kind: 'number' },
// quantity: { kind: 'number' }
// },
// stakeDelegation: {
// ticker: { kind: 'text' },
// 'stake-pool': { kind: 'text', full: true }
// }
}
}
},
/**
* Read-only intent templates.
*
* Change only app.defaultIntents and the runtime will rebuild the live
* editable intents automatically.
*/
defaultIntents: {
// Uncomment the connect intent below to enable the most common wallet connection UX out of the box.
// Intent-based Cardano dapps do not require a mandatory wallet connection to work.
// connect: {
// "label": "Connect wallet",
// "description": "Share public wallet information with this dapp.",
// "code": {
// "type": "script",
// "title": "Connect with this dapp?",
// "description": "About to share public wallet information with the dapp.",
// "exportAs": "connect",
// "run": {
// "name": {
// "type": "getName"
// },
// "address": {
// "type": "getCurrentAddress"
// },
// "addressInfo": {
// "type": "macro",
// "run": "{getAddressInfo(get('cache.address'))}"
// }
// }
// }
// },
userIntent: {
"label": "🚀 Connect with dapp?",
"description": "About to share to the dapp your public wallet information and a CIP-8 signature to verify ownership",
"code": {
"type": "script",
"title": "🚀 Connect with dapp?",
"description": "About to share to the dapp your public wallet information and a CIP-8 signature to verify ownership",
"exportAs": "connect",
"return": {
"mode": "last"
},
"run": {
"data": {
"type": "script",
"run": {
"name": {
"type": "getName"
},
"address": {
"type": "getCurrentAddress"
},
"addressInfo": {
"type": "macro",
"run": "{getAddressInfo(get('cache.data.address'))}"
},
"agreement": {
"type": "macro",
"run": "{replaceAll('Myself, the user of wallet ADDRESS accepts to share all this information in order to connect with the dapp','ADDRESS',get('cache.data.address'))}"
},
"salt": {
"type": "macro",
"run": "{uuid()}"
}
}
},
"hash": {
"type": "macro",
"run": "{sha512(objToJson(get('cache.data')))}"
},
"sign": {
"type": "signDataWithAddress",
"address": "{get('cache.data.address')}",
"dataHex": "{get('cache.hash')}"
},
"finally": {
"type": "macro",
"run": {
"name": "{get('cache.data.name')}",
"address": "{get('cache.data.address')}",
"addressInfo": "{get('cache.data.addressInfo')}",
"signature": "{get('cache.sign')}",
"hash": "{get('cache.hash')}"
}
}
}
}
}
},
/**
* Example connected wallet normalizer.
*
* This helper is intentionally placed in the customization section
* because wallet identity shape can vary between flows.
*
* Return undefined when no connected wallet should be shown.
*/
normalizeConnectedWallet({ decoded, value }) {
const wallet = value || {};
const resultWallet = decoded?.wallet || decoded?.result?.wallet || decoded?.data?.wallet || {};
const connect = wallet?.connect || wallet || {};
const next = {
name: text(connect.name || resultWallet.name || decoded?.walletName),
type: text(connect.type || connect.walletType || resultWallet.type || decoded?.walletType || decoded?.type),
brand: text(connect.brand || connect.walletBrand || connect.subType || resultWallet.brand || resultWallet.subType || decoded?.walletBrand || decoded?.subType || decoded?.brand),
address: text(connect.address || resultWallet.address || decoded?.address)
};
return next.name || next.type || next.brand || next.address ? next : undefined;
},
/**
* Example transient wallet result handler.
*
* This hook runs exactly when a wallet result is captured from the URL
* or manually decoded from the options panel.
*
* Any intent result carrying a `connect` export can hydrate the
* connected wallet widget, regardless of which intent produced it.
* This keeps widget hydration based on transient results instead of
* using merged exports as a permanent source of truth.
*/
onResultCaptured({ app, result }) {
const connectExport = result?.exports?.connect;
if (!connectExport) return;
app.custom.connectedWallet = app.config.normalizeConnectedWallet({
decoded: result?.decoded,
value: connectExport
});
},
/**
* Example intent resolver.
*
* This is where example intent-specific transformations live.
* Replace, remove, or extend this function to fit the current set of
* intents. The runtime will stay generic.
*/
getIntentCode({ app, intentKey, code }) {
const next = clone(code);
const args = next.args || {};
if (next.exportAs || next.return) next.returnURLPattern = buildReturnUrl();
if (intentKey === 'connect' && app.custom.connectedWallet?.name) {
next.title = `Reconnect ${app.custom.connectedWallet.name}?`;
}
// Examples:
// if (intentKey === 'payment') {
// const connectedName = app.exports?.connect?.name || app.custom.connectedWallet?.name || '';
// if (app.options.network === 'preprod' && args['return-URL'] === 'https://cardanoscan.io/transaction/{txHash}') {
// args['return-URL'] = 'https://preprod.cardanoscan.io/transaction/{txHash}';
// }
// if (connectedName && !text(args.message).includes(connectedName)) {
// args.message = `${text(args.message)}\nRequested by ${connectedName}`.trim();
// }
// next.title = `Payment request: ${args.title || 'Untitled'}`;
// if (next.run?.build) next.run.build.title = `✅ ${args.title || 'Payment request'}`;
// }
// if (intentKey === 'stakeDelegation') {
// next.title = `Delegating to ${args.ticker || 'a stake pool'}`;
// if (next.run?.build) next.run.build.title = `✅ Delegate to ${args.ticker || 'a stake pool'}`;
// }
return next;
},
/**
* Custom business rules.
*
* This is the main place to derive UI state, summaries, custom state,
* and use-case-specific behavior from the current runtime values.
*/
logic(app) {
const key = app.ui.currentIntentKey;
const intent = app.intents[key] || {};
const code = intent.code || {};
const currentResult = app.result;
/* Consume transient wallet return data only once. */
if (currentResult) {
app.result = undefined;
}
app.ui.showDebug = !!app.options.useDebug;
app.ui.showIntentSelect = !!app.options.useIntentSelect && Object.keys(app.defaultIntents).length > 1;
app.ui.showThemeSelect = !!app.options.useThemeSelect;
app.ui.showAction = !!app.options.useAction;
app.ui.showQR = !!app.options.useQR;
app.ui.showOptionsToggle = !!app.options.useOptions;
app.ui.actionSectionDisabled = !app.options.useActionSection;
app.ui.hasArgs = !!Object.keys(code.args || {}).length;
app.ui.currentFields = inferFieldsFromJSON({
json: code.args || {},
fieldConfig: app.config.ui.currentFields?.intents?.[key] || {},
pathPrefix: ['intents', key, 'code', 'args']
});
app.ui.optionFields = inferFieldsFromJSON({
json: app.options,
fieldConfig: app.config.ui.currentFields?.options || {},
pathPrefix: ['options']
});
/**
* Example field validation rules.
*
* Use this area to validate current intent arguments and expose
* warnings or errors to the user. Blocking validations disable the
* main action button and the copy-link button.
*/
const validations = [];
// if (key === 'payment') {
// const quantity = Number(code.args?.quantity || 0);
// const address = text(code.args?.['to-address']);
// const returnUrl = text(code.args?.['return-URL']);
// if (!(quantity > 0)) validations.push({ level: 'err', blocking: true, message: 'Quantity must be greater than 0.' });
// if (address) {
// const expectedPrefix = app.options.network === 'mainnet' ? 'addr1' : 'addr_test1';
// if (!address.startsWith(expectedPrefix)) validations.push({ level: 'err', blocking: true, message: `Destination address must start with "${expectedPrefix}" for ${app.options.network}.` });
// }
// if (returnUrl && !/^https:\/\//.test(returnUrl)) validations.push({ level: 'warn', blocking: false, message: 'Return URL should usually use HTTPS.' });
// }
// if (key === 'stakeDelegation') {
// const ticker = text(code.args?.ticker);
// if (ticker && ticker.length < 3) validations.push({ level: 'warn', blocking: false, message: 'Ticker is usually at least 3 characters.' });
// }
app.ui.fieldStatus = validations[0]?.message || '';
app.ui.fieldStatusLevel = validations[0]?.level || '';
app.ui.actionDisabled = !!validations.find((item) => item.blocking) || !!app.ui.migrationNeeded;
app.ui.intentSummary = {
title: code.title || app.defaultIntents[key]?.label || 'Continue',
lead: code.description || app.defaultIntents[key]?.description || '',
sub: ''
};
},
/**
* Example custom UI renderer.
*
* The connected wallet widget is intentionally implemented here as a
* customization example.
*
* When enabled, the widget renders whenever a connected wallet exists
* or a default `connect` intent is available:
* - connected wallet present: show wallet chip even without a default
* `connect` intent
* - no connected wallet: only show the connect button when a default
* `connect` intent is available
*/
render(app) {
const widget = $('connect-widget');
const connectButton = $('connect-wallet-btn');
const connectedBox = $('connected-wallet');
if (!widget || !connectButton || !connectedBox) return;
const wallet = app.custom.connectedWallet;
const hasConnectIntent = !!app.defaultIntents.connect;
const enabled = !!app.options.useConnect && (!!wallet || hasConnectIntent);
widget.classList.toggle('hidden', !enabled);
connectButton.classList.toggle('hidden', !enabled || !!wallet || !hasConnectIntent);
connectedBox.classList.toggle('hidden', !enabled || !wallet);
if (!wallet) return;
$('connected-wallet-name').textContent = wallet.name || 'Connected wallet';
$('connected-wallet-sub').textContent = [wallet.type, wallet.brand].filter(Boolean).join(' · ');
$('connected-wallet-address').textContent = truncate({ value: wallet.address, start: 12, end: 10 });
},
/**
* Example custom event bindings.
*
* Add custom buttons or interactive widgets here when they are not part
* of the generic autogenerated runtime.
*/
bind(app) {
const connectButton = $('connect-wallet-btn');
const disconnectButton = $('disconnect-wallet-btn');
if (connectButton) {
connectButton.onclick = app.defaultIntents.connect
? () => app.openIntent({ intentKey: 'connect' })
: null;
}
if (disconnectButton) {
disconnectButton.onclick = () => {
app.custom.connectedWallet = undefined;
app.dirty = true;
};
}
}
}
});
/**
* Exposes the global reactive app proxy for direct customization.
*/
window.app = app;
/********************************************************************
* ADVANCED AUTOGENERATED RUNTIME
*
* The helpers below power persistence, rendering, encode/decode,
* and lifecycle behavior. They are shared runtime infrastructure and
* usually should not be altered in generated apps.
********************************************************************/
/** Returns a DOM element by its id. */
const $ = (id) => document.getElementById(id);
/** Converts any value into a safe string. */
const text = (value) => String(value ?? '');
/** Converts a label into a stable kebab-case fragment for DOM ids. */
const kebab = (value) => text(value).replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-|-$/g, '').toLowerCase();
/** Converts a state key into a human-friendly label. */
const labelize = (value) => text(value).replace(/[-_]+/g, ' ').replace(/\b\w/g, (match) => match.toUpperCase());
/** Checks whether a value is a plain object-like structure. */
function isObject(value) {
return !!value && typeof value === 'object' && !Array.isArray(value);
}
/** Deep-clones JSON-safe values used by the runtime state. */
function clone(value) {
return JSON.parse(JSON.stringify(value));
}
/** Deep-merges plain objects while replacing arrays and primitives. */
function merge({ base, extra }) {
if (!isObject(base)) return clone(extra);
const output = clone(base);
for (const [key, value] of Object.entries(extra || {})) {
output[key] = Array.isArray(value)
? clone(value)
: isObject(value) && isObject(output[key])
? merge({ base: output[key], extra: value })
: clone(value);
}
return output;
}
/** Writes a value into a nested path inside an object graph. */
function setPath({ root, path, value }) {
let ref = root;
path.slice(0, -1).forEach((key) => { ref = ref[key]; });
ref[path[path.length - 1]] = value;
}
/** Rewrites only the origin/base of a generated wallet URL. */
function replaceBaseUrl({ url, urlBase }) {
const base = new URL(urlBase);
const current = new URL(url, base);
const next = new URL(base.href);
next.pathname = current.pathname;
next.search = current.search;
next.hash = current.hash;
return next.toString();
}
/** Truncates any text value for compact UI display. */
function truncate({ value, start = 12, end = 10 }) {
const next = text(value);
return next.length > start + end ? `${next.slice(0, start)}…${next.slice(-end)}` : next;
}
/** Loads persisted app state from localStorage. */
function loadPersisted({ appId }) {
try {
return JSON.parse(localStorage.getItem(appId) || 'null');
} catch (_error) {
return null;
}
}
/** Persists the current runtime state. */
function savePersisted({ app }) {
if (app.ui?.migrationNeeded) return;
localStorage.setItem(app.id, JSON.stringify({
version: app.version,
options: app.options,
custom: app.custom,
exports: app.exports,
lastResult: app.lastResult,
ui: { currentIntentKey: app.ui.currentIntentKey },
intents: Object.fromEntries(Object.keys(app.intents).map((key) => [key, {
code: app.intents[key].code,
exports: app.intents[key].exports || {}
}]))
}));
}
/** Removes persisted runtime state for the current dapp. */
function clearPersisted({ app }) {
localStorage.removeItem(app.id);
}
/** Reconciles live runtime intents from the current default intents and overrides. */
function reconcileIntents({ app, sourceIntents = {} }) {
const nextIntents = {};
Object.entries(app.defaultIntents || {}).forEach(([key, intent]) => {
const current = sourceIntents[key] || {};
const code = merge({ base: intent.code || {}, extra: current.code || {} });
code.args = merge({ base: intent.code?.args || {}, extra: current.code?.args || {} });
nextIntents[key] = {
label: intent.label,
description: intent.description,
code,
exports: current.exports || app.intents?.[key]?.exports || {}
};
});
app.intents = nextIntents;
if (!app.defaultIntents[app.ui.currentIntentKey]) {
app.ui.currentIntentKey = Object.keys(app.defaultIntents)[0] || '';
}
}
/** Wraps an object graph in a reactive proxy that schedules updates on writes. */
function proxify({ value, onChange, cache }) {
if (!isObject(value) && !Array.isArray(value)) return value;
if (cache.has(value)) return cache.get(value);
const internalKeys = { muting: 1, queued: 1, rendering: 1, needsUpdate: 1 };
const proxy = new Proxy(value, {
get(target, key) {
const next = Reflect.get(target, key);
return (isObject(next) || Array.isArray(next)) ? proxify({ value: next, onChange, cache }) : next;
},
set(target, key, next) {
Reflect.set(target, key, next);
if (!internalKeys[key]) onChange();
return true;
},
deleteProperty(target, key) {
delete target[key];
if (!internalKeys[key]) onChange();
return true;
}
});
cache.set(value, proxy);
return proxy;
}
/** Schedules one update cycle for the app state proxy. */
function queueUpdate({ app }) {
if (!app || app.muting) return;
if (app.queued || app.rendering) {
app.needsUpdate = true;
return;
}
app.queued = true;
Promise.resolve().then(() => app.update());
}
/** Removes selected query parameters from the current browser history entry. */
function cleanLocationParams({ names }) {
const url = new URL(window.location.href);
let changed = false;
names.forEach((name) => {
if (url.searchParams.has(name)) {
url.searchParams.delete(name);
changed = true;
}
});
if (changed) window.history.replaceState({}, document.title, `${url.pathname}${url.search}${url.hash}`);
}
/** Detects the default control kind for a value when no field override exists. */
function inferFieldKind({ value }) {
return Array.isArray(value) || isObject(value)
? 'json'
: typeof value === 'boolean'
? 'checkbox'
: typeof value === 'number'
? 'number'
: 'text';
}
/** Parses raw DOM control data back into the right runtime value type. */
function parseFieldValue({ raw, kind }) {
if (kind === 'checkbox') return !!raw;
if (kind === 'number') {
const next = Number(raw);
return Number.isFinite(next) ? next : 0;
}
if (kind === 'json') {
const value = text(raw).trim();
return value ? JSON.parse(value) : {};
}
return text(raw);
}
/**
* Builds a raw field list from any JSON object and an optional field schema.
*
* This helper is implementation-agnostic and can be reused in other
* renderers such as React or server-side HTML builders.
*/
function inferFieldsFromJSON({ json = {}, fieldConfig = {}, pathPrefix = [] }) {
const fields = [];
Object.entries(json || {}).forEach(([name, value]) => {
const config = fieldConfig[name] || {};
fields.push({
name,
label: config.label || labelize(name),
kind: config.kind || inferFieldKind({ value }),
options: config.options || [],
placeholder: config.placeholder || '',
full: config.full === true || config.kind === 'json' || config.kind === 'textarea' || config.kind === 'html',
value,
path: [...pathPrefix, name],
onInput: config.onInput,
onChange: config.onChange,
action: config.action,
html: config.html || ''
});
});
Object.entries(fieldConfig || {}).forEach(([name, config]) => {
if (json[name] !== undefined || config.hidden) return;
fields.push({
name,
label: config.label || labelize(name),
kind: config.kind || 'button',
options: config.options || [],
placeholder: config.placeholder || '',
full: config.full === true,
value: config.value,
path: config.path || null,
onInput: config.onInput,
onChange: config.onChange,
action: config.action,
html: config.html || ''
});
});
return fields;
}
/** Creates one DOM control from a resolved field definition. */
function createControl({ app, field, formId }) {
const write = ({ raw, eventName }) => {
try {
const next = parseFieldValue({ raw, kind: field.kind });
if (field.path) setPath({ root: app, path: field.path, value: next });
if (field[eventName]) field[eventName]({ app, field, value: next });
app.dirty = true;
} catch (error) {
app.status = error.message || 'Invalid field value';
}
};
if (field.kind === 'button') {
const node = document.createElement('button');
node.type = 'button';
node.className = 'btn btn--ghost';
node.textContent = field.label;
node.onclick = () => field.action && field.action({ app, field });
return node;
}
if (field.kind === 'html') {
const node = document.createElement('div');
node.className = 'control';
node.innerHTML = field.html;
return node;
}
if (field.kind === 'checkbox') {
const row = document.createElement('label');
row.className = 'checkbox';
const input = document.createElement('input');
input.type = 'checkbox';
input.id = `${formId}-${kebab(field.name)}-input`;
input.checked = !!field.value;
input.onchange = (event) => write({ raw: event.target.checked, eventName: 'onChange' });
row.appendChild(input);
const span = document.createElement('span');
span.textContent = 'Enabled';
row.appendChild(span);
return row;
}
const input = document.createElement(
field.kind === 'textarea' || field.kind === 'json'
? 'textarea'
: field.kind === 'select'
? 'select'
: 'input'
);
input.id = `${formId}-${kebab(field.name)}-input`;
input.className = 'control';
if (field.placeholder) input.placeholder = field.placeholder;
if (field.kind === 'select') {
field.options.forEach((item) => {
const option = document.createElement('option');
option.value = item.value;
option.textContent = item.label;
option.selected = item.value === field.value;
input.appendChild(option);
});
input.onchange = (event) => write({ raw: event.target.value, eventName: 'onChange' });
return input;
}
if (field.kind !== 'textarea' && field.kind !== 'json') input.type = field.kind === 'number' ? 'number' : 'text';
input.value = field.kind === 'json'
? JSON.stringify(field.value || {}, null, 2)
: field.kind === 'number'
? String(field.value ?? 0)
: text(field.value);
input.oninput = (event) => {
write({ raw: event.target.value, eventName: 'onInput' });
};
input.onchange = (event) => {
write({ raw: event.target.value, eventName: 'onChange' });
};
return input;
}
/** Renders a list of resolved fields into a target container. */
function renderFields({ app, root, fields, formId }) {
const active = document.activeElement;
const focus = active && root.contains(active) && active.id
? { id: active.id, start: active.selectionStart, end: active.selectionEnd }
: null;
root.innerHTML = '';
fields.forEach((field) => {
const wrapper = document.createElement('div');
wrapper.className = 'field' + (field.full ? ' field--full' : '');
wrapper.id = `${formId}-${kebab(field.name)}-field`;
if (!['button', 'html'].includes(field.kind)) {
const title = document.createElement('label');
title.setAttribute('for', `${formId}-${kebab(field.name)}-input`);
title.textContent = field.label;
wrapper.appendChild(title);
}
wrapper.appendChild(createControl({ app, field, formId }));
root.appendChild(wrapper);
});
if (focus) {
const node = document.getElementById(focus.id);
if (node) {
try {
node.focus();
if (typeof node.setSelectionRange === 'function') {
node.setSelectionRange(focus.start, focus.end ?? focus.start);
}
} catch (_error) {}
}
}
}
/** Builds the clean return URL pattern used by wallet intents. */
function buildReturnUrl() {
const url = new URL(window.location.href);
return `${url.origin}${url.pathname}${url.hash}`;
}
/** Encodes one intent into a GameChanger wallet URL. */
async function buildIntentUrl({ app, intentKey }) {
if (!window.gc?.encode?.url) throw new Error('GameChanger library not loaded');
const source = clone(app.intents[intentKey]?.code || {});
const code = typeof app.config.getIntentCode === 'function'
? app.config.getIntentCode({ app, intentKey, code: source })
: source;
let url = await window.gc.encode.url({
input: JSON.stringify(code),
apiVersion: "2",
network: app.options.network,
encoding: app.options.encoding,
refAddress: app.options.refAddress || undefined,
disableNetworkRouter: !!app.options.disableNetworkRouter,
urlPattern: undefined
})
//.catch(err=>{console.error(err)});
if (app.options.walletBaseUrl) {
url = replaceBaseUrl({ url, urlBase: app.options.walletBaseUrl });
}
return url;
}
/** Encodes one intent into a QR payload. */
async function buildIntentQr({ app, intentKey, qrResultType }) {
const source = clone(app.intents[intentKey]?.code || {});
const code = typeof app.config.getIntentCode === 'function'
? app.config.getIntentCode({ app, intentKey, code: source })
: source;
return await window.gc.encode.qr({
input: JSON.stringify(code),
apiVersion: "2",
network: app.options.network,
encoding: app.options.encoding,
refAddress: app.options.refAddress || undefined,
disableNetworkRouter: !!app.options.disableNetworkRouter,
urlPattern: undefined,
qrResultType: qrResultType || 'png'
}).catch(err=>{console.error(err)});
}
/** Opens an encoded intent in a popup or in the current tab. */
async function openIntent({ app, intentKey }) {
const key = intentKey || app.ui.currentIntentKey;
const url = await buildIntentUrl({ app, intentKey: key });
if (!app.options.usePopup) {
window.location.href = url;
return url;
}
window.open(url, 'gc_udc_popup', app.options.popupFeatures || 'noopener,width=480,height=720');
return url;
}
/** Decodes one wallet response payload and merges its exports into app state. */
async function decodeWalletResultValue({ app, resultValue }) {
if (!resultValue || !window.gc?.encodings?.msg?.decoder) throw new Error('GameChanger decoder not loaded');