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

Fix incorrect order of rejected deposits #282

Closed
wants to merge 1 commit into from
Closed
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
32 changes: 22 additions & 10 deletions apps/godwoken-bridge/src/components/Deposit/List.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import styled from "styled-components";
import React, { useEffect, useRef } from "react";
import React, { useEffect, useRef, useState } from "react";
import { Navigate, useNavigate, useParams } from "react-router-dom";
import { number } from "@ckb-lumos/codec";
import { useInfiniteScroll } from "ahooks";
import { useDeepCompareEffect, useInfiniteScroll } from "ahooks";
import { format } from "date-fns";
import { AxiosError } from "axios";
import { LightGodwoken } from "light-godwoken";
Expand All @@ -16,6 +16,7 @@ import { Empty } from "../Container/Empty";
const DepositListDiv = styled.div`
border-bottom-left-radius: 24px;
border-bottom-right-radius: 24px;

.list {
max-height: 500px;
min-height: 50px;
Expand All @@ -31,6 +32,7 @@ export interface DepositListParams {
export const DepositList: React.FC<DepositListParams> = ({ depositList, isLoading }) => {
const lightGodwoken = useLightGodwoken();
const cancelTimeout = lightGodwoken?.getCancelTimeout() || 0;
const [completedList, setCompletedList] = useState<DepositHistoryType[]>([]);

const listRef = useRef<HTMLDivElement>(null);
const depositHistory = useInfiniteScroll(
Expand Down Expand Up @@ -77,7 +79,22 @@ export const DepositList: React.FC<DepositListParams> = ({ depositList, isLoadin
const depositHistoryList = depositHistory.data?.list ?? [];
const depositHistoryTxHashes = depositHistoryList.map((history) => history.txHash);
const isListLoading = isLoading || depositHistory.loading || depositHistory.loadingMore;

useDeepCompareEffect(() => {
const res = depositList.filter(
(item) => item.status !== "pending" && !depositHistoryTxHashes.includes(item.txHash),
);
const list = [...depositHistoryList, ...res];
list.sort((a, b) => {
if (a.date < b.date) {
return 1;
} else if (a.date > b.date) {
return -1;
} else {
return 0;
}
});
setCompletedList(list);
}, [depositHistoryList, depositList]);
const params = useParams();
const navigate = useNavigate();
const isPending = params.status === "pending";
Expand All @@ -87,9 +104,7 @@ export const DepositList: React.FC<DepositListParams> = ({ depositList, isLoadin
}

const pendingList = depositList.filter((history) => history.status === "pending");
const completedList = depositList.filter((history) => {
return history.status !== "pending" && !depositHistoryTxHashes.includes(history.txHash);
});

function navigateStatus(targetStatus: "pending" | "completed") {
navigate(`/${params.version}/deposit/${targetStatus}`);
}
Expand Down Expand Up @@ -122,13 +137,10 @@ export const DepositList: React.FC<DepositListParams> = ({ depositList, isLoadin
)}
{isCompleted && (
<div ref={listRef} className="list completed-list">
{!completedList.length && !depositHistoryList.length && <Empty>No completed deposits</Empty>}
{completedList.length === 0 && <Empty>No completed deposits</Empty>}
{completedList.map((deposit, index) => (
<DepositItem {...deposit} key={index}></DepositItem>
))}
{depositHistoryList.map((deposit, index) => (
<DepositItem {...deposit} key={index}></DepositItem>
))}
</div>
)}
{isListLoading && <Placeholder />}
Expand Down