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
fba43662
Commit
fba43662
authored
5 months ago
by
Dima Rifai
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#356
- Add the toggle logic between HP and Vests
parent
a30c5910
No related branches found
No related tags found
2 merge requests
!481
bring recent develop changes to mater to match the backend
,
!466
Delrifai/#356 calculate hive power for voters and votes history 2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
components/Witnesses/VotersDialog.tsx
+72
-12
72 additions, 12 deletions
components/Witnesses/VotersDialog.tsx
with
72 additions
and
12 deletions
components/Witnesses/VotersDialog.tsx
+
72
−
12
View file @
fba43662
import
{
useState
}
from
"
react
"
;
import
{
useState
,
useEffect
}
from
"
react
"
;
import
Link
from
"
next/link
"
;
import
{
MoveDown
,
MoveUp
,
Loader2
}
from
"
lucide-react
"
;
import
{
Switch
}
from
"
../ui/switch
"
;
import
{
cn
,
formatNumber
}
from
"
@/lib/utils
"
;
import
useWitnessVoters
from
"
@/hooks/api/common/useWitnessVoters
"
;
import
{
Dialog
,
DialogContent
}
from
"
@/components/ui/dialog
"
;
...
...
@@ -17,6 +17,9 @@ import useWitnessDetails from "@/hooks/api/common/useWitnessDetails";
import
CustomPagination
from
"
../CustomPagination
"
;
import
{
config
}
from
"
@/Config
"
;
import
LastUpdatedTooltip
from
"
../LastUpdatedTooltip
"
;
import
{
convertVestsToHP
}
from
"
@/utils/Calculations
"
;
import
fetchingService
from
"
@/services/FetchingService
"
;
import
{
useHiveChainContext
}
from
"
@/contexts/HiveChainContext
"
;
type
VotersDialogProps
=
{
accountName
:
string
;
...
...
@@ -41,6 +44,7 @@ const VotersDialog: React.FC<VotersDialogProps> = ({
const
[
sortKey
,
setSortKey
]
=
useState
<
string
>
(
"
vests
"
);
const
[
isAsc
,
setIsAsc
]
=
useState
<
boolean
>
(
false
);
const
[
pageNum
,
setPageNum
]
=
useState
<
number
>
(
1
);
const
[
isHP
,
setIsHP
]
=
useState
<
boolean
>
(
true
);
// Toggle state
const
{
witnessDetails
}
=
useWitnessDetails
(
accountName
,
true
);
const
{
witnessVoters
,
isWitnessVotersLoading
}
=
useWitnessVoters
(
...
...
@@ -69,6 +73,51 @@ const VotersDialog: React.FC<VotersDialogProps> = ({
}
else
return
null
;
};
interface
Supply
{
amount
:
string
;
nai
:
string
;
precision
:
number
;
}
const
[
totalVestingShares
,
setTotalVestingShares
]
=
useState
<
Supply
>
({
amount
:
"
0
"
,
nai
:
""
,
precision
:
0
,
});
const
[
totalVestingFundHive
,
setTotalVestingFundHive
]
=
useState
<
Supply
>
({
amount
:
"
0
"
,
nai
:
""
,
precision
:
0
,
});
const
{
hiveChain
}
=
useHiveChainContext
();
useEffect
(()
=>
{
const
fetchDynamicGlobalProperties
=
async
()
=>
{
const
dynamicGlobalProperties
=
await
fetchingService
.
getDynamicGlobalProperties
();
const
_totalVestingfundHive
=
dynamicGlobalProperties
.
total_vesting_fund_hive
;
const
_totalVestingShares
=
dynamicGlobalProperties
.
total_vesting_shares
;
setTotalVestingFundHive
(
_totalVestingfundHive
);
setTotalVestingShares
(
_totalVestingShares
);
}
fetchDynamicGlobalProperties
();
},
[]);
const
fetchHivePower
=
(
value
:
string
,
isHP
:
boolean
):
string
=>
{
if
(
isHP
)
{
if
(
!
hiveChain
)
return
""
;
return
convertVestsToHP
(
hiveChain
,
value
,
totalVestingFundHive
,
totalVestingShares
);
}
return
formatNumber
(
parseInt
(
value
),
true
,
false
)
+
"
Vests
"
;
// Return raw vests if not toggled to HP
};
return
(
<
Dialog
open
=
{
isVotersOpen
}
...
...
@@ -91,15 +140,26 @@ const VotersDialog: React.FC<VotersDialogProps> = ({
<
Loader2
className
=
"animate-spin mt-1 h-4 w-4 ml-3 ..."
/>
)
}
</
div
>
<
div
className
=
"flex justify-end"
>
{
witnessDetails
&&
(
<
LastUpdatedTooltip
lastUpdatedAt
=
{
witnessDetails
.
votes_updated_at
}
<
div
className
=
"flex justify-between items-center w-full"
>
<
div
className
=
"flex items-center"
>
{
witnessDetails
&&
(
<
LastUpdatedTooltip
lastUpdatedAt
=
{
witnessDetails
.
votes_updated_at
}
/>
)
}
</
div
>
<
div
className
=
"flex items-center"
>
<
label
className
=
"mr-2"
>
Vests
</
label
>
<
Switch
checked
=
{
isHP
}
onCheckedChange
=
{
()
=>
setIsHP
((
prev
)
=>
!
prev
)
}
className
=
"mx-1"
/>
)
}
<
label
>
HP
</
label
>
</
div
>
</
div
>
<
CustomPagination
<
CustomPagination
currentPage
=
{
pageNum
}
onPageChange
=
{
(
newPage
:
number
)
=>
{
setPageNum
(
newPage
);
...
...
@@ -161,19 +221,19 @@ const VotersDialog: React.FC<VotersDialogProps> = ({
className
=
"text-right"
data-testid
=
"vote-power"
>
{
f
ormatNumb
er
(
voter
.
vests
,
true
)
}
{
f
etchHivePow
er
(
voter
.
vests
.
toString
(),
isHP
)
}
</
TableCell
>
<
TableCell
className
=
"text-right"
data-testid
=
"account-power"
>
{
f
ormatNumb
er
(
voter
.
account_vests
,
true
)
}
{
f
etchHivePow
er
(
voter
.
account_vests
.
toString
(),
isHP
)
}
</
TableCell
>
<
TableCell
className
=
"text-right"
data-testid
=
"proxied-power"
>
{
f
ormatNumb
er
(
voter
.
proxied_vests
,
true
)
}
{
f
etchHivePow
er
(
voter
.
proxied_vests
.
toString
(),
isHP
)
}
</
TableCell
>
</
TableRow
>
))
}
...
...
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