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
78a95507
Commit
78a95507
authored
Nov 07, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
condition for view all link
parent
20090348
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
92 deletions
+49
-92
TokenTransfer.tsx
ui/shared/TokenTransfer/TokenTransfer.tsx
+2
-12
helpers.ts
ui/shared/TokenTransfer/helpers.ts
+13
-0
TxDetailsTokenTransferList.tsx
ui/tx/details/TxDetailsTokenTransferList.tsx
+0
-60
TxDetailsTokenTransfers.tsx
ui/tx/details/TxDetailsTokenTransfers.tsx
+34
-20
No files found.
ui/shared/TokenTransfer/TokenTransfer.tsx
View file @
78a95507
...
...
@@ -3,12 +3,12 @@ import type { QueryKey } from '@tanstack/react-query';
import
{
useQuery
}
from
'
@tanstack/react-query
'
;
import
React
from
'
react
'
;
import
{
TokenTransfer
}
from
'
types/api/tokenTransfer
'
;
import
type
{
TokenTransferResponse
}
from
'
types/api/tokenTransfer
'
;
import
useFetch
from
'
lib/hooks/useFetch
'
;
import
DataFetchAlert
from
'
ui/shared/DataFetchAlert
'
;
import
SkeletonTable
from
'
ui/shared/SkeletonTable
'
;
import
{
flattenTotal
}
from
'
ui/shared/TokenTransfer/helpers
'
;
import
TokenTransferList
from
'
ui/shared/TokenTransfer/TokenTransferList
'
;
import
TokenTransferSkeletonMobile
from
'
ui/shared/TokenTransfer/TokenTransferSkeletonMobile
'
;
import
TokenTransferTable
from
'
ui/shared/TokenTransfer/TokenTransferTable
'
;
...
...
@@ -52,17 +52,7 @@ const TokenTransfer = ({ isLoading: isLoadingProp, isDisabled, queryKey, path, b
return
<
Alert
>
There are no token transfers
</
Alert
>;
}
const
items
=
data
.
items
.
reduce
((
result
,
item
)
=>
{
if
(
Array
.
isArray
(
item
.
total
))
{
item
.
total
.
forEach
((
total
)
=>
{
result
.
push
({
...
item
,
total
});
});
}
else
{
result
.
push
(
item
);
}
return
result
;
},
[]
as
Array
<
TokenTransfer
>
);
const
items
=
data
.
items
.
reduce
(
flattenTotal
,
[]);
return
(
<>
...
...
ui/shared/TokenTransfer/helpers.ts
0 → 100644
View file @
78a95507
import
type
{
TokenTransfer
}
from
'
types/api/tokenTransfer
'
;
export
const
flattenTotal
=
(
result
:
Array
<
TokenTransfer
>
,
item
:
TokenTransfer
):
Array
<
TokenTransfer
>
=>
{
if
(
Array
.
isArray
(
item
.
total
))
{
item
.
total
.
forEach
((
total
)
=>
{
result
.
push
({
...
item
,
total
});
});
}
else
{
result
.
push
(
item
);
}
return
result
;
};
ui/tx/details/TxDetailsTokenTransferList.tsx
deleted
100644 → 0
View file @
20090348
import
{
Flex
,
useColorModeValue
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
type
{
TokenTransfer
}
from
'
types/api/tokenTransfer
'
;
import
TxDetailsTokenTransfer
from
'
./TxDetailsTokenTransfer
'
;
interface
Props
{
items
:
Array
<
TokenTransfer
>
;
}
function
getItemsNum
(
items
:
Array
<
TokenTransfer
>
)
{
const
nonErc1155items
=
items
.
filter
((
item
)
=>
item
.
token
.
type
!==
'
ERC-1155
'
).
length
;
const
erc1155items
=
items
.
filter
((
item
)
=>
item
.
token
.
type
===
'
ERC-1155
'
)
.
map
((
item
)
=>
{
if
(
Array
.
isArray
(
item
.
total
))
{
return
item
.
total
.
length
;
}
return
1
;
})
.
reduce
((
sum
,
item
)
=>
sum
+
item
,
0
);
return
nonErc1155items
+
erc1155items
;
}
const
TxDetailsTokenTransferList
=
({
items
}:
Props
)
=>
{
const
itemsNum
=
getItemsNum
(
items
);
const
hasScroll
=
itemsNum
>
5
;
const
gradientStartColor
=
useColorModeValue
(
'
whiteAlpha.600
'
,
'
blackAlpha.600
'
);
const
gradientEndColor
=
useColorModeValue
(
'
whiteAlpha.900
'
,
'
blackAlpha.900
'
);
return
(
<
Flex
flexDirection=
"column"
alignItems=
"flex-start"
rowGap=
{
5
}
w=
"100%"
_after=
{
hasScroll
?
{
position
:
'
absolute
'
,
content
:
'
""
'
,
bottom
:
0
,
left
:
0
,
right
:
'
20px
'
,
height
:
'
48px
'
,
bgGradient
:
`linear(to-b, ${ gradientStartColor } 37.5%, ${ gradientEndColor } 77.5%)`
,
}
:
undefined
}
maxH=
{
hasScroll
?
'
200px
'
:
'
auto
'
}
overflowY=
{
hasScroll
?
'
scroll
'
:
'
auto
'
}
pr=
{
hasScroll
?
5
:
0
}
pb=
{
hasScroll
?
10
:
0
}
>
{
items
.
map
((
item
,
index
)
=>
<
TxDetailsTokenTransfer
key=
{
index
}
{
...
item
}
/>)
}
</
Flex
>
);
};
export
default
React
.
memo
(
TxDetailsTokenTransferList
);
ui/tx/details/TxDetailsTokenTransfers.tsx
View file @
78a95507
import
{
Text
,
Icon
,
Link
,
GridItem
,
Show
}
from
'
@chakra-ui/react
'
;
import
{
Icon
,
Link
,
GridItem
,
Show
,
Flex
}
from
'
@chakra-ui/react
'
;
import
NextLink
from
'
next/link
'
;
import
React
from
'
react
'
;
...
...
@@ -7,55 +7,69 @@ import type { TokenTransfer } from 'types/api/tokenTransfer';
import
tokenIcon
from
'
icons/token.svg
'
;
import
link
from
'
lib/link/link
'
;
import
DetailsInfoItem
from
'
ui/shared/DetailsInfoItem
'
;
import
{
flattenTotal
}
from
'
ui/shared/TokenTransfer/helpers
'
;
import
TxDetailsTokenTransfer
List
from
'
./TxDetailsTokenTransferList
'
;
import
TxDetailsTokenTransfer
from
'
./TxDetailsTokenTransfer
'
;
interface
Props
{
data
:
Array
<
TokenTransfer
>
;
txHash
:
string
;
}
const
TOKEN_TRANSFERS
=
[
const
TOKEN_TRANSFERS
_TYPES
=
[
{
title
:
'
Tokens Transferred
'
,
hint
:
'
List of tokens transferred in the transaction.
'
,
type
:
'
token_transfer
'
},
{
title
:
'
Tokens Minted
'
,
hint
:
'
List of tokens minted in the transaction.
'
,
type
:
'
token_minting
'
},
{
title
:
'
Tokens Burnt
'
,
hint
:
'
List of tokens burnt in the transaction.
'
,
type
:
'
token_burning
'
},
{
title
:
'
Tokens Created
'
,
hint
:
'
List of tokens created in the transaction.
'
,
type
:
'
token_spawning
'
},
];
const
VISIBLE_ITEMS_NUM
=
3
;
const
TxDetailsTokenTransfers
=
({
data
,
txHash
}:
Props
)
=>
{
const
viewAllUrl
=
link
(
'
tx
'
,
{
id
:
txHash
},
{
tab
:
'
token_transfers
'
});
const
formattedData
=
data
.
reduce
(
flattenTotal
,
[]);
const
transferGroups
=
TOKEN_TRANSFERS_TYPES
.
map
((
group
)
=>
({
...
group
,
items
:
formattedData
?.
filter
((
token
)
=>
token
.
type
===
group
.
type
)
||
[],
}));
const
showViewAllLink
=
transferGroups
.
some
(({
items
})
=>
items
.
length
>
VISIBLE_ITEMS_NUM
);
return
(
<>
{
TOKEN_TRANSFERS
.
map
(({
title
,
hint
,
type
})
=>
{
const
items
=
data
?.
filter
((
token
)
=>
token
.
type
===
type
)
||
[];
{
transferGroups
.
map
(({
title
,
hint
,
type
,
items
})
=>
{
if
(
items
.
length
===
0
)
{
return
null
;
}
return
(
<
DetailsInfoItem
key=
{
type
}
title=
{
(
<>
<
Text
as=
"span"
>
{
title
}
</
Text
>
<
Text
as=
"span"
whiteSpace=
"pre"
variant=
"secondary"
>
(
{
items
.
length
}
)
</
Text
>
</>
)
}
title=
{
title
}
hint=
{
hint
}
position=
"relative"
>
<
TxDetailsTokenTransferList
items=
{
items
}
/>
<
Flex
flexDirection=
"column"
alignItems=
"flex-start"
rowGap=
{
5
}
w=
"100%"
>
{
items
.
slice
(
0
,
VISIBLE_ITEMS_NUM
).
map
((
item
,
index
)
=>
<
TxDetailsTokenTransfer
key=
{
index
}
{
...
item
}
/>)
}
</
Flex
>
</
DetailsInfoItem
>
);
})
}
<
Show
above=
"lg"
><
GridItem
></
GridItem
></
Show
>
<
GridItem
fontSize=
"sm"
alignItems=
"center"
display=
"inline-flex"
pl=
{
{
base
:
'
28px
'
,
lg
:
0
}
}
>
<
Icon
as=
{
tokenIcon
}
boxSize=
{
6
}
/>
<
NextLink
href=
{
viewAllUrl
}
passHref
>
<
Link
>
View all
</
Link
>
</
NextLink
>
<
Text
variant=
"secondary"
as=
"span"
whiteSpace=
"pre"
>
(
{
data
.
length
}
)
</
Text
>
</
GridItem
>
{
showViewAllLink
&&
(
<>
<
Show
above=
"lg"
><
GridItem
></
GridItem
></
Show
>
<
GridItem
fontSize=
"sm"
alignItems=
"center"
display=
"inline-flex"
pl=
{
{
base
:
'
28px
'
,
lg
:
0
}
}
>
<
Icon
as=
{
tokenIcon
}
boxSize=
{
6
}
/>
<
NextLink
href=
{
viewAllUrl
}
passHref
>
<
Link
>
View all
</
Link
>
</
NextLink
>
</
GridItem
>
</>
)
}
</>
);
};
...
...
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