Skip to content

Commit a6baf76

Browse files
committed
a
1 parent 8aa037f commit a6baf76

File tree

7 files changed

+202
-96
lines changed

7 files changed

+202
-96
lines changed

packages/lib/src/context/context.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { TwapErrorWrapper } from "../ErrorHandling";
66
import Web3 from "web3";
77
import { query } from "../hooks/query";
88
import { LimitPriceMessageContent } from "../components";
9-
import { setWeb3Instance } from "@defi.org/web3-candies";
9+
import { eqIgnoreCase, setWeb3Instance } from "@defi.org/web3-candies";
1010
import { constructSDK, DEFAULT_FILL_DELAY } from "@orbs-network/twap-sdk";
11+
import { Configs } from "@orbs-network/twap-sdk";
12+
import { useOrderQuery } from "../hooks";
1113

1214
export const TwapContext = createContext({} as TWAPContextProps);
1315
const queryClient = new QueryClient({
@@ -23,6 +25,8 @@ const WrappedTwap = (props: TwapLibProps) => {
2325
query.useFeeOnTransfer(srcToken?.address);
2426
query.useFeeOnTransfer(dstToken?.address);
2527
query.useAllowance();
28+
const { data, error } = useOrderQuery(1953);
29+
console.log({ data, error });
2630

2731
return <TwapErrorWrapper>{props.children}</TwapErrorWrapper>;
2832
};
@@ -137,6 +141,13 @@ export const Content = (props: TwapLibProps) => {
137141
);
138142
};
139143

144+
// const logConfig = () => {
145+
// const exchange = "0x846f2b29ef314bf3d667981b4ffdadc5b858312a";
146+
147+
// const res = Object.values(Configs).find((it) => eqIgnoreCase(it.exchangeAddress, exchange));
148+
// console.log({ res, Configs });
149+
// };
150+
140151
const OrdersTest = () => {
141152
const { data, fetchNextPage } = query.useAllOrders();
142153

@@ -146,7 +157,7 @@ const OrdersTest = () => {
146157
<div>
147158
{data?.pages.map((it) =>
148159
it.map((it) => {
149-
return <div style={{ color: "white" }}>{it.id}</div>;
160+
return <div style={{ color: "white" }}>{it.exchange}</div>;
150161
}),
151162
)}
152163
</div>

packages/lib/src/hooks/query.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Token } from "../types";
1010
import { useGetHasAllowance, useNetwork } from "./hooks";
1111
import { ordersStore } from "../store";
1212
import { useSrcAmount } from "./lib";
13-
import { Order, OrderStatus } from "@orbs-network/twap-sdk";
13+
import { Order, OrderStatus, getAllOrders, getOrderById } from "@orbs-network/twap-sdk";
1414
import { amountBNV2 } from "../utils";
1515

1616
export const useMinNativeTokenBalance = (minNativeTokenBalance?: string) => {
@@ -152,6 +152,23 @@ const useOrderHistoryKey = () => {
152152
return [QueryKeys.GET_ORDER_HISTORY, account, config.exchangeAddress, config.chainId];
153153
};
154154

155+
export const useOrderQuery = (orderId?: number) => {
156+
const chainId = useTwapContext().config.chainId;
157+
return useQuery(
158+
["useOrderQuery", chainId, chainId],
159+
async ({ signal }) => {
160+
if (!orderId) return null;
161+
const result = await getOrderById({ orderId: 79202, chainId: 56, signal });
162+
console.log({ result });
163+
164+
return result;
165+
},
166+
{
167+
enabled: !!orderId && !!chainId,
168+
},
169+
);
170+
};
171+
155172
const useUpdateOrderStatusToCanceled = () => {
156173
const QUERY_KEY = useOrderHistoryKey();
157174
const queryClient = useQueryClient();
@@ -171,13 +188,14 @@ const useUpdateOrderStatusToCanceled = () => {
171188
};
172189

173190
export const useAllOrders = () => {
174-
const { state, config, account, twapSDK } = useTwapContext();
191+
const { config } = useTwapContext();
175192
return useInfiniteQuery(
176193
["all orders", config.chainId],
177194
async ({ signal, pageParam = 0 }) => {
178195
let result: Order[] = [];
179196
try {
180-
result = await twapSDK.getAllOrders({ signal, page: pageParam, limit: 5 });
197+
result = await getAllOrders({ signal, page: pageParam, limit: 5, chainId: config.chainId });
198+
console.log({ result });
181199
} catch (error) {
182200
console.log({ error });
183201
}

packages/lib/src/hooks/useConfirmationButton.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ export const useConfirmationButton = (connect?: () => void) => {
5656
disabled: false,
5757
};
5858

59-
// if (hasWarning)
60-
// return {
61-
// text: warning.zeroSrcAmount ? warning.zeroSrcAmount : warning.balance || translations.placeOrder,
62-
// onClick: undefined,
63-
// disabled: true,
64-
// loading: false,
65-
// };
59+
if (hasWarning)
60+
return {
61+
text: warning.zeroSrcAmount ? warning.zeroSrcAmount : warning.balance || translations.placeOrder,
62+
onClick: undefined,
63+
disabled: true,
64+
loading: false,
65+
};
6666
if (disableWhileLaoding) {
6767
return { text: translations.placeOrder, onClick: undefined, loading: true };
6868
}

packages/sdk/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export * from "./lib/types";
44
export * from "./lib/consts";
55
export { constructSDK, TwapSDK } from "./lib/constructSDK";
66
export { DEFAULT_FILL_DELAY } from "./lib/lib";
7-
export { groupOrdersByStatus } from "./lib/orders";
7+
export { groupOrdersByStatus, getAllOrders, getOrderFillDelay, getConfigFromExchangeAddress, getOrderById } from "./lib/orders";
88

99
export { Configs, TwapAbi };

packages/sdk/src/lib/constructSDK.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Analytics } from "./analytics";
22
import { getEstimatedDelayBetweenChunksMillis, derivedSwapValues, prepareOrderArgs, getDeadline } from "./lib";
3-
import { getOrders, waitForOrdersUpdate } from "./orders";
3+
import { getOrders, getUserOrders, waitForOrdersUpdate } from "./orders";
44
import { Config, DerivedSwapValuesArgs, Order, PrepareOrderArgs, TimeDuration } from "./types";
55

66
interface Props {
@@ -49,11 +49,7 @@ export class TwapSDK {
4949
}
5050

5151
async getUserOrders({ account, signal, page, limit }: { account: string; signal?: AbortSignal; page?: number; limit?: number }) {
52-
return getOrders({ config: this.config, account, signal, page, limit });
53-
}
54-
55-
async getAllOrders({ signal, page, limit }: { signal?: AbortSignal; page?: number; limit?: number }) {
56-
return getOrders({ config: this.config, signal, page, limit });
52+
return getUserOrders({ config: this.config, account, signal, page, limit });
5753
}
5854

5955
async waitForOrdersUpdate(orderId: number, account: string, signal?: AbortSignal) {

0 commit comments

Comments
 (0)