-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): show NEP-245 token transactions
- Loading branch information
Showing
6 changed files
with
208 additions
and
15 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
116 changes: 116 additions & 0 deletions
116
apps/app/src/components/common/NEPTokenTransactions.tsx
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,116 @@ | ||
import React from 'react'; | ||
import Link from 'next/link'; | ||
import { parseEventLogs } from '@/utils/near'; | ||
import FaRight from '../Icons/FaRight'; | ||
import { shortenAddress } from '@/utils/libs'; | ||
import TokenInfo from './TokenInfo'; | ||
import { MtEventLogData, TransactionLog } from '@/utils/types'; | ||
interface ParsedEventListProps { | ||
events: TransactionLog[]; | ||
} | ||
|
||
const NEPTokenTransactions: React.FC<ParsedEventListProps> = ({ | ||
events, | ||
}: ParsedEventListProps) => { | ||
return ( | ||
<> | ||
{events && | ||
events?.map((event: any, index: number) => { | ||
const parsedEvent: MtEventLogData = parseEventLogs(event); | ||
if ( | ||
parsedEvent?.standard === 'nep245' && | ||
Array.isArray(parsedEvent.data) | ||
) { | ||
return parsedEvent?.data?.map((data, j) => ( | ||
<div className="flex" key={`${index}-${j}`}> | ||
<div className="flex items-center flex-wrap break-all leading-7"> | ||
<FaRight className="inline-flex text-gray-400 text-xs" /> | ||
{['mt_mint', 'mt_burn'].includes(parsedEvent.event) ? ( | ||
<> | ||
<div className="font-semibold text-gray px-1"> | ||
From{' '} | ||
{'old_owner_id' in data && data?.old_owner_id ? ( | ||
<Link | ||
href={`/address/${data.old_owner_id}`} | ||
className="text-green-500 dark:text-green-250 font-normal pl-1 hover:no-underline" | ||
> | ||
{shortenAddress(data.old_owner_id)} | ||
</Link> | ||
) : ( | ||
<span className="font-normal pl-1">system</span> | ||
)} | ||
</div> | ||
<div className="font-semibold text-gray px-1"> | ||
To{' '} | ||
{'owner_id' in data && data?.owner_id ? ( | ||
<Link | ||
href={`/address/${data.owner_id}`} | ||
className="text-green-500 dark:text-green-250 font-normal pl-1" | ||
> | ||
{shortenAddress(data.owner_id)} | ||
</Link> | ||
) : ( | ||
<span className="font-normal pl-1">system</span> | ||
)} | ||
</div> | ||
</> | ||
) : ( | ||
<> | ||
<div className="font-semibold text-gray px-1"> | ||
From{' '} | ||
{'old_owner_id' in data && data?.old_owner_id ? ( | ||
<Link | ||
href={`/address/${data.old_owner_id}`} | ||
className="text-green-500 dark:text-green-250 font-normal pl-1 hover:no-underline" | ||
> | ||
{shortenAddress(data.old_owner_id)} | ||
</Link> | ||
) : ( | ||
<span className="font-normal pl-1">system</span> | ||
)} | ||
</div> | ||
<div className="font-semibold text-gray px-1"> | ||
To{' '} | ||
{'new_owner_id' in data && data?.new_owner_id ? ( | ||
<Link | ||
href={`/address/${data.new_owner_id}`} | ||
className="text-green-500 dark:text-green-250 font-normal pl-1" | ||
> | ||
{shortenAddress(data.new_owner_id)} | ||
</Link> | ||
) : ( | ||
<span className="font-normal pl-1">system</span> | ||
)} | ||
</div> | ||
</> | ||
)} | ||
<div className="flex items-center font-semibold text-gray px-1"> | ||
For{' '} | ||
<span className="flex items-center pl-1 font-normal"> | ||
<TokenInfo | ||
contract={ | ||
Array.isArray(data?.token_ids) && | ||
data.token_ids.length > 0 | ||
? data.token_ids?.[0]?.split(':')[1] | ||
: '' | ||
} | ||
amount={ | ||
Array.isArray(data?.amounts) && | ||
data.amounts.length > 0 | ||
? data.amounts[0] | ||
: '0' | ||
} | ||
/> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
)); | ||
} | ||
return null; | ||
})} | ||
</> | ||
); | ||
}; | ||
|
||
export default NEPTokenTransactions; |
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