Skip to content

Commit

Permalink
Improved the hive engine transfer dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
dkildar committed Nov 9, 2024
1 parent af0adcb commit 9a90e44
Show file tree
Hide file tree
Showing 14 changed files with 536 additions and 283 deletions.
223 changes: 0 additions & 223 deletions src/api/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1422,85 +1422,6 @@ export const updatePassword = (
ownerKey: PrivateKey
): Promise<TransactionConfirmation> => hiveClient.broadcast.updateAccount(update, ownerKey);

// HE Operations
export const transferHiveEngineKc = (
from: string,
to: string,
symbol: string,
amount: string,
memo: string
) => {
const json = JSON.stringify({
contractName: "tokens",
contractAction: "transfer",
contractPayload: {
symbol,
to,
quantity: amount.toString(),
memo
}
});

return keychain.customJson(from, "ssc-mainnet-hive", "Active", json, "Transfer");
};
export const delegateHiveEngineKc = (from: string, to: string, symbol: string, amount: string) => {
const json = JSON.stringify({
contractName: "tokens",
contractAction: "delegate",
contractPayload: {
symbol,
to,
quantity: amount.toString()
}
});

return keychain.customJson(from, "ssc-mainnet-hive", "Active", json, "Transfer");
};
export const undelegateHiveEngineKc = (
from: string,
to: string,
symbol: string,
amount: string
) => {
const json = JSON.stringify({
contractName: "tokens",
contractAction: "undelegate",
contractPayload: {
symbol,
from: to,
quantity: amount.toString()
}
});

return keychain.customJson(from, "ssc-mainnet-hive", "Active", json, "Transfer");
};
export const stakeHiveEngineKc = (from: string, to: string, symbol: string, amount: string) => {
const json = JSON.stringify({
contractName: "tokens",
contractAction: "stake",
contractPayload: {
symbol,
to,
quantity: amount.toString()
}
});

return keychain.customJson(from, "ssc-mainnet-hive", "Active", json, "Transfer");
};
export const unstakeHiveEngineKc = (from: string, to: string, symbol: string, amount: string) => {
const json = JSON.stringify({
contractName: "tokens",
contractAction: "unstake",
contractPayload: {
symbol,
to,
quantity: amount.toString()
}
});

return keychain.customJson(from, "ssc-mainnet-hive", "Active", json, "Transfer");
};

