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

[FRE-937, FRE-950, FRE-953, FRE-954, FRE-957] feat(widget-v2): add skip client #193

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/forty-crews-relax.md
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to add changeset in previous PR #188, let's bump it with this PR

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@skip-go/widget': patch
---

inject connected wallet from parent prop
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"eslint.format.enable": true
"eslint.format.enable": true,
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
}
12 changes: 12 additions & 0 deletions packages/widget-v2/src/constants/skipClientDefault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const appUrl = "https://go.skip.build";

export const endpointOptions = {
getRpcEndpointForChain: async (chainID: string) => {
return `${appUrl}/api/rpc/${chainID}`;
},
getRestEndpointForChain: async (chainID: string) => {
return `${appUrl}/api/rest/${chainID}`;
},
};

export const apiURL = `${appUrl}/api/widget/skip`;
78 changes: 70 additions & 8 deletions packages/widget-v2/src/state/skipClient.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import { atom } from "jotai";
import { Asset, SkipClient, Chain } from "@skip-go/client";
import {
Asset,
SkipClient,
Chain,
RouteRequest,
SkipClientOptions,
} from "@skip-go/client";
import { atomWithQuery } from "jotai-tanstack-query";
import { apiURL, endpointOptions } from "@/constants/skipClientDefault";

export const skipClientConfigAtom = atom<SkipClientOptions>({
apiURL,
endpointOptions,
});

export const skipClient = atom(new SkipClient());
export const skipClient = atom((get) => {
const options = get(skipClientConfigAtom);
return new SkipClient(options);
});

export type ClientAsset = Asset & {
chain_key: string;
chainName: string;
};

const flattenData = (data: Record<string, Asset[] >, chains?: Chain[]) => {
const flattenData = (data: Record<string, Asset[]>, chains?: Chain[]) => {
const flattenedData: ClientAsset[] = [];

for (const chainKey in data) {
Expand All @@ -19,7 +33,8 @@ const flattenData = (data: Record<string, Asset[] >, chains?: Chain[]) => {
flattenedData.push({
...asset,
chain_key: chainKey,
chainName: chain?.prettyName ?? chain?.chainName ?? asset.chainID ?? "--",
chainName:
chain?.prettyName ?? chain?.chainName ?? asset.chainID ?? "--",
});
});
}
Expand Down Expand Up @@ -53,10 +68,57 @@ export const skipChainsAtom = atomWithQuery((get) => {
return skip.chains({
includeEVM: true,
includeSVM: true,
})
}
}
})
});
},
};
});

export const skipBridgesAtom = atomWithQuery((get) => {
const skip = get(skipClient);
return {
queryKey: ["skipBridges"],
queryFn: async () => {
return skip.bridges();
},
};
});

export const skipSwapVenuesAtom = atomWithQuery((get) => {
const skip = get(skipClient);
return {
queryKey: ["skipSwapVenue"],
queryFn: async () => {
return skip.venues();
},
};
});

export const skipRouteRequestAtom = atom<RouteRequest>();

export const skipRouteAtom = atomWithQuery((get) => {
const skip = get(skipClient);
const params = get(skipRouteRequestAtom);
return {
queryKey: ["skipRoute", params],
queryFn: async () => {
if (!params) {
throw new Error("No route request provided");
}
return skip.route({
...params,
smartRelay: true,
smartSwapOptions: {
splitRoutes: true,
evmSwaps: true,
},
experimentalFeatures: ["hyperlane"],
allowMultiTx: true,
allowUnsafe: true,
});
},
enabled: !!params,
};
});

export type ChainWithAsset = Chain & {
asset?: ClientAsset;
Expand Down
Loading