From bd611100ab33a112288dfc35131161fbe7ca83ea Mon Sep 17 00:00:00 2001 From: sktbrd Date: Fri, 13 Dec 2024 19:00:28 +0700 Subject: [PATCH] feat: add optional fee recipient to matcha swap settings --- src/fidgets/swap/Swap.tsx | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/fidgets/swap/Swap.tsx b/src/fidgets/swap/Swap.tsx index bf532df0..1a5d2c5d 100644 --- a/src/fidgets/swap/Swap.tsx +++ b/src/fidgets/swap/Swap.tsx @@ -17,6 +17,7 @@ type MatchaFidgetSettings = { fontFamily: string; fontColor: string; swapScale: number; + optionalFeeRecipient?: string; } & FidgetSettingsStyle; const matchaProperties: FidgetProperties = { @@ -51,6 +52,14 @@ const matchaProperties: FidgetProperties = { inputSelector: ChainSelector, group: "settings", }, + // added inout for optional fee recipient + { + fieldName: "optionalFeeRecipient", + default: "0xabc..12345", + required: false, + inputSelector: TextInput, + group: "settings", + }, // { // fieldName: "background", // default: "", @@ -92,7 +101,13 @@ const Swap: React.FC> = ({ settings }) => { const matchaBaseUrl = "https://matcha.xyz/trade"; const buildMatchaUrl = () => { - const { defaultSellToken, defaultBuyToken, fromChain, toChain } = settings; + const { + defaultSellToken, + defaultBuyToken, + fromChain, + toChain, + optionalFeeRecipient, + } = settings; const params = new URLSearchParams(); if (defaultSellToken) params.append("sellAddress", defaultSellToken); @@ -100,14 +115,19 @@ const Swap: React.FC> = ({ settings }) => { if (fromChain) params.append("sellChain", fromChain.toString().toLowerCase()); if (toChain) params.append("buyChain", toChain.toString().toLowerCase()); + + // Add referral reward parameters if optionalFeeRecipient is provided + if (optionalFeeRecipient) { + params.append("ref", optionalFeeRecipient); // Referral address + params.append("swapFeeBps", "10"); // Example fee percentage in bps (adjust as needed) + } + // function calculateHeight(value: number) { + // const translation = (value - 1) * 30; + // return `${translation}%`; + // } return `${matchaBaseUrl}?${params.toString()}`; }; - // function calculateHeight(value: number) { - // const translation = (value - 1) * 30; - // return `${translation}%`; - // } - return (