-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support hide scam transactions (#1811)
* feat: filter scam * chore: i18n * feat: update rabby-api * chore: change hover style * fix: i18n
- Loading branch information
Showing
14 changed files
with
323 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
import { last } from 'lodash'; | ||
import React, { useRef } from 'react'; | ||
import { Trans, useTranslation } from 'react-i18next'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { useAccount } from '@/ui/store-hooks'; | ||
import { useInfiniteScroll } from 'ahooks'; | ||
import { Virtuoso } from 'react-virtuoso'; | ||
import { Empty, Modal } from 'ui/component'; | ||
import { useWallet } from 'ui/utils'; | ||
import { HistoryItem, HistoryItemActionContext } from './HistoryItem'; | ||
import { Loading } from './Loading'; | ||
|
||
const PAGE_COUNT = 10; | ||
|
||
export const HistoryList = ({ | ||
isMainnet = true, | ||
isFilterScam = false, | ||
}: { | ||
isMainnet?: boolean; | ||
isFilterScam?: boolean; | ||
}) => { | ||
const wallet = useWallet(); | ||
const { t } = useTranslation(); | ||
|
||
const ref = useRef<HTMLDivElement | null>(null); | ||
const [account] = useAccount(); | ||
|
||
const getAllTxHistory = ( | ||
params: Parameters<typeof wallet.openapi.getAllTxHistory>[0] | ||
) => { | ||
const getHistory = isMainnet | ||
? wallet.openapi.getAllTxHistory | ||
: wallet.testnetOpenapi.getAllTxHistory; | ||
|
||
return getHistory(params).then((res) => { | ||
if (res.history_list) { | ||
res.history_list = res.history_list.filter((item) => { | ||
return !item.is_scam; | ||
}); | ||
} | ||
return res; | ||
}); | ||
}; | ||
|
||
const fetchData = async (startTime = 0) => { | ||
const { address } = account!; | ||
|
||
const getHistory = isFilterScam | ||
? getAllTxHistory | ||
: isMainnet | ||
? wallet.openapi.listTxHisotry | ||
: wallet.testnetOpenapi.listTxHisotry; | ||
|
||
const res = await getHistory({ | ||
id: address, | ||
start_time: !isFilterScam ? startTime : undefined, | ||
}); | ||
|
||
const { project_dict, cate_dict, history_list: list } = res; | ||
const displayList = list | ||
.map((item) => ({ | ||
...item, | ||
projectDict: project_dict, | ||
cateDict: cate_dict, | ||
tokenDict: 'token_dict' in res ? res.token_dict : undefined, | ||
tokenUUIDDict: | ||
'token_uuid_dict' in res ? res.token_uuid_dict : undefined, | ||
})) | ||
.sort((v1, v2) => v2.time_at - v1.time_at); | ||
return { | ||
last: last(displayList)?.time_at, | ||
list: displayList, | ||
}; | ||
}; | ||
|
||
const { data, loading, loadingMore, loadMore } = useInfiniteScroll( | ||
(d) => fetchData(d?.last), | ||
{ | ||
isNoMore: (d) => { | ||
return isFilterScam | ||
? true | ||
: !d?.last || (d?.list.length || 0) < PAGE_COUNT; | ||
}, | ||
} | ||
); | ||
|
||
const isEmpty = (data?.list?.length || 0) <= 0 && !loading; | ||
|
||
const [ | ||
focusingHistoryItem, | ||
setFocusingHistoryItem, | ||
] = React.useState<HistoryItemActionContext | null>(null); | ||
|
||
return ( | ||
<div className="overflow-auto h-full" ref={ref}> | ||
<Modal | ||
visible={!!focusingHistoryItem} | ||
// View Message | ||
title={t('page.transactions.modalViewMessage.title')} | ||
className="view-tx-message-modal" | ||
onCancel={() => { | ||
setFocusingHistoryItem(null); | ||
}} | ||
maxHeight="360px" | ||
> | ||
<div className="parsed-content text-14"> | ||
{focusingHistoryItem?.parsedInputData} | ||
</div> | ||
</Modal> | ||
|
||
{loading ? ( | ||
<div className={isFilterScam ? 'pt-[20px]' : ''}> | ||
{isFilterScam ? ( | ||
<div className="filter-scam-loading-text"> | ||
{t('page.transactions.filterScam.loading')} | ||
</div> | ||
) : null} | ||
<Loading count={4} active /> | ||
</div> | ||
) : ( | ||
<> | ||
{isEmpty ? ( | ||
<Empty | ||
title={t('page.transactions.empty.title')} | ||
desc={ | ||
<span> | ||
<Trans i18nKey="page.transactions.empty.desc" t={t}> | ||
No transactions found on | ||
<Link className="underline" to="/settings/chain-list"> | ||
supported chains | ||
</Link> | ||
</Trans> | ||
</span> | ||
} | ||
className="pt-[108px]" | ||
></Empty> | ||
) : ( | ||
<Virtuoso | ||
style={{ | ||
height: '100%', | ||
}} | ||
data={data?.list || []} | ||
itemContent={(_, item) => { | ||
return ( | ||
<HistoryItem | ||
data={item} | ||
projectDict={item.projectDict} | ||
cateDict={item.cateDict} | ||
tokenDict={item.tokenDict || item.tokenUUIDDict || {}} | ||
key={item.id} | ||
onViewInputData={setFocusingHistoryItem} | ||
isTestnet={!isMainnet} | ||
/> | ||
); | ||
}} | ||
endReached={loadMore} | ||
components={{ | ||
Footer: () => { | ||
if (loadingMore) { | ||
return <Loading count={4} active />; | ||
} | ||
return null; | ||
}, | ||
}} | ||
></Virtuoso> | ||
)} | ||
</> | ||
)} | ||
</div> | ||
); | ||
}; |
File renamed without changes.
Oops, something went wrong.