Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed un-delegation in Hive Power #217

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/api/mutations/delegate-vesting-shares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@ import { useGlobalStore } from "@/core/global-store";
import { error } from "@/features/shared";
import * as keychain from "@/utils/keychain";

export function useDelegateVestingSharesByKey(username: string) {
export function useDelegateVestingSharesByKey(username?: string) {
const activeUser = useGlobalStore((s) => s.activeUser);

return useMutation({
mutationKey: ["delegateVestingSharesByKey"],
mutationFn: ({ key, value = "0.000000 VESTS" }: { key: PrivateKey; value: string }) => {
mutationKey: ["delegateVestingSharesByKey", activeUser?.username, username],
mutationFn: ({
key,
value = "0.000000 VESTS",
delegatee = username
}: {
key: PrivateKey;
value: string;
delegatee?: string;
}) => {
const op: Operation = [
"delegate_vesting_shares",
{
delegator: activeUser?.username,
delegatee: username,
delegatee,
vesting_shares: value
}
];
Expand All @@ -27,17 +35,23 @@ export function useDelegateVestingSharesByKey(username: string) {
});
}

export function useDelegateVestingSharesByKeychain(username: string) {
export function useDelegateVestingSharesByKeychain(username?: string) {
const activeUser = useGlobalStore((s) => s.activeUser);

return useMutation({
mutationKey: ["delegateVestingSharesByKey"],
mutationFn: ({ value = "0.000000 VESTS" }: { value: string }) => {
mutationKey: ["delegateVestingSharesByKC", activeUser?.username, username],
mutationFn: ({
value = "0.000000 VESTS",
delegatee = username
}: {
value: string;
delegatee?: string;
}) => {
const op: Operation = [
"delegate_vesting_shares",
{
delegator: activeUser?.username,
delegatee: username,
delegatee,
vesting_shares: value
}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export function DelegatedVesting({ onHide, account, totalDelegated }: Props) {
1000
).useClientQuery();

const { mutateAsync: delegateByKey } = useDelegateVestingSharesByKey(account.name);
const { mutateAsync: delegateByKeychain } = useDelegateVestingSharesByKeychain(account.name);
const { mutateAsync: delegateByKey } = useDelegateVestingSharesByKey();
const { mutateAsync: delegateByKeychain } = useDelegateVestingSharesByKeychain();

const data = useMemo(
() =>
Expand Down Expand Up @@ -135,15 +135,26 @@ export function DelegatedVesting({ onHide, account, totalDelegated }: Props) {
<KeyOrHotDialog
popOver={true}
onToggle={() => setHideList(!hideList)}
onKey={(key) => delegateByKey({ key, value: "0.000000 VESTS" })}
onKey={(key) =>
delegateByKey({
key,
value: "0.000000 VESTS",
delegatee: x.delegatee
})
}
onHot={() =>
delegateVestingSharesHot(
activeUser.username,
username,
"0.000000 VESTS"
)
}
onKc={() => delegateByKeychain({ value: "0.000000 VESTS" })}
onKc={() =>
delegateByKeychain({
value: "0.000000 VESTS",
delegatee: x.delegatee
})
}
>
<a href="#" className="undelegate">
{i18next.t("delegated-vesting.undelegate")}
Expand Down
Loading