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

Add chainlink oracle to the UI #16

Merged
merged 6 commits into from
Mar 12, 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"test:watch": "pnpm exec jest --watchAll --verbose"
},
"dependencies": {
"@bleu-fi/ui": "^0.1.33",
"@bleu-fi/ui": "^0.1.48",
"@cowprotocol/app-data": "^1.2.2",
"@graphql-codegen/typescript-operations": "^4.2.0",
"@hookform/resolvers": "^3.3.4",
Expand Down
103 changes: 85 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 76 additions & 2 deletions src/app/builder/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,85 @@
"use client";

import { ReactFlowProvider } from "reactflow";
import { useSafeAppsSDK } from "@safe-global/safe-apps-react-sdk";
import { useEffect, useState } from "react";
import { Node, ReactFlowProvider } from "reactflow";
import { Address } from "viem";

import { Board } from "#/components/Board";
import { defaultEdgeProps } from "#/components/edges";
import Menu from "#/components/menus";
import { defaultNodeProps } from "#/components/nodes";
import { getDefaultStopLossData } from "#/components/nodes/StopLossNode";
import { getDefaultSwapData } from "#/components/nodes/SwapNode";
import { Spinner } from "#/components/Spinner";
import { ChainId } from "#/lib/publicClients";
import { INodeData } from "#/lib/types";

const createInitNodes = async (chainId: ChainId, safeAddress: Address) => {
const swapData = getDefaultSwapData(chainId, safeAddress);
const conditionData = await getDefaultStopLossData({
chainId,
tokenBuy: swapData.tokenBuy,
tokenSell: swapData.tokenSell,
});

return [
{
id: "condition",
type: "stopLoss",
data: conditionData,
...defaultNodeProps,
},
{
id: "swap",
type: "swap",
data: swapData,
...defaultNodeProps,
},
{
id: "end",
type: "endNode",
selectable: false,
...defaultNodeProps,
},
] as Node<INodeData>[];
};

const initEdges = [
{
id: "condition-swap",
source: "condition",
target: "swap",
type: "addHook",
...defaultEdgeProps,
},
{
id: "swap-end",
source: "swap",
target: "end",
type: "addHook",
...defaultEdgeProps,
},
];

export default function PlaygroundPage() {
const {
safe: { safeAddress, chainId },
} = useSafeAppsSDK();
const [initNodes, setInitNodes] = useState<Node<INodeData>[]>([]);

useEffect(() => {
createInitNodes(chainId as ChainId, safeAddress as Address).then(
(nodes) => {
setInitNodes(nodes);
}
);
}, [chainId, safeAddress]);

if (initNodes.length === 0) {
return <Spinner />;
}

return (
<div className="hidden h-full flex-col md:flex text-white">
<ReactFlowProvider>
Expand All @@ -17,7 +91,7 @@ export default function PlaygroundPage() {
<div className="md:order-1">
<div className="flex h-full flex-col space-y-4">
<div className="h-full">
<Board />
<Board initNodes={initNodes} initEdges={initEdges} />
</div>
</div>
</div>
Expand Down
Loading
Loading