Skip to content

Commit

Permalink
fix: build error && swap default token
Browse files Browse the repository at this point in the history
  • Loading branch information
junjieit committed Oct 18, 2024
1 parent bf4bf07 commit 9c8e63f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/doc/src/stories/widgets/Config.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ Primary.args = {
projectId: 'project2',
apiKey: 'ee53d6b75b12aceed4',
hasOrder: true,
onlyChainId: 56,
onlyChainId: 167000,
};
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,23 @@ function TransactionTime({
}
return `${sec}s`;
}, [time]);
const t = useRef<NodeJS.Timer>();
const t = useRef<number>();
useEffect(() => {
if (isStarted) {
setTime(0);
clearInterval(t.current);
t.current = setInterval(() => {
window.clearInterval(t.current);
t.current = window.setInterval(() => {
setTime((i) => i + 1);
}, 1000);
}
return () => {
clearInterval(t.current);
window.clearInterval(t.current);
};
}, [isStarted]);

useEffect(() => {
if (isEnded) {
clearInterval(t.current);
window.clearInterval(t.current);
}
}, [isEnded]);

Expand Down Expand Up @@ -237,7 +237,9 @@ export default function WithExecutionDialog({
};
const dispatch = useDispatch<AppThunkDispatch>();

const noSubmissionDialog = useUserOptions(state => state.noSubmissionDialog);
const noSubmissionDialog = useUserOptions(
(state) => state.noSubmissionDialog,
);

return (
<ExecutionContext.Provider value={ctxVal}>
Expand Down
16 changes: 12 additions & 4 deletions packages/dodoex-widgets/src/hooks/Swap/useInitDefaultToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ function getDefaultToken({
}) {
let findToken = null as TokenInfo | null;
let setDefaultAmount: number | undefined;
const tokenListTarget = tokenList.filter(
let tokenListTarget = tokenList.filter(
(token) =>
(!token.side || token.side === side) &&
(!chainId || token.chainId === chainId),
);
if (!tokenListTarget.length) {
tokenListTarget = tokenList.filter(
(token) => !token.side || token.side === side,
);
}
if (tokenListTarget.length) {
let needFindToken = getLastToken(side);
if (!needFindToken && defaultToken) {
Expand Down Expand Up @@ -77,20 +82,22 @@ export function useInitDefaultToken({
setIsReverseRouting: React.Dispatch<React.SetStateAction<boolean>>;
}) {
const tokenList = useSelector(getTokenList);
const { crossChain, defaultFromToken, defaultToToken } = useUserOptions();
const { crossChain, defaultFromToken, defaultToToken, onlyChainId } =
useUserOptions();
const autoConnectLoading = useSelector(getAutoConnectLoading);
const { chainId, isActivating } = useWeb3React();

const initToken = () => {
let findFromToken: TokenInfo | null = null;
let setDefaultFromAmount: number | undefined;
if (!crossChain && autoConnectLoading) return;
const findChainId = crossChain ? undefined : onlyChainId ?? chainId;
if (!fromToken) {
const result = getDefaultToken({
side: 'from',
defaultToken: defaultFromToken,
tokenList,
chainId: crossChain ? undefined : chainId,
chainId: findChainId,
});
findFromToken = result.findToken;
setDefaultFromAmount = result.setDefaultAmount;
Expand All @@ -110,7 +117,7 @@ export function useInitDefaultToken({
defaultToken: defaultToToken,
tokenList,
occupyToken: findFromToken,
chainId: crossChain ? undefined : chainId,
chainId: findChainId,
});
if (findToToken) {
setToToken(findToToken);
Expand Down Expand Up @@ -140,6 +147,7 @@ export function useInitDefaultToken({
crossChain,
autoConnectLoading,
chainId,
onlyChainId,
isActivating,
]);
}
6 changes: 3 additions & 3 deletions packages/dodoex-widgets/src/locales/en-US.po
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ msgid "Start Time"
msgstr "Start Time"

#: src/components/ErrorMessageDialog.tsx:63
#: src/components/WithExecutionDialog/index.tsx:316
#: src/components/WithExecutionDialog/index.tsx:318
msgid "Dismiss"
msgstr "Dismiss"

Expand Down Expand Up @@ -1336,7 +1336,7 @@ msgid "The mid price needs to be greater than {min} and less than 100,000,000"
msgstr "The mid price needs to be greater than {min} and less than 100,000,000"

#: src/components/ErrorMessageDialog.tsx:39
#: src/components/WithExecutionDialog/index.tsx:281
#: src/components/WithExecutionDialog/index.tsx:283
msgid "Something went wrong."
msgstr "Something went wrong."

Expand Down Expand Up @@ -1645,7 +1645,7 @@ msgstr "Hours"
msgid "High"
msgstr "High"

#: src/components/WithExecutionDialog/index.tsx:316
#: src/components/WithExecutionDialog/index.tsx:318
msgid "Close"
msgstr "Close"

Expand Down
6 changes: 3 additions & 3 deletions packages/dodoex-widgets/src/locales/zh-CN.po
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ msgid "Start Time"
msgstr ""

#: src/components/ErrorMessageDialog.tsx:63
#: src/components/WithExecutionDialog/index.tsx:316
#: src/components/WithExecutionDialog/index.tsx:318
msgid "Dismiss"
msgstr "忽略"

Expand Down Expand Up @@ -1336,7 +1336,7 @@ msgid "The mid price needs to be greater than {min} and less than 100,000,000"
msgstr ""

#: src/components/ErrorMessageDialog.tsx:39
#: src/components/WithExecutionDialog/index.tsx:281
#: src/components/WithExecutionDialog/index.tsx:283
msgid "Something went wrong."
msgstr "发生异常错误."

Expand Down Expand Up @@ -1645,7 +1645,7 @@ msgstr "小时"
msgid "High"
msgstr ""

#: src/components/WithExecutionDialog/index.tsx:316
#: src/components/WithExecutionDialog/index.tsx:318
msgid "Close"
msgstr "关闭"

Expand Down
10 changes: 8 additions & 2 deletions packages/dodoex-widgets/src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { create } from 'zustand';
import { Page } from './types';
import { Page, PageType } from './types';

export { PageType } from './types';
export type { Page } from './types';
Expand All @@ -17,9 +17,15 @@ export const useRouterStore = create<RouterState>((set, get) => ({
historyList: [],
push: (page: Page) => {
set((oldState) => {
const historyList = [
...oldState.historyList,
oldState.page ?? {
type: PageType.Pool,
},
];
return {
page,
historyList: [...oldState.historyList, page],
historyList,
};
});
},
Expand Down

0 comments on commit 9c8e63f

Please sign in to comment.