From 353fcdf5eb9b21883551907788f7d0dc0a2fd601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 30 Jan 2025 16:41:05 +0100 Subject: [PATCH] Add referrer field to ad --- src/web/src/SubmitButton.jsx | 46 +++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/web/src/SubmitButton.jsx b/src/web/src/SubmitButton.jsx index b78d05e..df6e8d8 100644 --- a/src/web/src/SubmitButton.jsx +++ b/src/web/src/SubmitButton.jsx @@ -440,6 +440,22 @@ const AdForm = (props) => { const [isValid, setIsValid] = useState(false); const [isLoading, setIsLoading] = useState(false); const { switchNetwork } = useSwitchNetwork(); + const [referrer, setReferrer] = useState(""); + + const buildURL = (baseURL) => { + let url; + try { + url = new URL(baseURL); + } catch (err) { + return baseURL; + } + + if (referrer?.trim()) { + const safe = encodeURIComponent(referrer.trim().slice(0, 100)); + url.searchParams.set("kiwi_news_referrer", safe); + } + return url.toString(); + }; const { address, isConnected } = useAccount(); const { data: balanceData } = useBalance({ @@ -486,11 +502,12 @@ const AdForm = (props) => { } const transferFee = minAdPrice === 0n ? 0n : minAdPrice - 1n; + const finalUrl = buildURL(url); const { config, error } = usePrepareContractWrite({ address: adContractAddress, abi: adContractABI, functionName: "set", - args: [title, url], + args: [title, finalUrl], value: parsedUserPrice + transferFee, chainId: optimism.id, }); @@ -680,6 +697,33 @@ const AdForm = (props) => { +
+ + setReferrer(e.target.value)} + style={{ + width: "100%", + padding: "6px", + border: "1px solid #ddd", + borderRadius: "4px", + }} + /> + + We share 50% of the ad fee income with the person who is named as + the referrer. + +
+ {({ account, chain, mounted, openConnectModal }) => { const connected = account && chain && mounted;