diff --git a/apps/web/app/merchant/page.tsx b/apps/web/app/merchant/page.tsx index be6a603..56fee58 100644 --- a/apps/web/app/merchant/page.tsx +++ b/apps/web/app/merchant/page.tsx @@ -4,7 +4,7 @@ import { completeBuckets, type LoanView } from "@runway/sdk"; import Link from "next/link"; import { QRCodeSVG } from "qrcode.react"; -import { useState, type ReactNode } from "react"; +import { useEffect, useState, type ReactNode } from "react"; import { Icon } from "../../components/art"; import { useNow } from "../../components/motion"; import { RevenueChart, type BucketPoint } from "../../components/RevenueChart"; @@ -54,14 +54,18 @@ export default function MerchantPage() { const [busy, setBusy] = useState(false); const [copied, setCopied] = useState(false); const [txError, setTxError] = useState(null); - const m = useAsync( - () => (w.accountId ? credit.merchantByAccount(w.accountId) : Promise.resolve(null)), - [w.accountId], - ); + // ?view=: anyone can look at a merchant's dashboard read-only (it is all public on-chain data). + const [viewAs, setViewAs] = useState(null); + useEffect(() => { + const v = new URLSearchParams(window.location.search).get("view"); + if (v && /^[a-z0-9._-]{2,64}$/.test(v)) setViewAs(v); + }, []); + const account = w.accountId ?? viewAs; + const readOnly = !w.accountId && viewAs !== null; + const m = useAsync(() => (account ? credit.merchantByAccount(account) : Promise.resolve(null)), [account]); const usdcReady = useAsync( - () => - w.accountId ? storageOf(DEPLOYMENT.token, w.accountId).then((s) => s !== null) : Promise.resolve(false), - [w.accountId], + () => (account ? storageOf(DEPLOYMENT.token, account).then((s) => s !== null) : Promise.resolve(false)), + [account], ); const merchant = m.data; const chain = useAsync(async () => { @@ -89,7 +93,7 @@ export default function MerchantPage() { }; // ---------- not connected ---------- - if (!w.accountId) + if (!account) return ( @@ -124,6 +128,16 @@ export default function MerchantPage() {

Connect the wallet that should receive your payouts.

+

+ Just looking?{" "} + + View the demo merchant's dashboard + {" "} + (read-only). +

You need a NEAR testnet wallet (Meteor works best) with about 4 NEAR from{" "} @@ -161,7 +175,7 @@ export default function MerchantPage() {
); - const usdcWarning = usdcReady.data === false && ( + const usdcWarning = !readOnly && usdcReady.data === false && ( Your wallet isn't registered with the USDC token yet, so it can't receive your sales or a loan. Open{" "} @@ -173,6 +187,16 @@ export default function MerchantPage() { ); // ---------- register ---------- + if (!merchant && readOnly) + return ( + + +

+ {viewAs} isn't registered as a Runway merchant. +

+
+
+ ); if (!merchant) { const valid = /^[a-z0-9]{2,32}$/.test(handle); return ( @@ -235,10 +259,11 @@ export default function MerchantPage() { const done = chain.data ? completeBuckets(chain.data.buckets, current) : []; const first = current - BigInt(done.length); const currentInflow = BigInt(chain.data?.buckets.find((b) => BigInt(b.bucket) === current)?.inflow ?? "0"); + // The chart shows the last 12 windows; offers look at the last 6 completed ones. const points: BucketPoint[] = [ ...done.map((v, i) => ({ bucket: first + BigInt(i), inflow: v, current: false })), ...(chain.data ? [{ bucket: current, inflow: currentInflow, current: true }] : []), - ]; + ].slice(-12); const loan = chain.data?.loan; const repaidPct = loan ? Number((BigInt(loan.repaid) * 1000n) / BigInt(loan.owed)) / 10 : 0; const clock = windowClock(now); @@ -335,14 +360,18 @@ export default function MerchantPage() { } actions={ - <> - - Capital - - - Payout settings - - + readOnly ? ( + read-only view + ) : ( + <> + + Capital + + + Payout settings + + + ) } > Payments to {merchant.merchant.settlement} are split @@ -351,6 +380,12 @@ export default function MerchantPage() {
{usdcWarning} + {readOnly && ( + + You're viewing this merchant's dashboard read-only: everything here is public on-chain + data. Connect your own wallet to register and manage your own. + + )}
@@ -494,35 +529,42 @@ export default function MerchantPage() {
-
+ {readOnly ? (

- Claimable: {fmtUsdc(merchant.claimable)} USDC (payouts - that couldn't be delivered). -

- - setNewPayout(e.target.value)} - hint={`Now: ${merchant.merchant.payout}`} - /> - -

- Careful: the payout account is also the wallet that manages this merchant (it accepts - offers). Only change it to a wallet you control. + Payouts go to {merchant.merchant.payout}. Claimable:{" "} + {fmtUsdc(merchant.claimable)} USDC.

-
+ ) : ( +
+

+ Claimable: {fmtUsdc(merchant.claimable)} USDC (payouts + that couldn't be delivered). +

+ + setNewPayout(e.target.value)} + hint={`Now: ${merchant.merchant.payout}`} + /> + +

+ Careful: the payout account is also the wallet that manages this merchant (it accepts + offers). Only change it to a wallet you control. +

+
+ )}