@nano133/nanoterra 0.9.0 → 0.9.3
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/CHANGELOG.md +40 -0
- package/README.md +55 -7
- package/ai/SPEC.md +6 -0
- package/dist/player-signin/panel/index.d.ts +2 -2
- package/dist/player-signin/panel/index.js +3 -2
- package/dist/player-signin/panel/mount.d.ts +1 -1
- package/dist/player-signin/panel/mount.js +5 -3
- package/dist/player-signin/panel/view.d.ts +3 -0
- package/dist/player-signin/panel/view.js +49 -46
- package/dist/player-signin/panel/words.d.ts +96 -1
- package/dist/player-signin/panel/words.js +109 -24
- package/dist/shop/panel/index.d.ts +2 -0
- package/dist/shop/panel/index.js +3 -0
- package/dist/shop/panel/looks.d.ts +3 -0
- package/dist/shop/panel/looks.js +11 -11
- package/dist/shop/panel/mount.d.ts +18 -2
- package/dist/shop/panel/mount.js +48 -21
- package/dist/shop/panel/pay.d.ts +3 -0
- package/dist/shop/panel/pay.js +38 -25
- package/dist/shop/panel/words.d.ts +89 -0
- package/dist/shop/panel/words.js +79 -0
- package/package.json +1 -1
- package/src/player-signin/panel/index.ts +4 -3
- package/src/player-signin/panel/mount.ts +6 -4
- package/src/player-signin/panel/style.css +22 -17
- package/src/player-signin/panel/view.ts +60 -55
- package/src/player-signin/panel/words.ts +202 -24
- package/src/shop/panel/index.ts +4 -0
- package/src/shop/panel/looks.ts +14 -14
- package/src/shop/panel/mount.ts +60 -21
- package/src/shop/panel/pay.ts +51 -30
- package/src/shop/panel/style.css +24 -20
- package/src/shop/panel/words.ts +172 -0
|
@@ -1,26 +1,111 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
// Every word of the sign-in sheet, and its words for each passkey fault, in plain English. A game gives `words` to `mountPlayerSignin` (or to
|
|
2
|
+
// `signInView`) with the keys it wants to change, in its own words or language; the rest stay these. A text with a value in it is a function of that
|
|
3
|
+
// value. The wallets' names (Berry Wallet, NanChat, Nautilus) are names, not words: they stay.
|
|
4
|
+
//
|
|
5
|
+
// The fault codes are @nano133/signin's (PasskeyFault). A fault never names a seed or a key, and never tells the player to delete a passkey. No
|
|
6
|
+
// sentence has more than 10 words.
|
|
7
|
+
export const PLAYER_SIGNIN_WORDS = {
|
|
8
|
+
title: "Sign in",
|
|
9
|
+
close: "Close",
|
|
10
|
+
lead: "No password and no payment.",
|
|
11
|
+
usePasskey: "Use a passkey",
|
|
12
|
+
passkeyHint: "Face ID, Touch ID or your device PIN",
|
|
13
|
+
passkeyOff: "Not on this browser",
|
|
14
|
+
lastUsed: "Last used",
|
|
15
|
+
orWallet: "Or a wallet app",
|
|
16
|
+
chooseWallet: "Choose your wallet",
|
|
17
|
+
orPasskey: "Or a passkey",
|
|
18
|
+
back: "Back",
|
|
19
|
+
passkeyTitle: "Passkey",
|
|
20
|
+
passkeyText: "Face ID, Touch ID or your device PIN. The passkey stays on your device. The game never sees it.",
|
|
21
|
+
useMine: "Use my passkey",
|
|
22
|
+
makeOne: "Make a passkey",
|
|
23
|
+
waitingPasskey: "Waiting for your passkey…",
|
|
24
|
+
makingPasskey: "Making your passkey…",
|
|
25
|
+
openingPasskey: "Opening your passkey…",
|
|
26
|
+
madeTitle: "Your passkey is made",
|
|
27
|
+
madeText: "Press the key to open it.",
|
|
28
|
+
openMine: "Open my passkey",
|
|
29
|
+
spareTitle: "Keep a spare key",
|
|
30
|
+
spareText: "Your looks belong to this passkey. If you lose it, this code brings them back.",
|
|
31
|
+
spareFine: "Keep it secret. Anyone with it can sign in as you. Import it as a seed in Nautilus or another wallet. Then sign in with that wallet.",
|
|
32
|
+
showCode: "Show my code",
|
|
33
|
+
copyCode: "Copy the code",
|
|
34
|
+
copied: "Copied",
|
|
35
|
+
copyFailed: "Copy failed: write it down",
|
|
36
|
+
later: "Later",
|
|
37
|
+
continue: "Continue",
|
|
38
|
+
signingIn: "Signing in…",
|
|
39
|
+
signInFailed: "Sign-in did not work. Try again.",
|
|
40
|
+
faultWallets: "Sign in with a wallet app",
|
|
41
|
+
faults: {
|
|
42
|
+
cancelled: { title: "No passkey was used", text: "No passkey was used." },
|
|
43
|
+
"no-prf": { title: "Not on this device yet", text: "This device's passkeys cannot sign in to games yet. Use a wallet app, or a passkey on another device." },
|
|
44
|
+
unsupported: { title: "No passkeys here", text: "This browser has no passkeys. Use a wallet app." },
|
|
45
|
+
"other-form": { title: "Not this password manager", text: "This game cannot read your password manager's answer. Choose iCloud Keychain or Google Password Manager instead. Or use a wallet app." },
|
|
46
|
+
"not-a-purse": { title: "Not this game's passkey", text: "That passkey is not one of this game's. Choose another one, or make one." },
|
|
47
|
+
"wrong-host": { title: "Wrong address", text: (rpId) => `Passkeys for this game work only on ${rpId}.` },
|
|
48
|
+
exists: { title: "You have a passkey", text: "This device has your passkey already. Use it." },
|
|
49
|
+
unstable: { title: "Not on this device", text: "This device gave two answers for one passkey. It cannot sign in here. Use a wallet app." },
|
|
50
|
+
"other-passkey": { title: "Another passkey", text: "That is another passkey. Choose the one you just made. Its name has today's date." },
|
|
51
|
+
failed: { title: "That did not work", text: "The passkey did not work. Try again." },
|
|
52
|
+
},
|
|
53
|
+
starting: "Starting…",
|
|
54
|
+
startFailed: "Sign-in did not start. Try again.",
|
|
55
|
+
refusal: (text) => text,
|
|
56
|
+
waitingFor: (wallet) => `Waiting for ${wallet}…`,
|
|
57
|
+
signedInAs: (address) => `Signed in as ${address}`,
|
|
58
|
+
openApp: (wallet) => `Open ${wallet}`,
|
|
59
|
+
anotherWallet: "Another wallet",
|
|
60
|
+
onComputer: "On this computer: ",
|
|
61
|
+
openLink: (wallet) => `open ${wallet}`,
|
|
62
|
+
aWallet: "a wallet",
|
|
63
|
+
openOnPhone: (wallet) => `Open this page on your phone to use ${wallet}.`,
|
|
64
|
+
qrLabel: (wallet) => `QR code to sign in with ${wallet}`,
|
|
65
|
+
onlyYours: (host) => `Only approve a sign-in you started yourself, on ${host}.`,
|
|
66
|
+
comeBack: (wallet) => `Approve the sign-in in ${wallet}. Then come back to this page.`,
|
|
67
|
+
yourWallet: "your wallet",
|
|
68
|
+
scanWith: (wallet) => `Scan this with ${wallet} on your phone. Then approve the sign-in.`,
|
|
69
|
+
scanCamera: (wallet) => `Scan this with your phone's camera to open ${wallet}. Then approve the sign-in.`,
|
|
70
|
+
checkCode: "Check that Nautilus shows this code: ",
|
|
71
|
+
tryAgain: "Try again",
|
|
72
|
+
otherWay: "Choose another way",
|
|
73
|
+
expired: "This sign-in expired.",
|
|
74
|
+
usedElsewhere: "This sign-in was used in another browser. Start again.",
|
|
75
|
+
tooManyChecks: "Too many checks. Waiting a moment…",
|
|
76
|
+
};
|
|
77
|
+
/** The game's words over the defaults; its faults over the default faults. A key it leaves out, or gives as undefined, keeps its default. */
|
|
78
|
+
export function playerSigninWords(over) {
|
|
79
|
+
const out = { ...PLAYER_SIGNIN_WORDS, faults: { ...PLAYER_SIGNIN_WORDS.faults } };
|
|
80
|
+
for (const [k, v] of Object.entries(over ?? {})) {
|
|
81
|
+
if (v === undefined || !(k in PLAYER_SIGNIN_WORDS))
|
|
82
|
+
continue;
|
|
83
|
+
if (k === "faults") {
|
|
84
|
+
for (const [code, f] of Object.entries(v))
|
|
85
|
+
if (f && code in out.faults)
|
|
86
|
+
out.faults[code] = f;
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
out[k] = v;
|
|
25
90
|
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
/** What happens after each fault: the passkey step again, or the wallet apps. Not words: the sheet's steps. */
|
|
94
|
+
const NEXT = {
|
|
95
|
+
cancelled: "stay",
|
|
96
|
+
"no-prf": "wallets",
|
|
97
|
+
unsupported: "wallets",
|
|
98
|
+
"other-form": "wallets",
|
|
99
|
+
"not-a-purse": "stay",
|
|
100
|
+
"wrong-host": "wallets",
|
|
101
|
+
exists: "stay",
|
|
102
|
+
unstable: "wallets",
|
|
103
|
+
"other-passkey": "stay",
|
|
104
|
+
failed: "stay",
|
|
105
|
+
};
|
|
106
|
+
/** A fault's title, text and next step, in the game's words (default: PLAYER_SIGNIN_WORDS). An unknown code gets the words of "failed". */
|
|
107
|
+
export function faultWords(code, rpId, words = PLAYER_SIGNIN_WORDS) {
|
|
108
|
+
const known = code in NEXT ? code : "failed";
|
|
109
|
+
const f = words.faults?.[known] ?? PLAYER_SIGNIN_WORDS.faults[known];
|
|
110
|
+
return { title: f.title, text: typeof f.text === "function" ? f.text(rpId) : f.text, next: NEXT[known] };
|
|
26
111
|
}
|
|
@@ -5,3 +5,5 @@ export type { LooksViewOptions, SlotWords } from "./looks.js";
|
|
|
5
5
|
export { PAY_TIMING, isTestOrder, payPanel } from "./pay.js";
|
|
6
6
|
export type { PayOptions, PayPanel } from "./pay.js";
|
|
7
7
|
export { qrModules, qrSvg, qrVersionFor } from "./qr.js";
|
|
8
|
+
export { COINGECKO_CREDIT, SHOP_WORDS, priceLine, shopWords } from "./words.js";
|
|
9
|
+
export type { ShopWords } from "./words.js";
|
package/dist/shop/panel/index.js
CHANGED
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
// import "@nano133/nanoterra/shop/style.css";
|
|
5
5
|
// const shop = mountShop(document.getElementById("shop")!, { looks, owned: () => me.owned, signedIn: () => !!me.address, signIn, worn, wear, onOwned });
|
|
6
6
|
//
|
|
7
|
+
// Every word of the two sheets can be the game's own: `mountShop(el, { ..., words: { sendExactly: "Pay exactly" } })` (ShopWords; SHOP_WORDS are the defaults).
|
|
8
|
+
//
|
|
7
9
|
// The server part is "@nano133/nanoterra/shop" (the handler and the stores): it must not load this one.
|
|
8
10
|
export { mountShop } from "./mount.js";
|
|
9
11
|
export { looksView, slotsOf } from "./looks.js";
|
|
10
12
|
export { PAY_TIMING, isTestOrder, payPanel } from "./pay.js";
|
|
11
13
|
export { qrModules, qrSvg, qrVersionFor } from "./qr.js";
|
|
14
|
+
export { COINGECKO_CREDIT, SHOP_WORDS, priceLine, shopWords } from "./words.js";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Look } from "../../looks/look.js";
|
|
2
|
+
import { type ShopWords } from "./words.js";
|
|
2
3
|
/** A tab's words: its key's word, and its plain choice's name (an item slot's: "Plain shovel", "No charm"). */
|
|
3
4
|
export type SlotWords = {
|
|
4
5
|
tab: string;
|
|
@@ -24,6 +25,8 @@ export type LooksViewOptions = {
|
|
|
24
25
|
tab?: string;
|
|
25
26
|
/** A tab was chosen: the sheet draws again with it. */
|
|
26
27
|
onTab?: (slot: string) => void;
|
|
28
|
+
/** The game's words (./words.ts): the keys it leaves out keep the defaults. */
|
|
29
|
+
words?: Partial<ShopWords>;
|
|
27
30
|
};
|
|
28
31
|
/** The wear slots of a list, in the order they first show (the outfits first). */
|
|
29
32
|
export declare function slotsOf(looks: readonly Look[]): string[];
|
package/dist/shop/panel/looks.js
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
// with `takeOff`, each item tab starts with its plain choice (free, "No charm").
|
|
6
6
|
import { h } from "../../admin/panel/dom.js";
|
|
7
7
|
import { OUTFIT, isOutfit, usdText, wearOf } from "../../looks/look.js";
|
|
8
|
-
|
|
9
|
-
const titleCase = (s) => s.charAt(0).toUpperCase() + s.slice(1).replace(/-/g, " ");
|
|
8
|
+
import { shopWords } from "./words.js";
|
|
10
9
|
/** The wear slots of a list, in the order they first show (the outfits first). */
|
|
11
10
|
export function slotsOf(looks) {
|
|
12
11
|
const out = [OUTFIT];
|
|
@@ -34,13 +33,14 @@ function swatchOf(look) {
|
|
|
34
33
|
export function looksView(p) {
|
|
35
34
|
const slots = slotsOf(p.looks);
|
|
36
35
|
const tab = p.tab && slots.includes(p.tab) ? p.tab : slots[0];
|
|
37
|
-
const
|
|
36
|
+
const w = shopWords(p.words);
|
|
37
|
+
const words = (slot) => p.slots?.[slot] ?? (slot === OUTFIT ? { tab: w.outfits } : { tab: w.slotTab(slot), plain: w.slotPlain(slot) });
|
|
38
38
|
const list = h("ul", { class: "n133s-looks" });
|
|
39
39
|
const row = (pic, name, line, action, worn) => h("li", { class: `n133s-look${worn ? " n133s-look-worn" : ""}` }, pic, h("span", { class: "n133s-look-text" }, h("strong", {}, name), h("small", {}, line)), action);
|
|
40
40
|
if (tab !== OUTFIT && p.takeOff) {
|
|
41
41
|
const plain = p.plainWorn ? p.plainWorn(tab) : !p.looks.some((l) => wearOf(l) === tab && p.worn(l));
|
|
42
|
-
const action = h("button", { class: `n133s-btn${plain ? "" : " n133s-primary"}`, type: "button", disabled: plain, onclick: () => p.takeOff(tab) }, plain ?
|
|
43
|
-
list.append(row(h("span", { class: "n133s-swatch n133s-swatch-plain", "aria-hidden": "true" }), words(tab).plain ??
|
|
42
|
+
const action = h("button", { class: `n133s-btn${plain ? "" : " n133s-primary"}`, type: "button", disabled: plain, onclick: () => p.takeOff(tab) }, plain ? w.wearing : w.wear);
|
|
43
|
+
list.append(row(h("span", { class: "n133s-swatch n133s-swatch-plain", "aria-hidden": "true" }), words(tab).plain ?? w.slotPlain(tab), w.free, action, plain));
|
|
44
44
|
}
|
|
45
45
|
for (const look of p.looks) {
|
|
46
46
|
if (wearOf(look) !== tab)
|
|
@@ -48,14 +48,14 @@ export function looksView(p) {
|
|
|
48
48
|
const mine = look.priceUsd === 0 || p.owned.has(look.id);
|
|
49
49
|
const worn = p.worn(look);
|
|
50
50
|
const action = mine
|
|
51
|
-
? h("button", { class: `n133s-btn${worn ? "" : " n133s-primary"}`, type: "button", disabled: worn, onclick: () => p.wear(look) }, worn ?
|
|
52
|
-
: h("button", { class: "n133s-btn n133s-buy", type: "button", onclick: () => p.buy(look) },
|
|
53
|
-
const what = isOutfit(look) ? (look.change.hat
|
|
54
|
-
const state = mine ?
|
|
51
|
+
? h("button", { class: `n133s-btn${worn ? "" : " n133s-primary"}`, type: "button", disabled: worn, onclick: () => p.wear(look) }, worn ? w.wearing : w.wear)
|
|
52
|
+
: h("button", { class: "n133s-btn n133s-buy", type: "button", onclick: () => p.buy(look) }, w.buy(usdText(look.priceUsd)));
|
|
53
|
+
const what = isOutfit(look) ? w.outfitLine(look.change.hat ?? null) : w.itemLine(tab);
|
|
54
|
+
const state = mine ? ` · ${look.priceUsd === 0 ? w.free : w.yours}` : "";
|
|
55
55
|
list.append(row(p.picture?.(look) ?? swatchOf(look), look.name, `${what}${state}`, action, worn));
|
|
56
56
|
}
|
|
57
57
|
const tabs = slots.length > 1
|
|
58
|
-
? h("div", { class: "n133s-tabs", role: "tablist", "aria-label":
|
|
58
|
+
? h("div", { class: "n133s-tabs", role: "tablist", "aria-label": w.kinds }, ...slots.map((s) => h("button", { class: "n133s-tab", type: "button", role: "tab", "aria-selected": s === tab ? "true" : "false", onclick: () => p.onTab?.(s) }, words(s).tab)))
|
|
59
59
|
: null;
|
|
60
|
-
return h("div", { class: "n133s-looks-view" }, tabs, list, h("p", { class: "n133s-fine" },
|
|
60
|
+
return h("div", { class: "n133s-looks-view" }, tabs, list, h("p", { class: "n133s-fine" }, w.looksNote), p.signedIn ? null : h("p", { class: "n133s-fine" }, w.signInFirst));
|
|
61
61
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Look } from "../../looks/look.js";
|
|
2
2
|
import { type SlotWords } from "./looks.js";
|
|
3
|
+
import { type ShopWords } from "./words.js";
|
|
3
4
|
export type ShopMountOptions = {
|
|
4
5
|
/** The game's looks (looks.json as it was read). The server decides every price; these are for the list. */
|
|
5
6
|
looks: unknown;
|
|
@@ -10,6 +11,16 @@ export type ShopMountOptions = {
|
|
|
10
11
|
signedIn(): boolean;
|
|
11
12
|
/** The game's sign-in: true when a player is signed in after it. With none, Buy asks the player to sign in and stops. */
|
|
12
13
|
signIn?: () => Promise<boolean>;
|
|
14
|
+
/**
|
|
15
|
+
* The game's own Buy (`buy(lookId)`) asked for a sign-in, and the player closed it without signing in: the game shows its own looks sheet again.
|
|
16
|
+
* The kit's list does not open then (the kit's sheet closes if it was open). A Buy in the kit's own list goes back to that list, as before.
|
|
17
|
+
*/
|
|
18
|
+
onSignInCancel?: (lookId: string, look: Look) => void;
|
|
19
|
+
/**
|
|
20
|
+
* The server refused an order with 401: the player's session ended, though `signedIn()` said yes. The game marks the player signed out. The sheet's
|
|
21
|
+
* "Sign in" key then calls `signIn()` without asking `signedIn()` first, so a stale "yes" cannot post the same refused order again.
|
|
22
|
+
*/
|
|
23
|
+
onSessionEnd?: () => void;
|
|
13
24
|
/** Whether the player wears this look now. */
|
|
14
25
|
worn(look: Look): boolean;
|
|
15
26
|
/** Wear a look the player owns. */
|
|
@@ -24,8 +35,10 @@ export type ShopMountOptions = {
|
|
|
24
35
|
picture?: (look: Look) => HTMLElement | null;
|
|
25
36
|
/** Words for the tabs of the wear slots. */
|
|
26
37
|
slots?: Record<string, SlotWords>;
|
|
27
|
-
/** The sheet's title. Default "Looks". */
|
|
38
|
+
/** The sheet's title. Default: `words.title` ("Looks"). */
|
|
28
39
|
title?: string;
|
|
40
|
+
/** The game's words for the two sheets, over the defaults (SHOP_WORDS): `{ buyTitle: (look) => look, sendExactly: "Pay exactly" }`. */
|
|
41
|
+
words?: Partial<ShopWords>;
|
|
29
42
|
/** Draw the Looks key. Default true; false: the game calls `open()` from its own key. */
|
|
30
43
|
key?: boolean;
|
|
31
44
|
/** "light", "dark", or "device" (the default): the page's `data-n133-theme` when it has one, else the device's setting. */
|
|
@@ -41,7 +54,10 @@ export type MountedShop = {
|
|
|
41
54
|
/** Opens the sheet on the looks. */
|
|
42
55
|
open(): void;
|
|
43
56
|
close(): void;
|
|
44
|
-
/**
|
|
57
|
+
/**
|
|
58
|
+
* Opens the sheet on Buy for one look (the game's own "Buy" elsewhere), on the next frame: close the game's own <dialog> first. A sign-in closed
|
|
59
|
+
* without a sign-in calls `onSignInCancel` and opens nothing.
|
|
60
|
+
*/
|
|
45
61
|
buy(lookId: string): void;
|
|
46
62
|
/** Draws the looks again (after the player signed in, or wore something). */
|
|
47
63
|
refresh(): void;
|
package/dist/shop/panel/mount.js
CHANGED
|
@@ -4,15 +4,21 @@
|
|
|
4
4
|
// owned() the looks the player owns (the game's GET /api/me gives them) signedIn() whether a player is signed in
|
|
5
5
|
// signIn() the game's own sign-in (the kit's sign-in path, or the game's): true when the player is signed in after it. The shop draws no sign-in.
|
|
6
6
|
// worn/wear what the player wears; `onOwned(lookId)` when a paid order gave a look (wear it)
|
|
7
|
+
// onSignInCancel(lookId) the game's own Buy (`buy(lookId)`) asked for a sign-in and the player closed it: the game shows its own sheet again
|
|
7
8
|
//
|
|
8
|
-
// `key: false` draws no key: the game opens the sheet from its own key with `open()`, as the options panel allows.
|
|
9
|
-
//
|
|
9
|
+
// `key: false` draws no key: the game opens the sheet from its own key with `open()`, as the options panel allows. `buy(lookId)` starts on the next frame:
|
|
10
|
+
// a game's own <dialog> that closed just before has had its `close` event by then (Chromium fires it at the frame), so its handler cannot take the focus.
|
|
11
|
+
// The sheet is a <dialog>: it rises from the bottom on a phone held upright and stands in the middle on a wide screen; on a phone held sideways the pay
|
|
12
|
+
// sheet puts the QR code beside the words. Phone first: text 16 px, every key 48 px or more each way.
|
|
13
|
+
//
|
|
14
|
+
// `words` changes any word of the two sheets (./words.ts: SHOP_WORDS are the defaults), for a game's own words or language.
|
|
10
15
|
import { ApiError, createApi } from "../../admin/panel/api.js";
|
|
11
16
|
import { h, releaseFocus } from "../../admin/panel/dom.js";
|
|
12
17
|
import { icon } from "../../admin/panel/icons.js";
|
|
13
18
|
import { checkLooks, wearOf } from "../../looks/look.js";
|
|
14
19
|
import { looksView, slotsOf } from "./looks.js";
|
|
15
20
|
import { payPanel } from "./pay.js";
|
|
21
|
+
import { shopWords } from "./words.js";
|
|
16
22
|
export function mountShop(root, options) {
|
|
17
23
|
const looks = checkLooks(options.looks);
|
|
18
24
|
const api = createApi(options.base ?? "/api/orders", options.fetch);
|
|
@@ -21,11 +27,13 @@ export function mountShop(root, options) {
|
|
|
21
27
|
let stopPay = null;
|
|
22
28
|
let destroyed = false;
|
|
23
29
|
const cleanup = [];
|
|
30
|
+
const words = shopWords(options.words);
|
|
31
|
+
const sheetTitle = options.title ?? words.title;
|
|
24
32
|
const title = h("h2", { class: "n133s-title", tabindex: "-1" });
|
|
25
|
-
const closeKey = h("button", { class: "n133s-close", type: "button", "aria-label":
|
|
33
|
+
const closeKey = h("button", { class: "n133s-close", type: "button", "aria-label": words.close }, icon("close", 20));
|
|
26
34
|
const body = h("div", { class: "n133s-body" });
|
|
27
|
-
const dialog = h("dialog", { class: "n133s-sheet", "aria-label":
|
|
28
|
-
const key = options.key === false ? null : h("button", { class: "n133s-key", type: "button", "aria-haspopup": "dialog" }, icon("shirt", 20), h("span", { class: "n133s-key-word" },
|
|
35
|
+
const dialog = h("dialog", { class: "n133s-sheet", "aria-label": sheetTitle }, h("header", { class: "n133s-head" }, title, closeKey), body);
|
|
36
|
+
const key = options.key === false ? null : h("button", { class: "n133s-key", type: "button", "aria-haspopup": "dialog" }, icon("shirt", 20), h("span", { class: "n133s-key-word" }, sheetTitle));
|
|
29
37
|
const wrap = h("div", { class: "n133-shop" }, key, dialog);
|
|
30
38
|
root.append(wrap);
|
|
31
39
|
// The theme: the game's word, or the page's (data-n133-theme), or the device's setting.
|
|
@@ -96,7 +104,7 @@ export function mountShop(root, options) {
|
|
|
96
104
|
function showLooks() {
|
|
97
105
|
if (destroyed)
|
|
98
106
|
return;
|
|
99
|
-
show(
|
|
107
|
+
show(sheetTitle, looksView({
|
|
100
108
|
looks,
|
|
101
109
|
owned: ownedNow(),
|
|
102
110
|
signedIn: options.signedIn(),
|
|
@@ -111,9 +119,10 @@ export function mountShop(root, options) {
|
|
|
111
119
|
showLooks();
|
|
112
120
|
}
|
|
113
121
|
: undefined,
|
|
114
|
-
buy: (l) => void buy(l),
|
|
122
|
+
buy: (l) => void buy(l, false),
|
|
115
123
|
picture: options.picture,
|
|
116
124
|
slots: options.slots,
|
|
125
|
+
words,
|
|
117
126
|
tab,
|
|
118
127
|
onTab: (s) => {
|
|
119
128
|
tab = s;
|
|
@@ -122,14 +131,18 @@ export function mountShop(root, options) {
|
|
|
122
131
|
},
|
|
123
132
|
}));
|
|
124
133
|
}
|
|
125
|
-
const back = (message, extra) => h("div", { class: "n133s-message" }, h("p", { class: "n133s-status" }, message), extra ?? null, h("button", { class: "n133s-btn n133s-wide", type: "button", onclick: () => showLooks() },
|
|
126
|
-
|
|
134
|
+
const back = (message, extra) => h("div", { class: "n133s-message" }, h("p", { class: "n133s-status" }, message), extra ?? null, h("button", { class: "n133s-btn n133s-wide", type: "button", onclick: () => showLooks() }, words.back));
|
|
135
|
+
/**
|
|
136
|
+
* `game`: the game's own Buy started it (`buy(lookId)`), not the kit's list: a closed sign-in goes back to the game, not to the list.
|
|
137
|
+
* `ended`: the server said the session ended (401): sign in again whatever `signedIn()` says.
|
|
138
|
+
*/
|
|
139
|
+
async function buy(look, game, ended = false) {
|
|
127
140
|
if (destroyed)
|
|
128
141
|
return;
|
|
129
142
|
tab = slotsOf(looks).length > 1 ? wearOf(look) : undefined;
|
|
130
|
-
if (!options.signedIn()) {
|
|
143
|
+
if (ended || !options.signedIn()) {
|
|
131
144
|
if (!options.signIn)
|
|
132
|
-
return show(
|
|
145
|
+
return show(words.buyTitle(look.name), back(words.signInFirst));
|
|
133
146
|
let ok = false;
|
|
134
147
|
try {
|
|
135
148
|
ok = await options.signIn();
|
|
@@ -137,11 +150,15 @@ export function mountShop(root, options) {
|
|
|
137
150
|
catch {
|
|
138
151
|
ok = false;
|
|
139
152
|
}
|
|
140
|
-
if (!ok || !options.signedIn())
|
|
141
|
-
|
|
153
|
+
if (!ok || !options.signedIn()) {
|
|
154
|
+
if (!game)
|
|
155
|
+
return showLooks();
|
|
156
|
+
close();
|
|
157
|
+
return options.onSignInCancel?.(look.id, look);
|
|
158
|
+
}
|
|
142
159
|
}
|
|
143
160
|
const box = h("div", { class: "n133s-turnstile", hidden: true });
|
|
144
|
-
show(
|
|
161
|
+
show(words.buyTitle(look.name), h("div", {}, h("p", { class: "n133s-status" }, words.making), box));
|
|
145
162
|
try {
|
|
146
163
|
const turnstile = options.personCheck ? await options.personCheck(box) : null;
|
|
147
164
|
const order = await api.post("", { lookId: look.id, turnstile });
|
|
@@ -150,19 +167,23 @@ export function mountShop(root, options) {
|
|
|
150
167
|
const pay = payPanel(order, {
|
|
151
168
|
lookName: look.name,
|
|
152
169
|
check: (id) => api.post(`/${id}/check`),
|
|
153
|
-
errorText: (e) => (e instanceof ApiError ? e.message : null),
|
|
170
|
+
errorText: (e) => (e instanceof ApiError ? words.refusal(e.message, e.status) : null),
|
|
171
|
+
words,
|
|
154
172
|
onPaid: () => {
|
|
155
173
|
bought.add(look.id);
|
|
156
174
|
options.onOwned?.(look.id, look);
|
|
157
175
|
},
|
|
158
176
|
});
|
|
159
|
-
show(
|
|
177
|
+
show(words.buyTitle(look.name), pay.node);
|
|
160
178
|
stopPay = pay.stop;
|
|
161
179
|
}
|
|
162
180
|
catch (e) {
|
|
163
|
-
const message = e instanceof ApiError ? e.message : e instanceof Error && e.message ? e.message :
|
|
164
|
-
const
|
|
165
|
-
|
|
181
|
+
const message = e instanceof ApiError ? words.refusal(e.message, e.status) : e instanceof Error && e.message ? words.refusal(e.message, 0) : words.orderFailed;
|
|
182
|
+
const gone = e instanceof ApiError && e.status === 401;
|
|
183
|
+
if (gone)
|
|
184
|
+
options.onSessionEnd?.();
|
|
185
|
+
const again = gone && options.signIn ? h("button", { class: "n133s-btn n133s-primary n133s-wide", type: "button", onclick: () => void buy(look, game, true) }, words.signIn) : null;
|
|
186
|
+
show(words.buyTitle(look.name), back(message, again));
|
|
166
187
|
}
|
|
167
188
|
}
|
|
168
189
|
return {
|
|
@@ -170,8 +191,14 @@ export function mountShop(root, options) {
|
|
|
170
191
|
close,
|
|
171
192
|
buy(lookId) {
|
|
172
193
|
const look = looks.find((l) => l.id === lookId);
|
|
173
|
-
|
|
174
|
-
|
|
194
|
+
// On the next frame (rAF; a hidden page has none): a <dialog> of the game's that closed just before has had its `close` event by then.
|
|
195
|
+
if (!look)
|
|
196
|
+
return;
|
|
197
|
+
const go = () => void buy(look, true);
|
|
198
|
+
if (typeof requestAnimationFrame === "function" && !globalThis.document?.hidden)
|
|
199
|
+
requestAnimationFrame(go);
|
|
200
|
+
else
|
|
201
|
+
setTimeout(go, 0);
|
|
175
202
|
},
|
|
176
203
|
refresh() {
|
|
177
204
|
if (isOpen() && body.querySelector(".n133s-looks-view"))
|
package/dist/shop/panel/pay.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PayView } from "../handler.js";
|
|
2
|
+
import { type ShopWords } from "./words.js";
|
|
2
3
|
export declare const PAY_TIMING: {
|
|
3
4
|
readonly pollMs: 5000;
|
|
4
5
|
readonly checkForMs: number;
|
|
@@ -14,6 +15,8 @@ export type PayOptions = {
|
|
|
14
15
|
errorText?(e: unknown): string | null;
|
|
15
16
|
/** The time now in ms (a test gives its own). */
|
|
16
17
|
now?: () => number;
|
|
18
|
+
/** The game's words (./words.ts): the keys it leaves out keep the defaults. */
|
|
19
|
+
words?: Partial<ShopWords>;
|
|
17
20
|
};
|
|
18
21
|
export type PayPanel = {
|
|
19
22
|
node: HTMLElement;
|
package/dist/shop/panel/pay.js
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
//
|
|
4
4
|
// TEST MODE: the server sends no address and no link, and this sheet shows a large "TEST MODE: DO NOT PAY" stamp where the QR code would be, with the
|
|
5
5
|
// wallet key off. Never change that: a payment to an address that nobody holds the key for is lost for good. The sheet decides it from the ORDER (its
|
|
6
|
-
// `test`, a missing `uri` or a missing `address`), never from a setting of the page.
|
|
7
|
-
import {
|
|
6
|
+
// `test`, a missing `uri` or a missing `address`), never from a setting of the page. The stamp's words are not among the game's words (./words.ts).
|
|
7
|
+
import { h } from "../../admin/panel/dom.js";
|
|
8
8
|
import { usdText } from "../../looks/look.js";
|
|
9
9
|
import { qrSvg } from "./qr.js";
|
|
10
|
+
import { priceLine, shopWords } from "./words.js";
|
|
10
11
|
export const PAY_TIMING = { pollMs: 5000, checkForMs: 2 * 60_000 };
|
|
11
12
|
/** True when this order must show the test stamp: the server said test mode, or it sent no address or no link. */
|
|
12
13
|
export const isTestOrder = (o) => o.test || !o.uri || !o.address;
|
|
@@ -17,27 +18,40 @@ export function payPanel(start, options) {
|
|
|
17
18
|
let timer;
|
|
18
19
|
let clockTimer;
|
|
19
20
|
let checkingUntil = 0;
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const
|
|
21
|
+
const w = shopWords(options.words);
|
|
22
|
+
const test = isTestOrder(order);
|
|
23
|
+
/** The order's state. In test mode nothing is checked, so it has nothing to say and takes no room. */
|
|
24
|
+
const status = h("p", { class: "n133s-status", role: "status", "aria-live": "polite", hidden: test });
|
|
25
|
+
const again = h("button", { class: "n133s-btn n133s-wide", type: "button", hidden: true }, w.checkAgain);
|
|
26
|
+
/** The time left, live only: in test mode nothing is paid, so nothing waits for the end. */
|
|
27
|
+
const ends = h("p", { class: "n133s-fine n133s-time-left", hidden: test });
|
|
28
|
+
const amount = h("div", { class: "n133s-amount" }, test ? null : h("span", { class: "n133s-exact" }, w.sendExactly), h("strong", {}, w.amount(order.xno)), h("span", {}, w.usd(usdText(Number(order.usd)))));
|
|
29
|
+
const copyKey = (value) => {
|
|
30
|
+
const key = h("button", { class: "n133s-btn n133s-small", type: "button" }, w.copy);
|
|
31
|
+
key.addEventListener("click", async () => {
|
|
32
|
+
try {
|
|
33
|
+
await navigator.clipboard.writeText(value);
|
|
34
|
+
key.textContent = w.copied;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
key.textContent = w.copyFailed;
|
|
38
|
+
}
|
|
39
|
+
setTimeout(() => (key.textContent = w.copy), 1500);
|
|
40
|
+
});
|
|
41
|
+
return key;
|
|
42
|
+
};
|
|
24
43
|
let payArea;
|
|
25
44
|
/** The main key (the wallet link; off in test mode): it stands in a foot that stays in view, so a phone on its side never hides it. */
|
|
26
45
|
let wallet;
|
|
27
|
-
const test = isTestOrder(order);
|
|
28
46
|
if (test) {
|
|
29
|
-
payArea = h("div", { class: "n133s-test-pay" }, h("div", { class: "n133s-qr n133s-qr-blocked", "aria-hidden": "true" }, h("div", { class: "n133s-qr-fake" })), h("div", { class: "n133s-stamp", role: "alert" }, h("span", {}, "TEST MODE:"), " ", h("span", {}, "DO NOT PAY")), h("p", { class: "n133s-fine" },
|
|
30
|
-
wallet = h("button", { class: "n133s-btn n133s-primary n133s-wide", type: "button", disabled: true },
|
|
47
|
+
payArea = h("div", { class: "n133s-test-pay" }, h("div", { class: "n133s-qr n133s-qr-blocked", "aria-hidden": "true" }, h("div", { class: "n133s-qr-fake" })), h("div", { class: "n133s-stamp", role: "alert" }, h("span", {}, "TEST MODE:"), " ", h("span", {}, "DO NOT PAY")), h("p", { class: "n133s-fine" }, w.testNote));
|
|
48
|
+
wallet = h("button", { class: "n133s-btn n133s-primary n133s-wide", type: "button", disabled: true }, w.walletOff);
|
|
31
49
|
}
|
|
32
50
|
else {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const copyAddress = h("button", { class: "n133s-btn n133s-small", type: "button" }, "Copy");
|
|
36
|
-
copyAddress.addEventListener("click", () => copy(order.address, copyAddress));
|
|
37
|
-
payArea = h("div", { class: "n133s-live-pay" }, h("div", { class: "n133s-qr" }, qrSvg(order.uri, `QR code to pay ${order.xno} XNO`)), h("details", { class: "n133s-by-hand" }, h("summary", {}, "Enter it by hand"), h("div", { class: "n133s-row" }, h("span", { class: "n133s-label" }, "Amount"), h("code", {}, `${order.xno} XNO`), copyAmount), h("div", { class: "n133s-row" }, h("span", { class: "n133s-label" }, "To"), h("code", { class: "n133s-address" }, order.address), copyAddress), h("p", { class: "n133s-fine" }, "Send exactly this amount, with every digit. Another amount does not match this order.")));
|
|
38
|
-
wallet = h("a", { class: "n133s-btn n133s-primary n133s-wide", href: order.uri }, "Open wallet");
|
|
51
|
+
payArea = h("div", { class: "n133s-live-pay" }, h("div", { class: "n133s-qr" }, qrSvg(order.uri, w.qrLabel(order.xno))), h("details", { class: "n133s-by-hand" }, h("summary", {}, w.byHand), h("div", { class: "n133s-row" }, h("span", { class: "n133s-label" }, w.amountLabel), h("code", {}, w.amount(order.xno)), copyKey(order.xno)), h("div", { class: "n133s-row" }, h("span", { class: "n133s-label" }, w.toLabel), h("code", { class: "n133s-address" }, order.address), copyKey(order.address)), h("p", { class: "n133s-fine" }, w.byHandNote)));
|
|
52
|
+
wallet = h("a", { class: "n133s-btn n133s-primary n133s-wide", href: order.uri }, w.wallet);
|
|
39
53
|
}
|
|
40
|
-
const node = h("div", { class: `n133s-pay${test ? " n133s-is-test" : ""}` }, h("div", { class: "n133s-pay-main" }, h("p", { class: "n133s-pay-what" },
|
|
54
|
+
const node = h("div", { class: `n133s-pay${test ? " n133s-is-test" : ""}` }, h("div", { class: "n133s-pay-main" }, h("p", { class: "n133s-pay-what" }, w.lookLine(options.lookName)), amount, payArea), h("div", { class: "n133s-pay-side" }, ends, status, again, h("p", { class: "n133s-fine n133s-prices" }, priceLine(w, order.prices)), h("div", { class: "n133s-foot" }, wallet)));
|
|
41
55
|
const stop = () => {
|
|
42
56
|
stopped = true;
|
|
43
57
|
if (timer)
|
|
@@ -50,7 +64,7 @@ export function payPanel(start, options) {
|
|
|
50
64
|
const ms = Math.max(0, order.expiresAt - now());
|
|
51
65
|
const m = Math.floor(ms / 60_000);
|
|
52
66
|
const s = Math.floor((ms % 60_000) / 1000);
|
|
53
|
-
|
|
67
|
+
ends.textContent = w.endsIn(`${m}:${String(s).padStart(2, "0")}`);
|
|
54
68
|
};
|
|
55
69
|
tick();
|
|
56
70
|
clockTimer = setInterval(tick, 1000);
|
|
@@ -58,7 +72,7 @@ export function payPanel(start, options) {
|
|
|
58
72
|
order = o;
|
|
59
73
|
if (o.status === "paid") {
|
|
60
74
|
stop();
|
|
61
|
-
payArea.replaceChildren(h("div", { class: "n133s-paid" }, h("strong", {},
|
|
75
|
+
payArea.replaceChildren(h("div", { class: "n133s-paid" }, h("strong", {}, w.paid), h("p", {}, w.paidLine(options.lookName))));
|
|
62
76
|
wallet.hidden = true;
|
|
63
77
|
status.textContent = "";
|
|
64
78
|
again.hidden = true;
|
|
@@ -67,13 +81,13 @@ export function payPanel(start, options) {
|
|
|
67
81
|
}
|
|
68
82
|
if (o.status === "paid_late") {
|
|
69
83
|
stop();
|
|
70
|
-
status.textContent =
|
|
84
|
+
status.textContent = w.paidLate;
|
|
71
85
|
again.hidden = true;
|
|
72
86
|
return true;
|
|
73
87
|
}
|
|
74
88
|
if (o.status === "expired") {
|
|
75
89
|
stop();
|
|
76
|
-
status.textContent =
|
|
90
|
+
status.textContent = w.expired;
|
|
77
91
|
again.hidden = false;
|
|
78
92
|
return false;
|
|
79
93
|
}
|
|
@@ -87,15 +101,15 @@ export function payPanel(start, options) {
|
|
|
87
101
|
if (show(o))
|
|
88
102
|
return;
|
|
89
103
|
if (o.status === "open")
|
|
90
|
-
status.textContent = test ? "
|
|
104
|
+
status.textContent = test ? "" : w.waiting;
|
|
91
105
|
}
|
|
92
106
|
catch (e) {
|
|
93
|
-
status.textContent = options.errorText?.(e) ??
|
|
107
|
+
status.textContent = options.errorText?.(e) ?? w.noConnection;
|
|
94
108
|
}
|
|
95
109
|
if (now() < checkingUntil)
|
|
96
110
|
timer = setTimeout(poll, PAY_TIMING.pollMs);
|
|
97
111
|
else if (!stopped) {
|
|
98
|
-
status.textContent =
|
|
112
|
+
status.textContent = w.stillWaiting;
|
|
99
113
|
again.hidden = false;
|
|
100
114
|
}
|
|
101
115
|
}
|
|
@@ -107,9 +121,8 @@ export function payPanel(start, options) {
|
|
|
107
121
|
void poll();
|
|
108
122
|
}
|
|
109
123
|
again.addEventListener("click", startChecking);
|
|
124
|
+
// Test mode makes no checks: nothing can be paid, so nothing is waited for.
|
|
110
125
|
if (!test)
|
|
111
126
|
startChecking();
|
|
112
|
-
else
|
|
113
|
-
status.textContent = "Test mode: the game does not wait for a payment.";
|
|
114
127
|
return { node, stop };
|
|
115
128
|
}
|