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
c83a4e42
Commit
c83a4e42
authored
4 months ago
by
Lukas
Browse files
Options
Downloads
Patches
Plain Diff
Update date time pickers on votes history dialog
parent
875998f9
No related branches found
No related tags found
2 merge requests
!491
Lbudginas/#391 new date time picker
,
!486
Lbudginas/#374 calendar dates selection bug
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
components/Witnesses/VotesHistoryDialog.tsx
+42
-36
42 additions, 36 deletions
components/Witnesses/VotesHistoryDialog.tsx
hooks/api/common/useWitnessVotesHistory.ts
+5
-1
5 additions, 1 deletion
hooks/api/common/useWitnessVotesHistory.ts
with
47 additions
and
37 deletions
components/Witnesses/VotesHistoryDialog.tsx
+
42
−
36
View file @
c83a4e42
...
...
@@ -27,6 +27,12 @@ import { useHiveChainContext } from "@/contexts/HiveChainContext";
import
{
convertVestsToHP
}
from
"
@/utils/Calculations
"
;
import
fetchingService
from
"
@/services/FetchingService
"
;
interface
Supply
{
amount
:
string
;
nai
:
string
;
precision
:
number
;
}
type
VotersDialogProps
=
{
accountName
:
string
;
isVotesHistoryOpen
:
boolean
;
...
...
@@ -57,8 +63,20 @@ const VotesHistoryDialog: React.FC<VotersDialogProps> = ({
);
const
[
toDate
,
setToDate
]
=
useState
<
Date
>
(
moment
().
toDate
());
const
[
isHP
,
setIsHP
]
=
useState
<
boolean
>
(
true
);
// Toggle state
const
[
totalVestingShares
,
setTotalVestingShares
]
=
useState
<
Supply
>
({
amount
:
"
0
"
,
nai
:
""
,
precision
:
0
,
});
const
[
totalVestingFundHive
,
setTotalVestingFundHive
]
=
useState
<
Supply
>
({
amount
:
"
0
"
,
nai
:
""
,
precision
:
0
,
});
const
{
hiveChain
}
=
useHiveChainContext
();
const
{
witnessDetails
}
=
useWitnessDetails
(
accountName
,
true
)
as
any
;
const
{
votesHistory
,
isVotesHistoryLoading
}
=
useWitnessVotesHistory
(
accountName
,
isVotesHistoryOpen
,
...
...
@@ -67,38 +85,30 @@ const VotesHistoryDialog: React.FC<VotersDialogProps> = ({
liveDataEnabled
);
useEffect
(()
=>
{
setPage
(
1
);
if
(
votesHistory
&&
votesHistory
?.
length
>
PAGE_SIZE
)
{
setDisplayData
(
votesHistory
.
slice
(
0
,
PAGE_SIZE
-
1
));
}
else
{
setDisplayData
(
votesHistory
);
}
},
[
votesHistory
]);
const
handlePageChange
=
(
page
:
number
)
=>
{
setPage
(
page
);
setDisplayData
(
votesHistory
?.
slice
((
page
-
1
)
*
PAGE_SIZE
,
page
*
PAGE_SIZE
-
1
)
);
};
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
();
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
};
useEffect
(()
=>
{
if
(
moment
(
fromDate
).
isSame
(
toDate
)
||
moment
(
fromDate
).
isAfter
(
toDate
))
{
setFromDate
(
moment
(
fromDate
).
subtract
(
1
,
"
hours
"
).
toDate
());
}
},
[
fromDate
,
toDate
]);
useEffect
(()
=>
{
const
fetchDynamicGlobalProperties
=
async
()
=>
{
...
...
@@ -115,18 +125,14 @@ const VotesHistoryDialog: React.FC<VotersDialogProps> = ({
fetchDynamicGlobalProperties
();
},
[]);
const
fetchHivePower
=
(
value
:
string
,
isHP
:
boolean
):
string
=>
{
if
(
isHP
)
{
if
(
!
hiveChain
)
return
""
;
return
convertVestsToHP
(
hiveChain
,
value
,
totalVestingFundHive
,
totalVestingShares
);
useEffect
(()
=>
{
setPage
(
1
);
if
(
votesHistory
&&
votesHistory
?.
length
>
PAGE_SIZE
)
{
setDisplayData
(
votesHistory
.
slice
(
0
,
PAGE_SIZE
-
1
));
}
else
{
setDisplayData
(
votesHistory
);
}
return
formatNumber
(
parseInt
(
value
),
true
,
false
)
+
"
Vests
"
;
// Return raw vests if not toggled to HP
};
},
[
votesHistory
]);
return
(
<
Dialog
...
...
This diff is collapsed.
Click to expand it.
hooks/api/common/useWitnessVotesHistory.ts
+
5
−
1
View file @
c83a4e42
import
{
useQuery
}
from
"
@tanstack/react-query
"
;
import
moment
from
"
moment
"
;
import
{
config
}
from
"
@/Config
"
;
import
fetchingService
from
"
@/services/FetchingService
"
;
...
...
@@ -10,6 +11,9 @@ const useWitnessVotesHistory = (
toDate
:
Date
,
liveDataEnabled
:
boolean
)
=>
{
const
isDatesCorrect
=
!
moment
(
fromDate
).
isSame
(
toDate
)
&&
!
moment
(
fromDate
).
isAfter
(
toDate
);
const
fetchVotesHist
=
async
()
=>
await
fetchingService
.
getWitnessVotesHistory
(
accountName
,
...
...
@@ -34,7 +38,7 @@ const useWitnessVotesHistory = (
liveDataEnabled
,
],
queryFn
:
fetchVotesHist
,
enabled
:
!!
accountName
&&
isModalOpen
,
enabled
:
!!
accountName
&&
isModalOpen
&&
isDatesCorrect
,
refetchInterval
:
liveDataEnabled
?
config
.
accountRefreshInterval
:
false
,
refetchOnWindowFocus
:
false
,
});
...
...
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