From 9b4fa09ada7a3610cce3087137a913387835ab1f Mon Sep 17 00:00:00 2001 From: "ildar.timerbaev" Date: Sat, 28 Dec 2024 09:20:17 +0300 Subject: [PATCH] Fixed un-delegation in Hive Power --- src/api/mutations/delegate-vesting-shares.ts | 30 ++++++++++++++----- .../_components/delegated-vesting/index.tsx | 19 +++++++++--- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/api/mutations/delegate-vesting-shares.ts b/src/api/mutations/delegate-vesting-shares.ts index d0235e2af..500c7c169 100644 --- a/src/api/mutations/delegate-vesting-shares.ts +++ b/src/api/mutations/delegate-vesting-shares.ts @@ -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 } ]; @@ -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 } ]; diff --git a/src/app/(dynamicPages)/profile/[username]/_components/delegated-vesting/index.tsx b/src/app/(dynamicPages)/profile/[username]/_components/delegated-vesting/index.tsx index 72e7a34aa..c14722e10 100644 --- a/src/app/(dynamicPages)/profile/[username]/_components/delegated-vesting/index.tsx +++ b/src/app/(dynamicPages)/profile/[username]/_components/delegated-vesting/index.tsx @@ -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( () => @@ -135,7 +135,13 @@ export function DelegatedVesting({ onHide, account, totalDelegated }: Props) { 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, @@ -143,7 +149,12 @@ export function DelegatedVesting({ onHide, account, totalDelegated }: Props) { "0.000000 VESTS" ) } - onKc={() => delegateByKeychain({ value: "0.000000 VESTS" })} + onKc={() => + delegateByKeychain({ + value: "0.000000 VESTS", + delegatee: x.delegatee + }) + } > {i18next.t("delegated-vesting.undelegate")}