Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
682dfe0c
Commit
682dfe0c
authored
Mar 28, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flatten erc1155 batch total
parent
e79b8d32
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
12 deletions
+58
-12
txStateChanges.ts
types/api/txStateChanges.ts
+21
-7
utils.tsx
ui/tx/state/utils.tsx
+37
-5
No files found.
types/api/txStateChanges.ts
View file @
682dfe0c
...
...
@@ -17,10 +17,7 @@ export interface TxStateChangeCoin {
export
type
TxStateChangeToken
=
TxStateChangeTokenErc20
|
TxStateChangeTokenErc721
|
TxStateChangeTokenErc1155
;
type
NftTokenChange
<
T
>
=
{
direction
:
'
from
'
|
'
to
'
;
total
:
T
;
}
type
ChangeDirection
=
'
from
'
|
'
to
'
;
export
interface
TxStateChangeTokenErc20
{
type
:
'
token
'
;
...
...
@@ -31,13 +28,30 @@ export interface TxStateChangeTokenErc20 {
export
interface
TxStateChangeTokenErc721
{
type
:
'
token
'
;
token
:
TokenInfo
<
'
ERC-721
'
>
;
change
:
Array
<
NftTokenChange
<
Erc721TotalPayload
>>
;
change
:
Array
<
{
direction
:
ChangeDirection
;
total
:
Erc721TotalPayload
;
}
>
;
}
export
type
TxStateChangeTokenErc1155
=
TxStateChangeTokenErc1155Single
|
TxStateChangeTokenErc1155Batch
;
export
interface
TxStateChangeTokenErc1155Single
{
type
:
'
token
'
;
token
:
TokenInfo
<
'
ERC-1155
'
>
;
change
:
Array
<
{
direction
:
ChangeDirection
;
total
:
Erc1155TotalPayload
;
}
>
;
}
export
interface
TxStateChangeTokenErc1155
{
export
interface
TxStateChangeTokenErc1155
Batch
{
type
:
'
token
'
;
token
:
TokenInfo
<
'
ERC-1155
'
>
;
change
:
Array
<
NftTokenChange
<
Erc1155TotalPayload
>>
;
change
:
Array
<
{
direction
:
ChangeDirection
;
total
:
Array
<
Erc1155TotalPayload
>
;
}
>
;
}
export
type
TxStateChanges
=
Array
<
TxStateChange
>
;
ui/tx/state/utils.tsx
View file @
682dfe0c
...
...
@@ -2,7 +2,8 @@ import { Box, Flex } from '@chakra-ui/react';
import
BigNumber
from
'
bignumber.js
'
;
import
React
from
'
react
'
;
import
type
{
TxStateChange
}
from
'
types/api/txStateChanges
'
;
import
type
{
TxStateChange
,
TxStateChangeTokenErc1155
,
TxStateChangeTokenErc1155Single
,
TxStateChangeTokenErc721
}
from
'
types/api/txStateChanges
'
;
import
type
ArrayElement
from
'
types/utils/ArrayElement
'
;
import
appConfig
from
'
configs/app/config
'
;
import
{
ZERO_ADDRESS
}
from
'
lib/consts
'
;
...
...
@@ -62,7 +63,6 @@ export function getStateElements(data: TxStateChange) {
const
difference
=
after
-
before
;
const
changeColor
=
difference
>=
0
?
'
green.500
'
:
'
red.500
'
;
const
changeSign
=
difference
>=
0
?
'
+
'
:
'
-
'
;
const
tokenIdValue
=
Array
.
isArray
(
data
.
change
)
?
data
.
change
[
0
].
total
.
token_id
:
null
;
const
change
=
(()
=>
{
if
(
!
before
&&
!
after
&&
data
.
address
.
hash
===
ZERO_ADDRESS
)
{
...
...
@@ -86,6 +86,27 @@ export function getStateElements(data: TxStateChange) {
return
<
Box
color=
{
changeColor
}
>
{
changeSign
}{
nbsp
}{
Math
.
abs
(
difference
).
toLocaleString
()
}
</
Box
>;
})();
const
tokenId
=
(()
=>
{
if
(
!
Array
.
isArray
(
data
.
change
))
{
return
null
;
}
return
(
data
.
change
as
Array
<
TxStateChangeNftItem
>
)
.
reduce
(
flattenTotal
,
[])
.
map
((
change
,
index
)
=>
{
return
(
<
TokenTransferNft
key=
{
index
}
hash=
{
data
.
token
.
address
}
id=
{
change
.
total
.
token_id
}
w=
"auto"
truncation=
"constant"
my=
{
{
base
:
'
-3px
'
,
lg
:
0
}
}
/>
);
});
})();
return
{
before
:
data
.
balance_before
?
(
<
Flex
whiteSpace=
"pre-wrap"
justifyContent=
{
{
base
:
'
flex-start
'
,
lg
:
'
flex-end
'
}
}
>
...
...
@@ -101,10 +122,21 @@ export function getStateElements(data: TxStateChange) {
)
:
null
,
change
,
hint
,
tokenId
:
tokenIdValue
?
<
TokenTransferNft
hash=
{
data
.
token
.
address
}
id=
{
tokenIdValue
}
w=
"auto"
truncation=
"constant"
my=
{
{
base
:
'
-3px
'
,
lg
:
0
}
}
/>
:
null
,
tokenId
,
};
}
}
}
type
TxStateChangeNftItem
=
ArrayElement
<
TxStateChangeTokenErc721
[
'
change
'
]
|
TxStateChangeTokenErc1155
[
'
change
'
]
>
;
type
TxStateChangeNftItemFlatten
=
ArrayElement
<
TxStateChangeTokenErc721
[
'
change
'
]
|
TxStateChangeTokenErc1155Single
[
'
change
'
]
>
;
function
flattenTotal
(
result
:
Array
<
TxStateChangeNftItemFlatten
>
,
item
:
TxStateChangeNftItem
):
Array
<
TxStateChangeNftItemFlatten
>
{
if
(
Array
.
isArray
(
item
.
total
))
{
result
.
push
(...
item
.
total
.
map
((
total
)
=>
({
...
item
,
total
})));
}
else
{
result
.
push
({
...
item
,
total
:
item
.
total
});
}
return
result
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment