Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat: add optional fee recipient to matcha swap settings #523

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/fidgets/swap/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type MatchaFidgetSettings = {
fontFamily: string;
fontColor: string;
swapScale: number;
optionalFeeRecipient?: string;
} & FidgetSettingsStyle;

const matchaProperties: FidgetProperties = {
Expand Down Expand Up @@ -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: "",
Expand Down Expand Up @@ -92,22 +101,33 @@ const Swap: React.FC<FidgetArgs<MatchaFidgetSettings>> = ({ 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);
if (defaultBuyToken) params.append("buyAddress", defaultBuyToken);
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 (
<div
style={{
Expand Down