Skip to content

Commit

Permalink
fix: bugs on affiliate
Browse files Browse the repository at this point in the history
  • Loading branch information
painiteleo authored and painiteleo committed Jul 9, 2024
1 parent 3dc347c commit 07e3181
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 65 deletions.
54 changes: 42 additions & 12 deletions src/components/app/affiliate/AppAffiliate.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { Button, Card, Input } from "@/components/ui";
import { createAffiliateCode, RequestParams } from "@/services/api/createAffiliateCode";
import {
Button,
Card,
DialogTrigger,
Input,
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui";
import {
AffiliateResponse,
createAffiliateCode,
RequestParams,
} from "@/services/api/createAffiliateCode";
import { FC, useEffect, useRef, useState } from "react";
import { twMerge } from "tailwind-merge";
import { useCopyToClipboard } from "usehooks-ts";
Expand All @@ -10,6 +22,9 @@ export const AppAffiliate: FC = () => {
const [isLoading, setIsLoading] = useState<boolean>(false);
const [copiedText, copy] = useCopyToClipboard();
const [affiliateUrl, setAffiliateUrl] = useState<string>("https://ledgity.finance/example");
const [errorMsg, setErrorMsg] = useState<string>();
const [isError, setIsError] = useState<boolean>(false);
const [affiliateData, setAffiliateData] = useState<AffiliateResponse>();

const handleCopy = (text: string) => {
copy(text)
Expand All @@ -28,7 +43,10 @@ export const AppAffiliate: FC = () => {
walletAddress: getAddress(walletAddress),
};
const data = await createAffiliateCode(requestParams);
console.log("data: ", data);
// setIsError(!data.isSuccess);
// setErrorMsg(data.message);
// setErrorMsg(data.message);
setAffiliateData(data);
setIsLoading(false);
}
};
Expand All @@ -51,13 +69,25 @@ export const AppAffiliate: FC = () => {
>
<div className="">Paste your wallet to participate in the affiliate program!</div>
<div className="flex justify-start w-full gap-x-2">
<Input
placeholder="Input Wallet Address"
value={walletAddress}
onChange={(e) => (setWalletAddress ? setWalletAddress(e.target.value) : null)}
disableDefaultCss={true}
className="bg-gray-300 w-full p-1 rounded-lg text-sm"
/>
<Tooltip open={affiliateData && !affiliateData.isSuccess}>
<TooltipTrigger className="w-full h-full content-center">
<Input
placeholder="Input Wallet Address"
value={walletAddress}
onChange={(e) => (setWalletAddress ? setWalletAddress(e.target.value) : null)}
disableDefaultCss={true}
className="bg-gray-300 w-full p-2 rounded-lg text-sm"
/>
</TooltipTrigger>
<TooltipContent
className="font-semibold"
variant={"destructive"}
side="bottom"
sideOffset={4}
>
{affiliateData?.message}
</TooltipContent>
</Tooltip>
<Button
size="tiny"
onClick={sendAffiliateRequest}
Expand All @@ -83,11 +113,11 @@ export const AppAffiliate: FC = () => {
<div className="relative flex bg-gray-300 w-full rounded-lg">
<i
className="ri-link rounded-full px-1 text-2xl font-bold absolute z-20 h-8 top-1/2 transform -translate-y-1/2 left-3 bg-none hover:cursor-pointer hover:bg-gray-100"
onClick={() => handleCopy(affiliateUrl)}
onClick={() => affiliateData && handleCopy(affiliateData.referralUrl)}
></i>
<input
type="text"
value={affiliateUrl}
value={affiliateData && affiliateData.referralUrl}
readOnly
className="w-full bg-transparent text-gray-400 focus:ring relative rounded text-sm border-none outline-none focus:outline-none pl-12 pr-3 py-2"
/>
Expand Down
65 changes: 12 additions & 53 deletions src/services/api/createAffiliateCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,10 @@ export interface RequestParams {
walletAddress: Address;
}

export interface QuotoV2Response {
deprecated: string;
inTokens: string[];
outTokens: string[];
inAmounts: string[];
outAmounts: string[];
gasEstimate: number;
dataGasEstimate: number;
gweiPerGas: number;
gasEstimateValue: number;
inValues: number[];
outValues: number[];
netOutValue: number;
priceImpact: number;
percentDiff: number;
partnerFeePercent: number;
pathId: string | null;
pathViz: object;
pathVizImage: string;
blockNumber: number;
export interface AffiliateResponse {
isSuccess: boolean;
message: string;
referralUrl: string;
}

export const createAffiliateCode = (params: RequestParams) => {
Expand All @@ -35,37 +19,12 @@ export const createAffiliateCode = (params: RequestParams) => {
headers: { "Content-Type": "application/json" },
body: JSON.stringify(params),
};
console.log("AFFILIATE_URL: ", AFFILIATE_URL);
return fetch(AFFILIATE_URL + "/affiliate/create", option)
.then(async (res) => {
// if (!res.ok) throw new Error();
if (!res.ok) console.log("failed: ", res);
const data: any = await res.json();
console.log("data: ", data);
// return {
// deprecated: data.deprecated,
// inTokens: data.inTokens,
// outTokens: data.outTokens,
// inAmounts: data.inAmounts,
// outAmounts: data.outAmounts,
// gasEstimate: data.gasEstimate,
// dataGasEstimate: data.dataGasEstimate,
// gweiPerGas: data.gweiPerGas,
// gasEstimateValue: data.gasEstimateValue,
// inValues: data.inValues,
// outValues: data.outValues,
// netOutValue: data.netOutValue,
// priceImpact: data.priceImpact,
// percentDiff: data.percentDiff,
// partnerFeePercent: data.partnerFeePercent,
// pathId: data.pathId,
// pathViz: data.pathViz,
// pathVizImage: data.pathVizImage,
// blockNumber: data.blockNumber,
// };
})
.catch((error) => {
console.log(error);
return undefined;
});
return fetch(AFFILIATE_URL + "/affiliate/create", option).then(async (res) => {
const data: any = await res.json();
return {
isSuccess: res.ok,
message: data.message,
referralUrl: data.referralUrl,
};
});
};

0 comments on commit 07e3181

Please sign in to comment.