// HE Hive Signer Operations
export const transferHiveEngineHs = (
from: string,
Expand Down Expand Up @@ -1629,150 +1550,6 @@ export const unstakeHiveEngineHs = (
return hotSign("custom-json", params, `@${from}/engine`);
};

//HE Key Operations
export const transferHiveEngineKey = async (
from: string,
key: PrivateKey,
symbol: string,
to: string,
amount: string,
memo: string
): Promise<TransactionConfirmation> => {
const json = JSON.stringify({
contractName: "tokens",
contractAction: "transfer",
contractPayload: {
symbol,
to,
quantity: amount.toString(),
memo
}
});

const op = {
id: "ssc-mainnet-hive",
json,
required_auths: [from],
required_posting_auths: []
};

const result = await hiveClient.broadcast.json(op, key);

return result;
};

export const delegateHiveEngineKey = async (
from: string,
key: PrivateKey,
symbol: string,
to: string,
amount: string
): Promise<TransactionConfirmation> => {
const json = JSON.stringify({
contractName: "tokens",
contractAction: "delegate",
contractPayload: {
symbol,
to,
quantity: amount.toString()
}
});

const op = {
id: "ssc-mainnet-hive",
json,
required_auths: [from],
required_posting_auths: []
};

const result = await hiveClient.broadcast.json(op, key);
return result;
};

export const undelegateHiveEngineKey = async (
from: string,
key: PrivateKey,
symbol: string,
to: string,
amount: string
): Promise<TransactionConfirmation> => {
const json = JSON.stringify({
contractName: "tokens",
contractAction: "undelegate",
contractPayload: {
symbol,
from: to,
quantity: amount.toString()
}
});

const op = {
id: "ssc-mainnet-hive",
json,
required_auths: [from],
required_posting_auths: []
};

const result = await hiveClient.broadcast.json(op, key);
return result;
};

export const stakeHiveEngineKey = async (
from: string,
key: PrivateKey,
symbol: string,
to: string,
amount: string
): Promise<TransactionConfirmation> => {
const json = JSON.stringify({
contractName: "tokens",
contractAction: "stake",
contractPayload: {
symbol,
to,
quantity: amount.toString()
}
});

const op = {
id: "ssc-mainnet-hive",
json,
required_auths: [from],
required_posting_auths: []
};

const result = await hiveClient.broadcast.json(op, key);
return result;
};

export const unstakeHiveEngineKey = async (
from: string,
key: PrivateKey,
symbol: string,
to: string,
amount: string
): Promise<TransactionConfirmation> => {
const json = JSON.stringify({
contractName: "tokens",
contractAction: "stake",
contractPayload: {
symbol,
to,
quantity: amount.toString()
}
});

const op = {
id: "ssc-mainnet-hive",
json,
required_auths: [from],
required_posting_auths: []
};

const result = await hiveClient.broadcast.json(op, key);
return result;
};

export const Revoke = (
account: string,
weight_threshold: number,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { EngineTransferFormHeader } from "@/app/(dynamicPages)/profile/[username]/engine/_components/engine-transfer/engine-transfer-form-header";
import { UserAvatar } from "@/features/shared";
import i18next from "i18next";
import { useGlobalStore } from "@/core/global-store";
import { Button } from "@/features/ui";
import { useMemo } from "react";
import { UilArrowRight } from "@tooni/iconscout-unicons-react";

interface Props {
titleLngKey: string;
onBack: () => void;
onConfirm: () => void;
to: string;
amount: string;
asset: string;
memo: string;
mode: string;
}

export function EngineTransferConfirmation({
titleLngKey,
onBack,
to,
amount,
asset,
memo,
onConfirm,
mode
}: Props) {
const activeUser = useGlobalStore((s) => s.activeUser);

const showTo = useMemo(
() => ["transfer", "delegate", "undelegate", "stake"].includes(mode),
[mode]
);

return (
<div className="transaction-form">
<EngineTransferFormHeader
step={2}
titleLngKey="confirm-title"
subTitleLngKey="confirm-sub-title"
/>
<div>
<div className="py-4 md:py-8">
<div className="flex items-center justify-center gap-4">
<UserAvatar username={activeUser?.username ?? ""} size="large" />
{showTo && (
<>
<UilArrowRight className="w-8 h-8" />
<UserAvatar username={to} size="large" />
</>
)}
</div>
<div className="text-center text-2xl font-semibold p-4">
<span className="text-blue-dark-sky mr-2">{amount}</span>
{asset}
</div>
{memo && <div className="memo">{memo}</div>}
</div>
<div className="flex justify-center gap-4 p-4">
<Button size="lg" appearance="secondary" outline={true} onClick={onBack}>
{i18next.t("g.back")}
</Button>
<Button size="lg" onClick={onConfirm}>
{i18next.t("transfer.confirm")}
</Button>
</div>
</div>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import i18next from "i18next";
interface Props {
titleLngKey: string;
subTitleLngKey: string;
step: number;
}

export function EngineTransferFormHeader({ titleLngKey, subTitleLngKey }: Props) {
export function EngineTransferFormHeader({ titleLngKey, subTitleLngKey, step }: Props) {
return (
<div className="transaction-form-header">
<div className="step-no">1</div>
<div className="step-no">{step}</div>
<div className="box-titles">
<div className="main-title">{i18next.t(`transfer.${titleLngKey}`)}</div>
<div className="sub-title">{i18next.t(`transfer.${subTitleLngKey}`)}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ interface Props {
subTitleLngKey: string;
onNext: () => void;
asset: string;
precision: number;
}

export function EngineTransferPowerDown({ titleLngKey, subTitleLngKey, onNext, asset }: Props) {
export function EngineTransferPowerDown({
titleLngKey,
subTitleLngKey,
onNext,
asset,
precision
}: Props) {
const activeUserWallet = useActiveUserWallet();

return (
Expand Down
Loading

0 comments on commit 9a90e44

Please sign in to comment.