Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Block Explorer UI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
Block Explorer UI
Commits
051a59d2
Commit
051a59d2
authored
1 month ago
by
Dima Rifai
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#479
- Use aggregated balance history instead of balance history
parent
3ee0cb02
No related branches found
No related tags found
1 merge request
!587
Delrifai/#479 use aggregated balance api
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
components/account/AccountBalanceHistoryCard.tsx
+51
-103
51 additions, 103 deletions
components/account/AccountBalanceHistoryCard.tsx
with
51 additions
and
103 deletions
components/account/AccountBalanceHistoryCard.tsx
+
51
−
103
View file @
051a59d2
...
...
@@ -10,6 +10,7 @@ import { useRouter } from "next/router";
import
{
Loader2
}
from
"
lucide-react
"
;
import
NoResult
from
"
../NoResult
"
;
import
{
Button
}
from
"
../ui/button
"
;
import
useAggregatedBalanceHistory
from
"
@/hooks/api/balanceHistory/useAggregatedHistory
"
;
// Define the type for balance operation data
type
AccountBalanceHistoryCardProps
=
{
...
...
@@ -30,42 +31,39 @@ const AccountBalanceHistoryCard: React.FC<AccountBalanceHistoryCardProps> = ({
const
accountNameFromRoute
=
(
router
.
query
.
accountName
as
string
)?.
slice
(
1
);
const
{
accountBalanceHistory
:
hiveBalanceHistory
,
isAccountBalanceHistoryLoading
:
hiveBalanceHistoryLoading
,
isAccountBalanceHistoryError
:
hiveBalanceHistoryError
,
}
=
useBalanceHistory
(
a
ggregatedA
ccountBalanceHistory
:
hiveBalanceHistory
,
isA
ggregatedA
ccountBalanceHistoryLoading
:
hiveBalanceHistoryLoading
,
isA
ggregatedA
ccountBalanceHistoryError
:
hiveBalanceHistoryError
,
}
=
use
Aggregated
BalanceHistory
(
accountNameFromRoute
,
"
HIVE
"
,
undefined
,
undefined
,
"
desc
"
,
defaultFromDate
"
daily
"
,
"
asc
"
,
defaultFromDate
,
);
const
{
accountBalanceHistory
:
vestsBalanceHistory
,
isAccountBalanceHistoryLoading
:
vestsBalanceHistoryLoading
,
isAccountBalanceHistoryError
:
vestsBalanceHistoryError
,
}
=
useBalanceHistory
(
a
ggregatedA
ccountBalanceHistory
:
vestsBalanceHistory
,
isA
ggregatedA
ccountBalanceHistoryLoading
:
vestsBalanceHistoryLoading
,
isA
ggregatedA
ccountBalanceHistoryError
:
vestsBalanceHistoryError
,
}
=
use
Aggregated
BalanceHistory
(
accountNameFromRoute
,
"
VESTS
"
,
undefined
,
undefined
,
"
desc
"
,
defaultFromDate
"
daily
"
,
"
asc
"
,
defaultFromDate
,
);
const
{
accountBalanceHistory
:
hbdBalanceHistory
,
isAccountBalanceHistoryLoading
:
hbdBalanceHistoryLoading
,
isAccountBalanceHistoryError
:
hbdBalanceHistoryError
,
}
=
useBalanceHistory
(
a
ggregatedA
ccountBalanceHistory
:
hbdBalanceHistory
,
isA
ggregatedA
ccountBalanceHistoryLoading
:
hbdBalanceHistoryLoading
,
isA
ggregatedA
ccountBalanceHistoryError
:
hbdBalanceHistoryError
,
}
=
use
Aggregated
BalanceHistory
(
accountNameFromRoute
,
"
HBD
"
,
undefined
,
undefined
,
"
desc
"
,
defaultFromDate
"
VESTS
"
,
"
daily
"
,
"
asc
"
,
defaultFromDate
,
);
const
handleBalancesVisibility
=
()
=>
{
...
...
@@ -77,90 +75,40 @@ const AccountBalanceHistoryCard: React.FC<AccountBalanceHistoryCardProps> = ({
vestsBalanceHistoryLoading
||
hbdBalanceHistoryLoading
;
const
hasData
=
hiveBalanceHistory
?.
operations_result
?.
length
>
0
||
vestsBalanceHistory
?.
operations_result
?.
length
>
0
||
hbdBalanceHistory
?.
operations_result
?.
length
>
0
;
hiveBalanceHistory
||
vestsBalanceHistory
||
hbdBalanceHistory
;
const
hasError
=
hiveBalanceHistoryError
||
vestsBalanceHistoryError
||
hbdBalanceHistoryError
;
const
prepareData
=
(
operations
:
{
timestamp
:
string
;
balance
:
number
}[]
)
=>
{
if
(
!
operations
||
operations
.
length
===
0
)
return
[];
const
dailyData
=
new
Map
<
string
,
{
balance
:
number
;
balance_change
:
number
}
>
();
operations
.
forEach
((
operation
:
any
)
=>
{
let
date
;
if
(
typeof
operation
.
timestamp
===
"
string
"
)
{
date
=
new
Date
(
operation
.
timestamp
);
}
else
if
(
typeof
operation
.
timestamp
===
"
number
"
)
{
date
=
new
Date
(
operation
.
timestamp
*
1000
);
}
else
{
return
;
}
if
(
!
isNaN
(
date
.
getTime
()))
{
const
dateString
=
date
.
toISOString
().
split
(
"
T
"
)[
0
];
let
balance_change
=
parseInt
(
operation
.
balance_change
,
10
);
let
balance
=
parseInt
(
operation
.
balance
,
10
);
const
prepareData
=
(
operations
:
{
timestamp
:
string
;
balance
:
number
}[]
)
=>
{
if
(
!
operations
||
operations
.
length
===
0
)
return
[];
if
(
dailyData
.
has
(
dateString
))
{
dailyData
.
get
(
dateString
)
!
.
balance_change
+=
balance_change
;
dailyData
.
get
(
dateString
)
!
.
balance
=
balance
;
}
else
{
dailyData
.
set
(
dateString
,
{
balance
,
balance_change
});
}
}
});
const
preparedData
=
Array
.
from
(
dailyData
.
entries
()).
map
(
([
date
,
data
])
=>
({
timestamp
:
date
,
balance
:
data
.
balance
,
balance_change
:
data
.
balance_change
,
})
);
return
preparedData
;
};
const
aggregatedData
=
new
Map
<
string
,
{
balance
:
number
;
balance_change
:
number
}
>
();
// Reverse and prepare data with useMemo
const
reversedHiveBalanceHistory
=
useMemo
(
()
=>
prepareData
(
Array
.
isArray
(
hiveBalanceHistory
?.
operations_result
)
?
[...
hiveBalanceHistory
.
operations_result
].
reverse
()
:
[]
),
[
hiveBalanceHistory
?.
operations_result
]
);
operations
.
forEach
((
operation
:
any
)
=>
{
let
balance_change
=
operation
.
balance
-
operation
.
prev_balance
;
let
balance
=
parseInt
(
operation
.
balance
,
10
);
const
reversedVestsBalanceHistory
=
useMemo
(
()
=>
prepareData
(
Array
.
isArray
(
vestsBalanceHistory
?.
operations_result
)
?
[...
vestsBalanceHistory
.
operations_result
].
reverse
()
:
[]
),
[
vestsBalanceHistory
?.
operations_result
]
);
aggregatedData
.
set
(
operation
.
date
,
{
balance
,
balance_change
});
});
const
re
versedHbdBalanceHistory
=
useMemo
(
()
=>
prepareData
(
Array
.
isArray
(
hbdBalanceHistory
?.
operations_result
)
?
[...
hbdBalanceHistory
.
operations_result
].
reverse
()
:
[]
)
,
[
hbdBalanceHistory
?.
operations_result
]
)
;
const
p
re
paredData
=
Array
.
from
(
aggregatedData
.
entries
()).
map
(
(
[
date
,
data
]
)
=>
({
timestamp
:
date
,
balance
:
data
.
balance
,
balance_change
:
data
.
balance_change
,
})
)
;
return
preparedData
;
}
;
const
handleButtonClick
=
(
e
:
MouseEvent
<
HTMLButtonElement
>
)
=>
{
e
.
stopPropagation
();
// Prevents the event from bubbling up
...
...
@@ -208,9 +156,9 @@ const AccountBalanceHistoryCard: React.FC<AccountBalanceHistoryCardProps> = ({
{
!
isLoading
&&
!
hasData
&&
<
NoResult
/>
}
{
!
isLoading
&&
hasData
&&
(
<
BalanceHistoryChart
hiveBalanceHistoryData
=
{
re
versedH
iveBalanceHistory
}
vestsBalanceHistoryData
=
{
re
versedV
estsBalanceHistory
}
hbdBalanceHistoryData
=
{
re
versedH
bdBalanceHistory
}
hiveBalanceHistoryData
=
{
p
re
pareData
(
h
iveBalanceHistory
)
}
vestsBalanceHistoryData
=
{
p
re
pareData
(
v
estsBalanceHistory
)
}
hbdBalanceHistoryData
=
{
p
re
pareData
(
h
bdBalanceHistory
)
}
quickView
=
{
true
}
className
=
"h-[320px]"
/>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment