Skip to content

Commit 3929d7a

Browse files
bump : squid widget (#3677)
* bump : squid widget * fix
1 parent c88032b commit 3929d7a

File tree

6 files changed

+49
-97
lines changed

6 files changed

+49
-97
lines changed

packages/grant-explorer/src/features/api/oso.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useState } from "react";
22
import useSWR from "swr";
3-
import { Hex } from "viem";
43
import { gql, GraphQLClient } from "graphql-request";
54

65
const osoApiKey = process.env.REACT_APP_OSO_API_KEY as string;

packages/grant-explorer/src/features/common/GenericModal.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface InfoModalProps {
1010
| React.Dispatch<React.SetStateAction<boolean>>
1111
| ((flag: boolean) => void);
1212
children?: ReactNode;
13+
isIframe?: boolean;
1314
}
1415

1516
export default function InfoModal({
@@ -57,7 +58,11 @@ export default function InfoModal({
5758
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
5859
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
5960
>
60-
<Dialog.Panel className="relative bg-white px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:max-w-lg sm:w-full sm:p-6">
61+
<Dialog.Panel
62+
className={`relative ${
63+
props.isIframe ? "" : "bg-white shadow-xl"
64+
} px-4 pt-5 pb-4 text-left overflow-hidden transform transition-all sm:my-8 sm:max-w-lg sm:w-full sm:p-6`}
65+
>
6166
<div className="sm:flex sm:items-start flex-col">
6267
<div className="mt-3 text-center sm:mt-0 sm:text-left w-full">
6368
<Dialog.Title

packages/grant-explorer/src/features/round/ViewCartPage/ChainConfirmationModalBody.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { TToken, getChainById, stringToBlobUrl } from "common";
44
import { useCartStorage } from "../../../store";
55
import { parseChainId } from "common/src/chains";
66
import { Checkbox } from "@chakra-ui/react";
7-
import { SwapParams } from "./SquidWidget";
87

98
type ChainConfirmationModalBodyProps = {
109
projectsByChain: { [chain: number]: CartProject[] };

packages/grant-explorer/src/features/round/ViewCartPage/SquidWidget.tsx

Lines changed: 29 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,50 @@
1-
import React, { useState } from 'react';
1+
import { useState } from 'react';
22

33
export type SwapParams = {
4-
initialFromChainId: number;
5-
initialToChainId: number;
4+
fromChainId: string;
5+
toChainId: string;
66
// amount: string;
7-
fromTokenAddress: string;
8-
toTokenAddress: string;
7+
fromTokenAddress?: string;
8+
toTokenAddress?: string;
99
};
1010

1111
const SquidWidget = ({
12-
integratorId = 'squid-swap-widget',
13-
companyName = 'Gitcoin',
14-
neutralContent = '#C4AEEC',
15-
baseContent = '#070002',
16-
base100 = '#ffffff',
17-
base200 = '#fafafa',
18-
base300 = '#e8e8e8',
19-
error = '#ED6A5E',
20-
warning = '#FFB155',
21-
success = '#2EAEB0',
22-
primary = '#A992EA',
23-
secondary = '#F89CC3',
24-
secondaryContent = '#F7F6FB',
25-
neutral = '#FFFFFF',
26-
roundedBtn = '26px',
27-
roundedCornerBtn = '999px',
28-
roundedBox = '1rem',
29-
roundedDropDown = '20rem',
30-
slippage = 1.5,
31-
infiniteApproval = false,
32-
enableExpress = true,
33-
apiUrl = 'https://api.squidrouter.com',
34-
comingSoonChainIds = [],
35-
iframeBackgroundColorHex = '#FFF',
36-
initialFromChainId = 1,
37-
initialToChainId = 10,
38-
fromTokenAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
39-
toTokenAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
40-
}) => {
12+
fromChainId,
13+
toChainId,
14+
fromTokenAddress,
15+
toTokenAddress,
16+
}: SwapParams) => {
17+
18+
console.log('fromChainId', fromChainId);
19+
console.log('toChainId', toChainId);
20+
console.log('fromTokenAddress', fromTokenAddress);
21+
console.log('toTokenAddress', toTokenAddress);
22+
4123
// State to manage loading
4224
const [loading, setLoading] = useState(true);
4325

4426
// Construct the config object
4527
const config = {
46-
integratorId,
47-
companyName,
48-
style: {
49-
neutralContent,
50-
baseContent,
51-
base100,
52-
base200,
53-
base300,
54-
error,
55-
warning,
56-
success,
57-
primary,
58-
secondary,
59-
secondaryContent,
60-
neutral,
61-
roundedBtn,
62-
roundedCornerBtn,
63-
roundedBox,
64-
roundedDropDown,
65-
},
66-
slippage,
67-
infiniteApproval,
68-
enableExpress,
69-
apiUrl,
70-
comingSoonChainIds,
71-
environment: 'mainnet',
72-
showOnRampLink: true,
73-
iframeBackgroundColorHex,
74-
initialFromChainId,
75-
initialToChainId,
76-
defaultTokens: [
77-
{
78-
address: fromTokenAddress,
79-
chainId: initialFromChainId,
28+
integratorId: "squid-swap-widget",
29+
instantExec: true,
30+
apiUrl: "https://apiplus.squidrouter.com",
31+
initialAssets: {
32+
from: {
33+
chainId: fromChainId,
34+
address: fromTokenAddress?.toLowerCase(),
8035
},
81-
{
82-
address: toTokenAddress,
83-
chainId: initialToChainId,
36+
to: {
37+
chainId: toChainId,
38+
address: toTokenAddress?.toLowerCase(),
8439
},
85-
],
40+
},
8641
};
8742

8843
// Convert config object to a URI-encoded JSON string
8944
const configString = encodeURIComponent(JSON.stringify(config));
9045

9146
// Construct the iframe URL
92-
const iframeUrl = `https://widget.squidrouter.com/iframe?config=${configString}`;
47+
const iframeUrl = `https://studio.squidrouter.com/iframe?config=${configString}`;
9348

9449
// Handler for when iframe loads
9550
const handleIframeLoad = () => {
@@ -98,27 +53,13 @@ const SquidWidget = ({
9853

9954
return (
10055
<div style={{ position: "relative", width: "500", height: "684px" }}>
101-
{loading && (
102-
<div
103-
style={{
104-
position: "absolute",
105-
top: "50%",
106-
left: "50%",
107-
transform: "translate(-50%, -50%)",
108-
fontSize: "18px",
109-
color: "#333",
110-
}}
111-
>
112-
Loading...
113-
</div>
114-
)}
11556
<iframe
11657
title="squid_widget"
11758
width="500"
11859
height="684"
11960
src={iframeUrl}
12061
onLoad={handleIframeLoad}
121-
style={{ display: loading ? "none" : "block" }} // Hide iframe until loaded
62+
style={{ display: "block" }}
12263
/>
12364
</div>
12465
);

packages/grant-explorer/src/features/round/ViewCartPage/SummaryContainer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-unexpected-multiline */
2-
import { getTokenPrice, NATIVE, submitPassportLite } from "common";
2+
import { getTokenPrice, submitPassportLite } from "common";
33
import { useCartStorage } from "../../../store";
44
import { useEffect, useMemo, useState } from "react";
55
import { Summary } from "./Summary";
@@ -31,7 +31,6 @@ import { useDataLayer } from "data-layer";
3131
import { isPresent } from "ts-is-present";
3232
import { getFormattedRoundId } from "../../common/utils/utils";
3333
import { datadogLogs } from "@datadog/browser-logs";
34-
import { SwapParams } from "./SquidWidget";
3534

3635
export function SummaryContainer(props: {
3736
enoughBalanceByChainId: Record<number, boolean>;

packages/grant-explorer/src/features/round/ViewCartPage/ViewCartPage.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ export default function ViewCart() {
3636
const chainIds = Object.keys(groupedCartProjects);
3737

3838
const [openSwapModel, setOpenSwapModal] = useState<boolean>(false);
39-
const [swapParams, setSwapParams] = useState<SwapParams>();
39+
const [swapParams, setSwapParams] = useState<SwapParams>(
40+
{
41+
fromChainId: "1",
42+
toChainId: "42161",
43+
fromTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
44+
toTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
45+
}
46+
);
4047

4148
const handleSwap = (params: SwapParams) => {
4249
setSwapParams(params);
@@ -208,10 +215,11 @@ export default function ViewCart() {
208215

209216
const swap = (_chainId: number | string) => {
210217
const chainId = Number(_chainId);
218+
const isConnectedChain = !connectedChain || connectedChain === chainId;
219+
211220
handleSwap({
212-
initialFromChainId:
213-
!connectedChain || connectedChain === chainId ? 1 : connectedChain,
214-
initialToChainId: chainId,
221+
fromChainId: isConnectedChain ? "1" : connectedChain.toString(),
222+
toChainId: chainId.toString(),
215223
fromTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
216224
toTokenAddress: getVotingTokenForChain(chainId).address,
217225
});
@@ -269,6 +277,7 @@ export default function ViewCart() {
269277
)}
270278
</div>
271279
<GenericModal
280+
isIframe={true}
272281
body={<SquidWidget {...swapParams} />}
273282
isOpen={openSwapModel}
274283
setIsOpen={swapModalHandler}

0 commit comments

Comments
 (0)