@medialane/ui 0.384.0 → 0.385.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/components/purchase-panel.cjs +237 -0
- package/dist/components/purchase-panel.cjs.map +1 -0
- package/dist/components/purchase-panel.d.cts +32 -0
- package/dist/components/purchase-panel.d.ts +32 -0
- package/dist/components/purchase-panel.js +201 -0
- package/dist/components/purchase-panel.js.map +1 -0
- package/dist/i18n/catalog/pt.cjs +10 -1
- package/dist/i18n/catalog/pt.cjs.map +1 -1
- package/dist/i18n/catalog/pt.js +10 -1
- package/dist/i18n/catalog/pt.js.map +1 -1
- package/dist/index.cjs +14 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/describe-error.cjs +14 -1
- package/dist/utils/describe-error.cjs.map +1 -1
- package/dist/utils/describe-error.d.cts +3 -1
- package/dist/utils/describe-error.d.ts +3 -1
- package/dist/utils/describe-error.js +12 -1
- package/dist/utils/describe-error.js.map +1 -1
- package/dist/utils/ipfs-gateway-fallback.cjs +9 -5
- package/dist/utils/ipfs-gateway-fallback.cjs.map +1 -1
- package/dist/utils/ipfs-gateway-fallback.d.cts +3 -1
- package/dist/utils/ipfs-gateway-fallback.d.ts +3 -1
- package/dist/utils/ipfs-gateway-fallback.js +9 -5
- package/dist/utils/ipfs-gateway-fallback.js.map +1 -1
- package/dist/utils/use-payment-options.cjs +65 -0
- package/dist/utils/use-payment-options.cjs.map +1 -0
- package/dist/utils/use-payment-options.d.cts +30 -0
- package/dist/utils/use-payment-options.d.ts +30 -0
- package/dist/utils/use-payment-options.js +39 -0
- package/dist/utils/use-payment-options.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var purchase_panel_exports = {};
|
|
31
|
+
__export(purchase_panel_exports, {
|
|
32
|
+
PurchasePanel: () => PurchasePanel,
|
|
33
|
+
amountText: () => amountText,
|
|
34
|
+
editionsAvailable: () => editionsAvailable
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(purchase_panel_exports);
|
|
37
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
38
|
+
var import_react = require("react");
|
|
39
|
+
var import_lucide_react = require("lucide-react");
|
|
40
|
+
var import_sdk = require("@medialane/sdk");
|
|
41
|
+
var import_image = __toESM(require("./image.js"), 1);
|
|
42
|
+
var import_alert = require("./alert.js");
|
|
43
|
+
var import_currency_icon = require("./currency-icon.js");
|
|
44
|
+
var import_cn = require("../utils/cn.js");
|
|
45
|
+
var import_format = require("../utils/format.js");
|
|
46
|
+
var import_use_usd_prices = require("../utils/use-usd-prices.js");
|
|
47
|
+
var import_use_payment_options = require("../utils/use-payment-options.js");
|
|
48
|
+
var import_provider = require("../i18n/provider.js");
|
|
49
|
+
var import_use_format = require("../i18n/use-format.js");
|
|
50
|
+
function amountText(raw, decimals) {
|
|
51
|
+
const [whole, frac = ""] = (0, import_sdk.formatAmount)(raw.toString(), decimals).split(".");
|
|
52
|
+
const lead = whole === "0" ? frac.match(/^0*/)?.[0].length ?? 0 : 0;
|
|
53
|
+
const shown = frac.slice(0, lead + 4).replace(/0+$/, "");
|
|
54
|
+
return shown ? `${whole}.${shown}` : whole;
|
|
55
|
+
}
|
|
56
|
+
function editionsAvailable(order) {
|
|
57
|
+
if (order.offer.itemType !== "ERC1155") return null;
|
|
58
|
+
return Math.max(1, parseInt(order.remainingAmount ?? order.offer.startAmount ?? "1", 10));
|
|
59
|
+
}
|
|
60
|
+
function PurchasePanel({
|
|
61
|
+
order,
|
|
62
|
+
image,
|
|
63
|
+
quantity,
|
|
64
|
+
onQuantityChange,
|
|
65
|
+
walletAddress,
|
|
66
|
+
payWith,
|
|
67
|
+
onPayWithChange,
|
|
68
|
+
onAddFunds,
|
|
69
|
+
error,
|
|
70
|
+
children
|
|
71
|
+
}) {
|
|
72
|
+
const name = order.token?.name || `Token #${order.nftTokenId}`;
|
|
73
|
+
const price = order.price;
|
|
74
|
+
const currency = price?.currency ?? null;
|
|
75
|
+
const available = editionsAvailable(order);
|
|
76
|
+
const { cost, options, isLoading } = (0, import_use_payment_options.usePaymentOptions)({ order, quantity, walletAddress });
|
|
77
|
+
const picked = isLoading ? payWith : (0, import_use_payment_options.pickPayment)(options, payWith);
|
|
78
|
+
(0, import_react.useEffect)(() => {
|
|
79
|
+
if (picked !== payWith) onPayWithChange(picked);
|
|
80
|
+
}, [picked, payWith, onPayWithChange]);
|
|
81
|
+
const paying = options.find((o) => o.symbol === payWith) ?? null;
|
|
82
|
+
const totalSymbol = paying?.symbol ?? currency;
|
|
83
|
+
const totalRaw = paying ? paying.cost : cost.total;
|
|
84
|
+
const totalDecimals = paying?.decimals ?? price?.decimals ?? 18;
|
|
85
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-5 p-5", children: [
|
|
86
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center gap-3.5 pr-8", children: [
|
|
87
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "relative h-14 w-14 shrink-0 overflow-hidden rounded-xl bg-muted", children: image ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image.default, { src: image, alt: name, fill: true, sizes: "56px", className: "object-cover", unoptimized: true }) : null }),
|
|
88
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "min-w-0", children: [
|
|
89
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "truncate text-base font-semibold leading-tight", children: name }),
|
|
90
|
+
price?.formatted && currency ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "mt-1 flex items-center gap-1.5 text-sm text-muted-foreground tabular-nums", children: [
|
|
91
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_currency_icon.CurrencyIcon, { symbol: currency, size: 12 }),
|
|
92
|
+
(0, import_format.formatDisplayPrice)(price.formatted),
|
|
93
|
+
" ",
|
|
94
|
+
currency
|
|
95
|
+
] }) : null
|
|
96
|
+
] })
|
|
97
|
+
] }),
|
|
98
|
+
available !== null && available > 1 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(QuantityField, { value: quantity, max: available, onChange: onQuantityChange }) : null,
|
|
99
|
+
walletAddress && currency ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
100
|
+
PayWith,
|
|
101
|
+
{
|
|
102
|
+
options,
|
|
103
|
+
isLoading,
|
|
104
|
+
selected: payWith,
|
|
105
|
+
onSelect: onPayWithChange,
|
|
106
|
+
onAddFunds
|
|
107
|
+
}
|
|
108
|
+
) : null,
|
|
109
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(TotalLine, { symbol: totalSymbol, raw: totalRaw, decimals: totalDecimals, feeBps: cost.feeBps }),
|
|
110
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-3", children: [
|
|
111
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_alert.Alert, { variant: "destructive", children: [
|
|
112
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.AlertCircle, { className: "h-4 w-4" }),
|
|
113
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertDescription, { children: error })
|
|
114
|
+
] }) : null,
|
|
115
|
+
children
|
|
116
|
+
] })
|
|
117
|
+
] });
|
|
118
|
+
}
|
|
119
|
+
function QuantityField({ value, max, onChange }) {
|
|
120
|
+
const t = (0, import_provider.useT)();
|
|
121
|
+
const format = (0, import_use_format.useFormat)();
|
|
122
|
+
const [draft, setDraft] = (0, import_react.useState)(String(value));
|
|
123
|
+
(0, import_react.useEffect)(() => setDraft(String(value)), [value]);
|
|
124
|
+
const clamp = (n) => Math.max(1, Math.min(max, Number.isFinite(n) ? Math.floor(n) : 1));
|
|
125
|
+
const commit = () => onChange(clamp(parseInt(draft, 10)));
|
|
126
|
+
const step = "grid h-10 w-10 place-items-center text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-xl";
|
|
127
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center justify-between gap-4", children: [
|
|
128
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
129
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm font-medium", children: t("Quantity") }),
|
|
130
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-xs text-muted-foreground tabular-nums", children: t("{count} available", { count: format.number(max) }) })
|
|
131
|
+
] }),
|
|
132
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center rounded-xl border border-border", children: [
|
|
133
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: step, disabled: value <= 1, onClick: () => onChange(clamp(value - 1)), "aria-label": t("Decrease quantity"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Minus, { className: "h-4 w-4" }) }),
|
|
134
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
135
|
+
"input",
|
|
136
|
+
{
|
|
137
|
+
inputMode: "numeric",
|
|
138
|
+
"aria-label": t("Quantity"),
|
|
139
|
+
value: draft,
|
|
140
|
+
onChange: (e) => setDraft(e.target.value.replace(/\D/g, "")),
|
|
141
|
+
onBlur: commit,
|
|
142
|
+
onKeyDown: (e) => {
|
|
143
|
+
if (e.key === "Enter") commit();
|
|
144
|
+
},
|
|
145
|
+
className: "h-10 w-14 bg-transparent text-center text-base font-semibold tabular-nums outline-none"
|
|
146
|
+
}
|
|
147
|
+
),
|
|
148
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: step, disabled: value >= max, onClick: () => onChange(clamp(value + 1)), "aria-label": t("Increase quantity"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Plus, { className: "h-4 w-4" }) })
|
|
149
|
+
] })
|
|
150
|
+
] });
|
|
151
|
+
}
|
|
152
|
+
function PayWith({
|
|
153
|
+
options,
|
|
154
|
+
isLoading,
|
|
155
|
+
selected,
|
|
156
|
+
onSelect,
|
|
157
|
+
onAddFunds
|
|
158
|
+
}) {
|
|
159
|
+
const t = (0, import_provider.useT)();
|
|
160
|
+
const nothingCovers = !isLoading && !options.some((o) => o.covers);
|
|
161
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex flex-col gap-2", children: [
|
|
162
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm font-medium", children: t("Pay with") }),
|
|
163
|
+
isLoading && options.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex h-14 items-center justify-center gap-2 rounded-xl border border-border text-xs text-muted-foreground", children: [
|
|
164
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Loader2, { className: "h-3.5 w-3.5 animate-spin" }),
|
|
165
|
+
t("Checking your balances\u2026")
|
|
166
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "grid grid-cols-2 gap-2", role: "radiogroup", "aria-label": t("Pay with"), children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
167
|
+
CoinChoice,
|
|
168
|
+
{
|
|
169
|
+
option,
|
|
170
|
+
quoting: isLoading && option.cost === null,
|
|
171
|
+
selected: selected === option.symbol,
|
|
172
|
+
onSelect: () => onSelect(option.symbol)
|
|
173
|
+
},
|
|
174
|
+
option.symbol
|
|
175
|
+
)) }),
|
|
176
|
+
nothingCovers ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "text-xs text-muted-foreground", children: [
|
|
177
|
+
t("Add funds to your wallet to buy this."),
|
|
178
|
+
" ",
|
|
179
|
+
onAddFunds ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: onAddFunds, className: "font-semibold text-primary hover:underline", children: t("Add funds") }) : null
|
|
180
|
+
] }) : null
|
|
181
|
+
] });
|
|
182
|
+
}
|
|
183
|
+
function CoinChoice({ option, quoting, selected, onSelect }) {
|
|
184
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
185
|
+
"button",
|
|
186
|
+
{
|
|
187
|
+
type: "button",
|
|
188
|
+
role: "radio",
|
|
189
|
+
"aria-checked": selected,
|
|
190
|
+
disabled: !option.covers,
|
|
191
|
+
onClick: onSelect,
|
|
192
|
+
className: (0, import_cn.cn)(
|
|
193
|
+
"flex items-center gap-2.5 rounded-xl border px-3 py-2.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
194
|
+
selected ? "border-primary bg-primary/[0.06]" : "border-border hover:bg-muted/40",
|
|
195
|
+
!option.covers && "opacity-45"
|
|
196
|
+
),
|
|
197
|
+
children: [
|
|
198
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_currency_icon.CurrencyIcon, { symbol: option.symbol, size: 20, className: "shrink-0" }),
|
|
199
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "min-w-0 flex-1", children: [
|
|
200
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "block text-sm font-semibold leading-tight", children: option.symbol }),
|
|
201
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "block truncate text-xs text-muted-foreground tabular-nums", children: amountText(option.balance, option.decimals) })
|
|
202
|
+
] }),
|
|
203
|
+
quoting ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Loader2, { className: "h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground" }) : selected ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Check, { className: "h-4 w-4 shrink-0 text-primary" }) : null
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
function TotalLine({ symbol, raw, decimals, feeBps }) {
|
|
209
|
+
const t = (0, import_provider.useT)();
|
|
210
|
+
const prices = (0, import_use_usd_prices.useUsdPrices)();
|
|
211
|
+
const text = raw !== null ? amountText(raw, decimals) : null;
|
|
212
|
+
const usd = text && symbol && !(0, import_format.isStableCurrency)(symbol) ? (0, import_use_usd_prices.usdValueFor)(text, symbol, prices) : null;
|
|
213
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-start justify-between gap-4 border-t border-border pt-4", children: [
|
|
214
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
215
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-sm font-medium", children: t("Total") }),
|
|
216
|
+
feeBps > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "text-xs text-muted-foreground", children: t("Includes {percent}% platform fee", { percent: String(feeBps / 100) }) }) : null
|
|
217
|
+
] }),
|
|
218
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "text-right", children: [
|
|
219
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "flex items-center justify-end gap-2 font-[family-name:var(--font-display)] text-2xl font-extrabold tracking-tight tabular-nums", children: [
|
|
220
|
+
symbol ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_currency_icon.CurrencyIcon, { symbol, size: 18 }) : null,
|
|
221
|
+
text ?? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.Loader2, { className: "h-5 w-5 animate-spin text-muted-foreground" }),
|
|
222
|
+
text && symbol ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-base font-bold text-muted-foreground", children: symbol }) : null
|
|
223
|
+
] }),
|
|
224
|
+
usd ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "text-xs text-muted-foreground tabular-nums", children: [
|
|
225
|
+
"\u2248 ",
|
|
226
|
+
usd
|
|
227
|
+
] }) : null
|
|
228
|
+
] })
|
|
229
|
+
] });
|
|
230
|
+
}
|
|
231
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
232
|
+
0 && (module.exports = {
|
|
233
|
+
PurchasePanel,
|
|
234
|
+
amountText,
|
|
235
|
+
editionsAvailable
|
|
236
|
+
});
|
|
237
|
+
//# sourceMappingURL=purchase-panel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/purchase-panel.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useState, type ReactNode } from \"react\";\nimport { AlertCircle, Check, Loader2, Minus, Plus } from \"lucide-react\";\nimport { formatAmount, type ApiOrder } from \"@medialane/sdk\";\nimport Image from \"./image.js\";\nimport { Alert, AlertDescription } from \"./alert.js\";\nimport { CurrencyIcon } from \"./currency-icon.js\";\nimport { cn } from \"../utils/cn.js\";\nimport { formatDisplayPrice, isStableCurrency } from \"../utils/format.js\";\nimport { useUsdPrices, usdValueFor } from \"../utils/use-usd-prices.js\";\nimport { pickPayment, usePaymentOptions, type PaymentOption } from \"../utils/use-payment-options.js\";\nimport { useT } from \"../i18n/provider.js\";\nimport { useFormat } from \"../i18n/use-format.js\";\n\n/** A raw amount as text: four decimals, or four significant digits below one. */\nexport function amountText(raw: bigint, decimals: number): string {\n const [whole, frac = \"\"] = formatAmount(raw.toString(), decimals).split(\".\");\n const lead = whole === \"0\" ? (frac.match(/^0*/)?.[0].length ?? 0) : 0;\n const shown = frac.slice(0, lead + 4).replace(/0+$/, \"\");\n return shown ? `${whole}.${shown}` : whole;\n}\n\nexport interface PurchasePanelProps {\n order: ApiOrder;\n /** The asset image, resolved by the app. */\n image?: string | null;\n quantity: number;\n onQuantityChange: (quantity: number) => void;\n /** The buyer's wallet; without one the coins are not listed. */\n walletAddress: string | null;\n payWith: string | null;\n onPayWithChange: (symbol: string | null) => void;\n /** Opens a way to add funds when no coin covers the purchase. */\n onAddFunds?: () => void;\n error?: string | null;\n /** The action area: the Buy button, or what replaces it. */\n children: ReactNode;\n}\n\n/** Editions left to buy from an ERC-1155 listing; null for ERC-721. */\nexport function editionsAvailable(order: ApiOrder): number | null {\n if (order.offer.itemType !== \"ERC1155\") return null;\n return Math.max(1, parseInt(order.remainingAmount ?? order.offer.startAmount ?? \"1\", 10));\n}\n\n/**\n * The body of a purchase: what is bought, how many, which coin pays and the total, with the cost\n * the app's client builds the purchase with. Each app passes its own action in `children`; the\n * panel does not buy anything itself.\n */\nexport function PurchasePanel({\n order,\n image,\n quantity,\n onQuantityChange,\n walletAddress,\n payWith,\n onPayWithChange,\n onAddFunds,\n error,\n children,\n}: PurchasePanelProps) {\n const name = order.token?.name || `Token #${order.nftTokenId}`;\n const price = order.price;\n const currency = price?.currency ?? null;\n const available = editionsAvailable(order);\n const { cost, options, isLoading } = usePaymentOptions({ order, quantity, walletAddress });\n\n const picked = isLoading ? payWith : pickPayment(options, payWith);\n useEffect(() => {\n if (picked !== payWith) onPayWithChange(picked);\n }, [picked, payWith, onPayWithChange]);\n\n const paying = options.find((o) => o.symbol === payWith) ?? null;\n const totalSymbol = paying?.symbol ?? currency;\n const totalRaw = paying ? paying.cost : cost.total;\n const totalDecimals = paying?.decimals ?? price?.decimals ?? 18;\n\n return (\n <div className=\"flex flex-col gap-5 p-5\">\n <div className=\"flex items-center gap-3.5 pr-8\">\n <div className=\"relative h-14 w-14 shrink-0 overflow-hidden rounded-xl bg-muted\">\n {image ? <Image src={image} alt={name} fill sizes=\"56px\" className=\"object-cover\" unoptimized /> : null}\n </div>\n <div className=\"min-w-0\">\n <p className=\"truncate text-base font-semibold leading-tight\">{name}</p>\n {price?.formatted && currency ? (\n <p className=\"mt-1 flex items-center gap-1.5 text-sm text-muted-foreground tabular-nums\">\n <CurrencyIcon symbol={currency} size={12} />\n {formatDisplayPrice(price.formatted)} {currency}\n </p>\n ) : null}\n </div>\n </div>\n\n {available !== null && available > 1 ? (\n <QuantityField value={quantity} max={available} onChange={onQuantityChange} />\n ) : null}\n\n {walletAddress && currency ? (\n <PayWith\n options={options}\n isLoading={isLoading}\n selected={payWith}\n onSelect={onPayWithChange}\n onAddFunds={onAddFunds}\n />\n ) : null}\n\n <TotalLine symbol={totalSymbol} raw={totalRaw} decimals={totalDecimals} feeBps={cost.feeBps} />\n\n <div className=\"flex flex-col gap-3\">\n {error ? (\n <Alert variant=\"destructive\">\n <AlertCircle className=\"h-4 w-4\" />\n <AlertDescription>{error}</AlertDescription>\n </Alert>\n ) : null}\n {children}\n </div>\n </div>\n );\n}\n\nfunction QuantityField({ value, max, onChange }: { value: number; max: number; onChange: (value: number) => void }) {\n const t = useT();\n const format = useFormat();\n const [draft, setDraft] = useState(String(value));\n useEffect(() => setDraft(String(value)), [value]);\n const clamp = (n: number) => Math.max(1, Math.min(max, Number.isFinite(n) ? Math.floor(n) : 1));\n const commit = () => onChange(clamp(parseInt(draft, 10)));\n const step = \"grid h-10 w-10 place-items-center text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-xl\";\n\n return (\n <div className=\"flex items-center justify-between gap-4\">\n <div>\n <p className=\"text-sm font-medium\">{t(\"Quantity\")}</p>\n <p className=\"text-xs text-muted-foreground tabular-nums\">{t(\"{count} available\", { count: format.number(max) })}</p>\n </div>\n <div className=\"flex items-center rounded-xl border border-border\">\n <button type=\"button\" className={step} disabled={value <= 1} onClick={() => onChange(clamp(value - 1))} aria-label={t(\"Decrease quantity\")}>\n <Minus className=\"h-4 w-4\" />\n </button>\n <input\n inputMode=\"numeric\"\n aria-label={t(\"Quantity\")}\n value={draft}\n onChange={(e) => setDraft(e.target.value.replace(/\\D/g, \"\"))}\n onBlur={commit}\n onKeyDown={(e) => { if (e.key === \"Enter\") commit(); }}\n className=\"h-10 w-14 bg-transparent text-center text-base font-semibold tabular-nums outline-none\"\n />\n <button type=\"button\" className={step} disabled={value >= max} onClick={() => onChange(clamp(value + 1))} aria-label={t(\"Increase quantity\")}>\n <Plus className=\"h-4 w-4\" />\n </button>\n </div>\n </div>\n );\n}\n\nfunction PayWith({\n options,\n isLoading,\n selected,\n onSelect,\n onAddFunds,\n}: {\n options: PaymentOption[];\n isLoading: boolean;\n selected: string | null;\n onSelect: (symbol: string) => void;\n onAddFunds?: () => void;\n}) {\n const t = useT();\n const nothingCovers = !isLoading && !options.some((o) => o.covers);\n\n return (\n <div className=\"flex flex-col gap-2\">\n <p className=\"text-sm font-medium\">{t(\"Pay with\")}</p>\n {isLoading && options.length === 0 ? (\n <div className=\"flex h-14 items-center justify-center gap-2 rounded-xl border border-border text-xs text-muted-foreground\">\n <Loader2 className=\"h-3.5 w-3.5 animate-spin\" />\n {t(\"Checking your balances…\")}\n </div>\n ) : (\n <div className=\"grid grid-cols-2 gap-2\" role=\"radiogroup\" aria-label={t(\"Pay with\")}>\n {options.map((option) => (\n <CoinChoice\n key={option.symbol}\n option={option}\n quoting={isLoading && option.cost === null}\n selected={selected === option.symbol}\n onSelect={() => onSelect(option.symbol)}\n />\n ))}\n </div>\n )}\n {nothingCovers ? (\n <p className=\"text-xs text-muted-foreground\">\n {t(\"Add funds to your wallet to buy this.\")}{\" \"}\n {onAddFunds ? (\n <button type=\"button\" onClick={onAddFunds} className=\"font-semibold text-primary hover:underline\">\n {t(\"Add funds\")}\n </button>\n ) : null}\n </p>\n ) : null}\n </div>\n );\n}\n\nfunction CoinChoice({ option, quoting, selected, onSelect }: { option: PaymentOption; quoting: boolean; selected: boolean; onSelect: () => void }) {\n return (\n <button\n type=\"button\"\n role=\"radio\"\n aria-checked={selected}\n disabled={!option.covers}\n onClick={onSelect}\n className={cn(\n \"flex items-center gap-2.5 rounded-xl border px-3 py-2.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n selected ? \"border-primary bg-primary/[0.06]\" : \"border-border hover:bg-muted/40\",\n !option.covers && \"opacity-45\",\n )}\n >\n <CurrencyIcon symbol={option.symbol} size={20} className=\"shrink-0\" />\n <span className=\"min-w-0 flex-1\">\n <span className=\"block text-sm font-semibold leading-tight\">{option.symbol}</span>\n <span className=\"block truncate text-xs text-muted-foreground tabular-nums\">{amountText(option.balance, option.decimals)}</span>\n </span>\n {quoting ? (\n <Loader2 className=\"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground\" />\n ) : selected ? (\n <Check className=\"h-4 w-4 shrink-0 text-primary\" />\n ) : null}\n </button>\n );\n}\n\nfunction TotalLine({ symbol, raw, decimals, feeBps }: { symbol: string | null; raw: bigint | null; decimals: number; feeBps: number }) {\n const t = useT();\n const prices = useUsdPrices();\n const text = raw !== null ? amountText(raw, decimals) : null;\n const usd = text && symbol && !isStableCurrency(symbol) ? usdValueFor(text, symbol, prices) : null;\n\n return (\n <div className=\"flex items-start justify-between gap-4 border-t border-border pt-4\">\n <div>\n <p className=\"text-sm font-medium\">{t(\"Total\")}</p>\n {feeBps > 0 ? (\n <p className=\"text-xs text-muted-foreground\">{t(\"Includes {percent}% platform fee\", { percent: String(feeBps / 100) })}</p>\n ) : null}\n </div>\n <div className=\"text-right\">\n <p className=\"flex items-center justify-end gap-2 font-[family-name:var(--font-display)] text-2xl font-extrabold tracking-tight tabular-nums\">\n {symbol ? <CurrencyIcon symbol={symbol} size={18} /> : null}\n {text ?? <Loader2 className=\"h-5 w-5 animate-spin text-muted-foreground\" />}\n {text && symbol ? <span className=\"text-base font-bold text-muted-foreground\">{symbol}</span> : null}\n </p>\n {usd ? <p className=\"text-xs text-muted-foreground tabular-nums\">≈ {usd}</p> : null}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmFmB;AAjFnB,mBAAoD;AACpD,0BAAyD;AACzD,iBAA4C;AAC5C,mBAAkB;AAClB,mBAAwC;AACxC,2BAA6B;AAC7B,gBAAmB;AACnB,oBAAqD;AACrD,4BAA0C;AAC1C,iCAAmE;AACnE,sBAAqB;AACrB,wBAA0B;AAGnB,SAAS,WAAW,KAAa,UAA0B;AAChE,QAAM,CAAC,OAAO,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,OAAO,SAAS,OAAO,QAAQ,GAAE;AAAA,WAC3H;AAAA,QACC,UACC,4CAAC,+BAAQ,WAAU,2DAA0D,IAC3E,WACF,4CAAC,6BAAM,WAAU,iCAAgC,IAC/C;AAAA;AAAA;AAAA,EACN;AAEJ;AAEA,SAAS,UAAU,EAAE,QAAQ,KAAK,UAAU,OAAO,GAAoF;AACrI,QAAM,QAAI,sBAAK;AACf,QAAM,aAAS,oCAAa;AAC5B,QAAM,OAAO,QAAQ,OAAO,WAAW,KAAK,QAAQ,IAAI;AACxD,QAAM,MAAM,QAAQ,UAAU,KAAC,gCAAiB,MAAM,QAAI,mCAAY,MAAM,QAAQ,MAAM,IAAI;AAE9F,SACE,6CAAC,SAAI,WAAU,sEACb;AAAA,iDAAC,SACC;AAAA,kDAAC,OAAE,WAAU,uBAAuB,YAAE,OAAO,GAAE;AAAA,MAC9C,SAAS,IACR,4CAAC,OAAE,WAAU,iCAAiC,YAAE,oCAAoC,EAAE,SAAS,OAAO,SAAS,GAAG,EAAE,CAAC,GAAE,IACrH;AAAA,OACN;AAAA,IACA,6CAAC,SAAI,WAAU,cACb;AAAA,mDAAC,OAAE,WAAU,kIACV;AAAA,iBAAS,4CAAC,qCAAa,QAAgB,MAAM,IAAI,IAAK;AAAA,QACtD,QAAQ,4CAAC,+BAAQ,WAAU,8CAA6C;AAAA,QACxE,QAAQ,SAAS,4CAAC,UAAK,WAAU,6CAA6C,kBAAO,IAAU;AAAA,SAClG;AAAA,MACC,MAAM,6CAAC,OAAE,WAAU,8CAA6C;AAAA;AAAA,QAAG;AAAA,SAAI,IAAO;AAAA,OACjF;AAAA,KACF;AAEJ;","names":["Image"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { ApiOrder } from '@medialane/sdk';
|
|
4
|
+
|
|
5
|
+
/** A raw amount as text: four decimals, or four significant digits below one. */
|
|
6
|
+
declare function amountText(raw: bigint, decimals: number): string;
|
|
7
|
+
interface PurchasePanelProps {
|
|
8
|
+
order: ApiOrder;
|
|
9
|
+
/** The asset image, resolved by the app. */
|
|
10
|
+
image?: string | null;
|
|
11
|
+
quantity: number;
|
|
12
|
+
onQuantityChange: (quantity: number) => void;
|
|
13
|
+
/** The buyer's wallet; without one the coins are not listed. */
|
|
14
|
+
walletAddress: string | null;
|
|
15
|
+
payWith: string | null;
|
|
16
|
+
onPayWithChange: (symbol: string | null) => void;
|
|
17
|
+
/** Opens a way to add funds when no coin covers the purchase. */
|
|
18
|
+
onAddFunds?: () => void;
|
|
19
|
+
error?: string | null;
|
|
20
|
+
/** The action area: the Buy button, or what replaces it. */
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
/** Editions left to buy from an ERC-1155 listing; null for ERC-721. */
|
|
24
|
+
declare function editionsAvailable(order: ApiOrder): number | null;
|
|
25
|
+
/**
|
|
26
|
+
* The body of a purchase: what is bought, how many, which coin pays and the total, with the cost
|
|
27
|
+
* the app's client builds the purchase with. Each app passes its own action in `children`; the
|
|
28
|
+
* panel does not buy anything itself.
|
|
29
|
+
*/
|
|
30
|
+
declare function PurchasePanel({ order, image, quantity, onQuantityChange, walletAddress, payWith, onPayWithChange, onAddFunds, error, children, }: PurchasePanelProps): react_jsx_runtime.JSX.Element;
|
|
31
|
+
|
|
32
|
+
export { PurchasePanel, type PurchasePanelProps, amountText, editionsAvailable };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { ApiOrder } from '@medialane/sdk';
|
|
4
|
+
|
|
5
|
+
/** A raw amount as text: four decimals, or four significant digits below one. */
|
|
6
|
+
declare function amountText(raw: bigint, decimals: number): string;
|
|
7
|
+
interface PurchasePanelProps {
|
|
8
|
+
order: ApiOrder;
|
|
9
|
+
/** The asset image, resolved by the app. */
|
|
10
|
+
image?: string | null;
|
|
11
|
+
quantity: number;
|
|
12
|
+
onQuantityChange: (quantity: number) => void;
|
|
13
|
+
/** The buyer's wallet; without one the coins are not listed. */
|
|
14
|
+
walletAddress: string | null;
|
|
15
|
+
payWith: string | null;
|
|
16
|
+
onPayWithChange: (symbol: string | null) => void;
|
|
17
|
+
/** Opens a way to add funds when no coin covers the purchase. */
|
|
18
|
+
onAddFunds?: () => void;
|
|
19
|
+
error?: string | null;
|
|
20
|
+
/** The action area: the Buy button, or what replaces it. */
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
/** Editions left to buy from an ERC-1155 listing; null for ERC-721. */
|
|
24
|
+
declare function editionsAvailable(order: ApiOrder): number | null;
|
|
25
|
+
/**
|
|
26
|
+
* The body of a purchase: what is bought, how many, which coin pays and the total, with the cost
|
|
27
|
+
* the app's client builds the purchase with. Each app passes its own action in `children`; the
|
|
28
|
+
* panel does not buy anything itself.
|
|
29
|
+
*/
|
|
30
|
+
declare function PurchasePanel({ order, image, quantity, onQuantityChange, walletAddress, payWith, onPayWithChange, onAddFunds, error, children, }: PurchasePanelProps): react_jsx_runtime.JSX.Element;
|
|
31
|
+
|
|
32
|
+
export { PurchasePanel, type PurchasePanelProps, amountText, editionsAvailable };
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { AlertCircle, Check, Loader2, Minus, Plus } from "lucide-react";
|
|
5
|
+
import { formatAmount } from "@medialane/sdk";
|
|
6
|
+
import Image from "./image.js";
|
|
7
|
+
import { Alert, AlertDescription } from "./alert.js";
|
|
8
|
+
import { CurrencyIcon } from "./currency-icon.js";
|
|
9
|
+
import { cn } from "../utils/cn.js";
|
|
10
|
+
import { formatDisplayPrice, isStableCurrency } from "../utils/format.js";
|
|
11
|
+
import { useUsdPrices, usdValueFor } from "../utils/use-usd-prices.js";
|
|
12
|
+
import { pickPayment, usePaymentOptions } from "../utils/use-payment-options.js";
|
|
13
|
+
import { useT } from "../i18n/provider.js";
|
|
14
|
+
import { useFormat } from "../i18n/use-format.js";
|
|
15
|
+
function amountText(raw, decimals) {
|
|
16
|
+
const [whole, frac = ""] = formatAmount(raw.toString(), decimals).split(".");
|
|
17
|
+
const lead = whole === "0" ? frac.match(/^0*/)?.[0].length ?? 0 : 0;
|
|
18
|
+
const shown = frac.slice(0, lead + 4).replace(/0+$/, "");
|
|
19
|
+
return shown ? `${whole}.${shown}` : whole;
|
|
20
|
+
}
|
|
21
|
+
function editionsAvailable(order) {
|
|
22
|
+
if (order.offer.itemType !== "ERC1155") return null;
|
|
23
|
+
return Math.max(1, parseInt(order.remainingAmount ?? order.offer.startAmount ?? "1", 10));
|
|
24
|
+
}
|
|
25
|
+
function PurchasePanel({
|
|
26
|
+
order,
|
|
27
|
+
image,
|
|
28
|
+
quantity,
|
|
29
|
+
onQuantityChange,
|
|
30
|
+
walletAddress,
|
|
31
|
+
payWith,
|
|
32
|
+
onPayWithChange,
|
|
33
|
+
onAddFunds,
|
|
34
|
+
error,
|
|
35
|
+
children
|
|
36
|
+
}) {
|
|
37
|
+
const name = order.token?.name || `Token #${order.nftTokenId}`;
|
|
38
|
+
const price = order.price;
|
|
39
|
+
const currency = price?.currency ?? null;
|
|
40
|
+
const available = editionsAvailable(order);
|
|
41
|
+
const { cost, options, isLoading } = usePaymentOptions({ order, quantity, walletAddress });
|
|
42
|
+
const picked = isLoading ? payWith : pickPayment(options, payWith);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (picked !== payWith) onPayWithChange(picked);
|
|
45
|
+
}, [picked, payWith, onPayWithChange]);
|
|
46
|
+
const paying = options.find((o) => o.symbol === payWith) ?? null;
|
|
47
|
+
const totalSymbol = paying?.symbol ?? currency;
|
|
48
|
+
const totalRaw = paying ? paying.cost : cost.total;
|
|
49
|
+
const totalDecimals = paying?.decimals ?? price?.decimals ?? 18;
|
|
50
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-5 p-5", children: [
|
|
51
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3.5 pr-8", children: [
|
|
52
|
+
/* @__PURE__ */ jsx("div", { className: "relative h-14 w-14 shrink-0 overflow-hidden rounded-xl bg-muted", children: image ? /* @__PURE__ */ jsx(Image, { src: image, alt: name, fill: true, sizes: "56px", className: "object-cover", unoptimized: true }) : null }),
|
|
53
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
54
|
+
/* @__PURE__ */ jsx("p", { className: "truncate text-base font-semibold leading-tight", children: name }),
|
|
55
|
+
price?.formatted && currency ? /* @__PURE__ */ jsxs("p", { className: "mt-1 flex items-center gap-1.5 text-sm text-muted-foreground tabular-nums", children: [
|
|
56
|
+
/* @__PURE__ */ jsx(CurrencyIcon, { symbol: currency, size: 12 }),
|
|
57
|
+
formatDisplayPrice(price.formatted),
|
|
58
|
+
" ",
|
|
59
|
+
currency
|
|
60
|
+
] }) : null
|
|
61
|
+
] })
|
|
62
|
+
] }),
|
|
63
|
+
available !== null && available > 1 ? /* @__PURE__ */ jsx(QuantityField, { value: quantity, max: available, onChange: onQuantityChange }) : null,
|
|
64
|
+
walletAddress && currency ? /* @__PURE__ */ jsx(
|
|
65
|
+
PayWith,
|
|
66
|
+
{
|
|
67
|
+
options,
|
|
68
|
+
isLoading,
|
|
69
|
+
selected: payWith,
|
|
70
|
+
onSelect: onPayWithChange,
|
|
71
|
+
onAddFunds
|
|
72
|
+
}
|
|
73
|
+
) : null,
|
|
74
|
+
/* @__PURE__ */ jsx(TotalLine, { symbol: totalSymbol, raw: totalRaw, decimals: totalDecimals, feeBps: cost.feeBps }),
|
|
75
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
76
|
+
error ? /* @__PURE__ */ jsxs(Alert, { variant: "destructive", children: [
|
|
77
|
+
/* @__PURE__ */ jsx(AlertCircle, { className: "h-4 w-4" }),
|
|
78
|
+
/* @__PURE__ */ jsx(AlertDescription, { children: error })
|
|
79
|
+
] }) : null,
|
|
80
|
+
children
|
|
81
|
+
] })
|
|
82
|
+
] });
|
|
83
|
+
}
|
|
84
|
+
function QuantityField({ value, max, onChange }) {
|
|
85
|
+
const t = useT();
|
|
86
|
+
const format = useFormat();
|
|
87
|
+
const [draft, setDraft] = useState(String(value));
|
|
88
|
+
useEffect(() => setDraft(String(value)), [value]);
|
|
89
|
+
const clamp = (n) => Math.max(1, Math.min(max, Number.isFinite(n) ? Math.floor(n) : 1));
|
|
90
|
+
const commit = () => onChange(clamp(parseInt(draft, 10)));
|
|
91
|
+
const step = "grid h-10 w-10 place-items-center text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-xl";
|
|
92
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-4", children: [
|
|
93
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
94
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: t("Quantity") }),
|
|
95
|
+
/* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground tabular-nums", children: t("{count} available", { count: format.number(max) }) })
|
|
96
|
+
] }),
|
|
97
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center rounded-xl border border-border", children: [
|
|
98
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: step, disabled: value <= 1, onClick: () => onChange(clamp(value - 1)), "aria-label": t("Decrease quantity"), children: /* @__PURE__ */ jsx(Minus, { className: "h-4 w-4" }) }),
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
"input",
|
|
101
|
+
{
|
|
102
|
+
inputMode: "numeric",
|
|
103
|
+
"aria-label": t("Quantity"),
|
|
104
|
+
value: draft,
|
|
105
|
+
onChange: (e) => setDraft(e.target.value.replace(/\D/g, "")),
|
|
106
|
+
onBlur: commit,
|
|
107
|
+
onKeyDown: (e) => {
|
|
108
|
+
if (e.key === "Enter") commit();
|
|
109
|
+
},
|
|
110
|
+
className: "h-10 w-14 bg-transparent text-center text-base font-semibold tabular-nums outline-none"
|
|
111
|
+
}
|
|
112
|
+
),
|
|
113
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: step, disabled: value >= max, onClick: () => onChange(clamp(value + 1)), "aria-label": t("Increase quantity"), children: /* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" }) })
|
|
114
|
+
] })
|
|
115
|
+
] });
|
|
116
|
+
}
|
|
117
|
+
function PayWith({
|
|
118
|
+
options,
|
|
119
|
+
isLoading,
|
|
120
|
+
selected,
|
|
121
|
+
onSelect,
|
|
122
|
+
onAddFunds
|
|
123
|
+
}) {
|
|
124
|
+
const t = useT();
|
|
125
|
+
const nothingCovers = !isLoading && !options.some((o) => o.covers);
|
|
126
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
127
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: t("Pay with") }),
|
|
128
|
+
isLoading && options.length === 0 ? /* @__PURE__ */ jsxs("div", { className: "flex h-14 items-center justify-center gap-2 rounded-xl border border-border text-xs text-muted-foreground", children: [
|
|
129
|
+
/* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 animate-spin" }),
|
|
130
|
+
t("Checking your balances\u2026")
|
|
131
|
+
] }) : /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 gap-2", role: "radiogroup", "aria-label": t("Pay with"), children: options.map((option) => /* @__PURE__ */ jsx(
|
|
132
|
+
CoinChoice,
|
|
133
|
+
{
|
|
134
|
+
option,
|
|
135
|
+
quoting: isLoading && option.cost === null,
|
|
136
|
+
selected: selected === option.symbol,
|
|
137
|
+
onSelect: () => onSelect(option.symbol)
|
|
138
|
+
},
|
|
139
|
+
option.symbol
|
|
140
|
+
)) }),
|
|
141
|
+
nothingCovers ? /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground", children: [
|
|
142
|
+
t("Add funds to your wallet to buy this."),
|
|
143
|
+
" ",
|
|
144
|
+
onAddFunds ? /* @__PURE__ */ jsx("button", { type: "button", onClick: onAddFunds, className: "font-semibold text-primary hover:underline", children: t("Add funds") }) : null
|
|
145
|
+
] }) : null
|
|
146
|
+
] });
|
|
147
|
+
}
|
|
148
|
+
function CoinChoice({ option, quoting, selected, onSelect }) {
|
|
149
|
+
return /* @__PURE__ */ jsxs(
|
|
150
|
+
"button",
|
|
151
|
+
{
|
|
152
|
+
type: "button",
|
|
153
|
+
role: "radio",
|
|
154
|
+
"aria-checked": selected,
|
|
155
|
+
disabled: !option.covers,
|
|
156
|
+
onClick: onSelect,
|
|
157
|
+
className: cn(
|
|
158
|
+
"flex items-center gap-2.5 rounded-xl border px-3 py-2.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
|
159
|
+
selected ? "border-primary bg-primary/[0.06]" : "border-border hover:bg-muted/40",
|
|
160
|
+
!option.covers && "opacity-45"
|
|
161
|
+
),
|
|
162
|
+
children: [
|
|
163
|
+
/* @__PURE__ */ jsx(CurrencyIcon, { symbol: option.symbol, size: 20, className: "shrink-0" }),
|
|
164
|
+
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
165
|
+
/* @__PURE__ */ jsx("span", { className: "block text-sm font-semibold leading-tight", children: option.symbol }),
|
|
166
|
+
/* @__PURE__ */ jsx("span", { className: "block truncate text-xs text-muted-foreground tabular-nums", children: amountText(option.balance, option.decimals) })
|
|
167
|
+
] }),
|
|
168
|
+
quoting ? /* @__PURE__ */ jsx(Loader2, { className: "h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground" }) : selected ? /* @__PURE__ */ jsx(Check, { className: "h-4 w-4 shrink-0 text-primary" }) : null
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
function TotalLine({ symbol, raw, decimals, feeBps }) {
|
|
174
|
+
const t = useT();
|
|
175
|
+
const prices = useUsdPrices();
|
|
176
|
+
const text = raw !== null ? amountText(raw, decimals) : null;
|
|
177
|
+
const usd = text && symbol && !isStableCurrency(symbol) ? usdValueFor(text, symbol, prices) : null;
|
|
178
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4 border-t border-border pt-4", children: [
|
|
179
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
180
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: t("Total") }),
|
|
181
|
+
feeBps > 0 ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: t("Includes {percent}% platform fee", { percent: String(feeBps / 100) }) }) : null
|
|
182
|
+
] }),
|
|
183
|
+
/* @__PURE__ */ jsxs("div", { className: "text-right", children: [
|
|
184
|
+
/* @__PURE__ */ jsxs("p", { className: "flex items-center justify-end gap-2 font-[family-name:var(--font-display)] text-2xl font-extrabold tracking-tight tabular-nums", children: [
|
|
185
|
+
symbol ? /* @__PURE__ */ jsx(CurrencyIcon, { symbol, size: 18 }) : null,
|
|
186
|
+
text ?? /* @__PURE__ */ jsx(Loader2, { className: "h-5 w-5 animate-spin text-muted-foreground" }),
|
|
187
|
+
text && symbol ? /* @__PURE__ */ jsx("span", { className: "text-base font-bold text-muted-foreground", children: symbol }) : null
|
|
188
|
+
] }),
|
|
189
|
+
usd ? /* @__PURE__ */ jsxs("p", { className: "text-xs text-muted-foreground tabular-nums", children: [
|
|
190
|
+
"\u2248 ",
|
|
191
|
+
usd
|
|
192
|
+
] }) : null
|
|
193
|
+
] })
|
|
194
|
+
] });
|
|
195
|
+
}
|
|
196
|
+
export {
|
|
197
|
+
PurchasePanel,
|
|
198
|
+
amountText,
|
|
199
|
+
editionsAvailable
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=purchase-panel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/purchase-panel.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useState, type ReactNode } from \"react\";\nimport { AlertCircle, Check, Loader2, Minus, Plus } from \"lucide-react\";\nimport { formatAmount, type ApiOrder } from \"@medialane/sdk\";\nimport Image from \"./image.js\";\nimport { Alert, AlertDescription } from \"./alert.js\";\nimport { CurrencyIcon } from \"./currency-icon.js\";\nimport { cn } from \"../utils/cn.js\";\nimport { formatDisplayPrice, isStableCurrency } from \"../utils/format.js\";\nimport { useUsdPrices, usdValueFor } from \"../utils/use-usd-prices.js\";\nimport { pickPayment, usePaymentOptions, type PaymentOption } from \"../utils/use-payment-options.js\";\nimport { useT } from \"../i18n/provider.js\";\nimport { useFormat } from \"../i18n/use-format.js\";\n\n/** A raw amount as text: four decimals, or four significant digits below one. */\nexport function amountText(raw: bigint, decimals: number): string {\n const [whole, frac = \"\"] = formatAmount(raw.toString(), decimals).split(\".\");\n const lead = whole === \"0\" ? (frac.match(/^0*/)?.[0].length ?? 0) : 0;\n const shown = frac.slice(0, lead + 4).replace(/0+$/, \"\");\n return shown ? `${whole}.${shown}` : whole;\n}\n\nexport interface PurchasePanelProps {\n order: ApiOrder;\n /** The asset image, resolved by the app. */\n image?: string | null;\n quantity: number;\n onQuantityChange: (quantity: number) => void;\n /** The buyer's wallet; without one the coins are not listed. */\n walletAddress: string | null;\n payWith: string | null;\n onPayWithChange: (symbol: string | null) => void;\n /** Opens a way to add funds when no coin covers the purchase. */\n onAddFunds?: () => void;\n error?: string | null;\n /** The action area: the Buy button, or what replaces it. */\n children: ReactNode;\n}\n\n/** Editions left to buy from an ERC-1155 listing; null for ERC-721. */\nexport function editionsAvailable(order: ApiOrder): number | null {\n if (order.offer.itemType !== \"ERC1155\") return null;\n return Math.max(1, parseInt(order.remainingAmount ?? order.offer.startAmount ?? \"1\", 10));\n}\n\n/**\n * The body of a purchase: what is bought, how many, which coin pays and the total, with the cost\n * the app's client builds the purchase with. Each app passes its own action in `children`; the\n * panel does not buy anything itself.\n */\nexport function PurchasePanel({\n order,\n image,\n quantity,\n onQuantityChange,\n walletAddress,\n payWith,\n onPayWithChange,\n onAddFunds,\n error,\n children,\n}: PurchasePanelProps) {\n const name = order.token?.name || `Token #${order.nftTokenId}`;\n const price = order.price;\n const currency = price?.currency ?? null;\n const available = editionsAvailable(order);\n const { cost, options, isLoading } = usePaymentOptions({ order, quantity, walletAddress });\n\n const picked = isLoading ? payWith : pickPayment(options, payWith);\n useEffect(() => {\n if (picked !== payWith) onPayWithChange(picked);\n }, [picked, payWith, onPayWithChange]);\n\n const paying = options.find((o) => o.symbol === payWith) ?? null;\n const totalSymbol = paying?.symbol ?? currency;\n const totalRaw = paying ? paying.cost : cost.total;\n const totalDecimals = paying?.decimals ?? price?.decimals ?? 18;\n\n return (\n <div className=\"flex flex-col gap-5 p-5\">\n <div className=\"flex items-center gap-3.5 pr-8\">\n <div className=\"relative h-14 w-14 shrink-0 overflow-hidden rounded-xl bg-muted\">\n {image ? <Image src={image} alt={name} fill sizes=\"56px\" className=\"object-cover\" unoptimized /> : null}\n </div>\n <div className=\"min-w-0\">\n <p className=\"truncate text-base font-semibold leading-tight\">{name}</p>\n {price?.formatted && currency ? (\n <p className=\"mt-1 flex items-center gap-1.5 text-sm text-muted-foreground tabular-nums\">\n <CurrencyIcon symbol={currency} size={12} />\n {formatDisplayPrice(price.formatted)} {currency}\n </p>\n ) : null}\n </div>\n </div>\n\n {available !== null && available > 1 ? (\n <QuantityField value={quantity} max={available} onChange={onQuantityChange} />\n ) : null}\n\n {walletAddress && currency ? (\n <PayWith\n options={options}\n isLoading={isLoading}\n selected={payWith}\n onSelect={onPayWithChange}\n onAddFunds={onAddFunds}\n />\n ) : null}\n\n <TotalLine symbol={totalSymbol} raw={totalRaw} decimals={totalDecimals} feeBps={cost.feeBps} />\n\n <div className=\"flex flex-col gap-3\">\n {error ? (\n <Alert variant=\"destructive\">\n <AlertCircle className=\"h-4 w-4\" />\n <AlertDescription>{error}</AlertDescription>\n </Alert>\n ) : null}\n {children}\n </div>\n </div>\n );\n}\n\nfunction QuantityField({ value, max, onChange }: { value: number; max: number; onChange: (value: number) => void }) {\n const t = useT();\n const format = useFormat();\n const [draft, setDraft] = useState(String(value));\n useEffect(() => setDraft(String(value)), [value]);\n const clamp = (n: number) => Math.max(1, Math.min(max, Number.isFinite(n) ? Math.floor(n) : 1));\n const commit = () => onChange(clamp(parseInt(draft, 10)));\n const step = \"grid h-10 w-10 place-items-center text-muted-foreground transition-colors hover:text-foreground disabled:pointer-events-none disabled:opacity-40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring rounded-xl\";\n\n return (\n <div className=\"flex items-center justify-between gap-4\">\n <div>\n <p className=\"text-sm font-medium\">{t(\"Quantity\")}</p>\n <p className=\"text-xs text-muted-foreground tabular-nums\">{t(\"{count} available\", { count: format.number(max) })}</p>\n </div>\n <div className=\"flex items-center rounded-xl border border-border\">\n <button type=\"button\" className={step} disabled={value <= 1} onClick={() => onChange(clamp(value - 1))} aria-label={t(\"Decrease quantity\")}>\n <Minus className=\"h-4 w-4\" />\n </button>\n <input\n inputMode=\"numeric\"\n aria-label={t(\"Quantity\")}\n value={draft}\n onChange={(e) => setDraft(e.target.value.replace(/\\D/g, \"\"))}\n onBlur={commit}\n onKeyDown={(e) => { if (e.key === \"Enter\") commit(); }}\n className=\"h-10 w-14 bg-transparent text-center text-base font-semibold tabular-nums outline-none\"\n />\n <button type=\"button\" className={step} disabled={value >= max} onClick={() => onChange(clamp(value + 1))} aria-label={t(\"Increase quantity\")}>\n <Plus className=\"h-4 w-4\" />\n </button>\n </div>\n </div>\n );\n}\n\nfunction PayWith({\n options,\n isLoading,\n selected,\n onSelect,\n onAddFunds,\n}: {\n options: PaymentOption[];\n isLoading: boolean;\n selected: string | null;\n onSelect: (symbol: string) => void;\n onAddFunds?: () => void;\n}) {\n const t = useT();\n const nothingCovers = !isLoading && !options.some((o) => o.covers);\n\n return (\n <div className=\"flex flex-col gap-2\">\n <p className=\"text-sm font-medium\">{t(\"Pay with\")}</p>\n {isLoading && options.length === 0 ? (\n <div className=\"flex h-14 items-center justify-center gap-2 rounded-xl border border-border text-xs text-muted-foreground\">\n <Loader2 className=\"h-3.5 w-3.5 animate-spin\" />\n {t(\"Checking your balances…\")}\n </div>\n ) : (\n <div className=\"grid grid-cols-2 gap-2\" role=\"radiogroup\" aria-label={t(\"Pay with\")}>\n {options.map((option) => (\n <CoinChoice\n key={option.symbol}\n option={option}\n quoting={isLoading && option.cost === null}\n selected={selected === option.symbol}\n onSelect={() => onSelect(option.symbol)}\n />\n ))}\n </div>\n )}\n {nothingCovers ? (\n <p className=\"text-xs text-muted-foreground\">\n {t(\"Add funds to your wallet to buy this.\")}{\" \"}\n {onAddFunds ? (\n <button type=\"button\" onClick={onAddFunds} className=\"font-semibold text-primary hover:underline\">\n {t(\"Add funds\")}\n </button>\n ) : null}\n </p>\n ) : null}\n </div>\n );\n}\n\nfunction CoinChoice({ option, quoting, selected, onSelect }: { option: PaymentOption; quoting: boolean; selected: boolean; onSelect: () => void }) {\n return (\n <button\n type=\"button\"\n role=\"radio\"\n aria-checked={selected}\n disabled={!option.covers}\n onClick={onSelect}\n className={cn(\n \"flex items-center gap-2.5 rounded-xl border px-3 py-2.5 text-left transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n selected ? \"border-primary bg-primary/[0.06]\" : \"border-border hover:bg-muted/40\",\n !option.covers && \"opacity-45\",\n )}\n >\n <CurrencyIcon symbol={option.symbol} size={20} className=\"shrink-0\" />\n <span className=\"min-w-0 flex-1\">\n <span className=\"block text-sm font-semibold leading-tight\">{option.symbol}</span>\n <span className=\"block truncate text-xs text-muted-foreground tabular-nums\">{amountText(option.balance, option.decimals)}</span>\n </span>\n {quoting ? (\n <Loader2 className=\"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground\" />\n ) : selected ? (\n <Check className=\"h-4 w-4 shrink-0 text-primary\" />\n ) : null}\n </button>\n );\n}\n\nfunction TotalLine({ symbol, raw, decimals, feeBps }: { symbol: string | null; raw: bigint | null; decimals: number; feeBps: number }) {\n const t = useT();\n const prices = useUsdPrices();\n const text = raw !== null ? amountText(raw, decimals) : null;\n const usd = text && symbol && !isStableCurrency(symbol) ? usdValueFor(text, symbol, prices) : null;\n\n return (\n <div className=\"flex items-start justify-between gap-4 border-t border-border pt-4\">\n <div>\n <p className=\"text-sm font-medium\">{t(\"Total\")}</p>\n {feeBps > 0 ? (\n <p className=\"text-xs text-muted-foreground\">{t(\"Includes {percent}% platform fee\", { percent: String(feeBps / 100) })}</p>\n ) : null}\n </div>\n <div className=\"text-right\">\n <p className=\"flex items-center justify-end gap-2 font-[family-name:var(--font-display)] text-2xl font-extrabold tracking-tight tabular-nums\">\n {symbol ? <CurrencyIcon symbol={symbol} size={18} /> : null}\n {text ?? <Loader2 className=\"h-5 w-5 animate-spin text-muted-foreground\" />}\n {text && symbol ? <span className=\"text-base font-bold text-muted-foreground\">{symbol}</span> : null}\n </p>\n {usd ? <p className=\"text-xs text-muted-foreground tabular-nums\">≈ {usd}</p> : null}\n </div>\n </div>\n );\n}\n"],"mappings":";AAmFmB,cAKP,YALO;AAjFnB,SAAS,WAAW,gBAAgC;AACpD,SAAS,aAAa,OAAO,SAAS,OAAO,YAAY;AACzD,SAAS,oBAAmC;AAC5C,OAAO,WAAW;AAClB,SAAS,OAAO,wBAAwB;AACxC,SAAS,oBAAoB;AAC7B,SAAS,UAAU;AACnB,SAAS,oBAAoB,wBAAwB;AACrD,SAAS,cAAc,mBAAmB;AAC1C,SAAS,aAAa,yBAA6C;AACnE,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAGnB,SAAS,WAAW,KAAa,UAA0B;AAChE,QAAM,CAAC,OAAO,OAAO,EAAE,IAAI,aAAa,IAAI,SAAS,GAAG,QAAQ,EAAE,MAAM,GAAG;AAC3E,QAAM,OAAO,UAAU,MAAO,KAAK,MAAM,KAAK,IAAI,CAAC,EAAE,UAAU,IAAK;AACpE,QAAM,QAAQ,KAAK,MAAM,GAAG,OAAO,CAA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;AACrI,QAAM,IAAI,KAAK;AACf,QAAM,SAAS,aAAa;AAC5B,QAAM,OAAO,QAAQ,OAAO,WAAW,KAAK,QAAQ,IAAI;AACxD,QAAM,MAAM,QAAQ,UAAU,CAAC,iBAAiB,MAAM,IAAI,YAAY,MAAM,QAAQ,MAAM,IAAI;AAE9F,SACE,qBAAC,SAAI,WAAU,sEACb;AAAA,yBAAC,SACC;AAAA,0BAAC,OAAE,WAAU,uBAAuB,YAAE,OAAO,GAAE;AAAA,MAC9C,SAAS,IACR,oBAAC,OAAE,WAAU,iCAAiC,YAAE,oCAAoC,EAAE,SAAS,OAAO,SAAS,GAAG,EAAE,CAAC,GAAE,IACrH;AAAA,OACN;AAAA,IACA,qBAAC,SAAI,WAAU,cACb;AAAA,2BAAC,OAAE,WAAU,kIACV;AAAA,iBAAS,oBAAC,gBAAa,QAAgB,MAAM,IAAI,IAAK;AAAA,QACtD,QAAQ,oBAAC,WAAQ,WAAU,8CAA6C;AAAA,QACxE,QAAQ,SAAS,oBAAC,UAAK,WAAU,6CAA6C,kBAAO,IAAU;AAAA,SAClG;AAAA,MACC,MAAM,qBAAC,OAAE,WAAU,8CAA6C;AAAA;AAAA,QAAG;AAAA,SAAI,IAAO;AAAA,OACjF;AAAA,KACF;AAEJ;","names":[]}
|
package/dist/i18n/catalog/pt.cjs
CHANGED
|
@@ -1699,7 +1699,16 @@ const pt = {
|
|
|
1699
1699
|
"\u2713 Available \u2014": "\u2713 Dispon\xEDvel \u2014",
|
|
1700
1700
|
"\u2713 Uploaded": "\u2713 Enviado",
|
|
1701
1701
|
"\u2713 Verified holder": "\u2713 Portador verificado",
|
|
1702
|
-
"\u2713 You're a holder \u2014 unlocked": "\u2713 Voc\xEA \xE9 portador \u2014 liberado"
|
|
1702
|
+
"\u2713 You're a holder \u2014 unlocked": "\u2713 Voc\xEA \xE9 portador \u2014 liberado",
|
|
1703
|
+
"{count} available": "{count} dispon\xEDveis",
|
|
1704
|
+
"Pay with": "Pagar com",
|
|
1705
|
+
"Checking your balances\u2026": "Verificando seus saldos\u2026",
|
|
1706
|
+
"Add funds to your wallet to buy this.": "Adicione fundos \xE0 sua carteira para comprar.",
|
|
1707
|
+
"Add funds": "Adicionar fundos",
|
|
1708
|
+
"Total": "Total",
|
|
1709
|
+
"Includes {percent}% platform fee": "Inclui taxa de plataforma de {percent}%",
|
|
1710
|
+
"Decrease quantity": "Diminuir quantidade",
|
|
1711
|
+
"Increase quantity": "Aumentar quantidade"
|
|
1703
1712
|
};
|
|
1704
1713
|
var pt_default = pt;
|
|
1705
1714
|
//# sourceMappingURL=pt.cjs.map
|