Skip to content

Commit

Permalink
Merge pull request #217 from ecency/bugfix/undelegate
Browse files Browse the repository at this point in the history
Fixed un-delegation in Hive Power
  • Loading branch information
feruzm authored Dec 28, 2024
2 parents da7724a + 9b4fa09 commit ee3ccc6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
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

0 comments on commit ee3ccc6

Please sign in to comment.