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

Feature #1012 - Delete account #1066

Merged
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
67 changes: 60 additions & 7 deletions packages/bierzo-wallet/src/communication/requestgenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Address, Amount, Identity, SendTransaction, UnsignedTransaction } from
import {
bnsCodec,
ChainAddressPair,
DeleteAccountTx,
DeleteDomainTx,
RegisterAccountTx,
RegisterDomainTx,
RegisterUsernameTx,
Expand Down Expand Up @@ -158,10 +160,42 @@ export const generateTransferDomainTxWithFee = async (
return await withChainFee(regDomainTx, creatorAddress);
};

export const generateRegisterAccountTxWithFee = async (
export const generateDeleteDomainTxWithFee = async (
creator: Identity,
domain: string,
): Promise<DeleteDomainTx> => {
const creatorAddress = bnsCodec.identityToAddress(creator);

const transaction: DeleteDomainTx = {
kind: "bns/delete_domain",
chainId: creator.chainId,
domain: domain,
};

return await withChainFee(transaction, creatorAddress);
};

export const generateDeleteAccountTxWithFee = async (
creator: Identity,
name: string,
domain: string,
): Promise<DeleteAccountTx> => {
const creatorAddress = bnsCodec.identityToAddress(creator);

const transaction: DeleteAccountTx = {
kind: "bns/delete_account",
chainId: creator.chainId,
name: name,
domain: domain,
};

return await withChainFee(transaction, creatorAddress);
};

export const generateRegisterAccountTxWithFee = async (
creator: Identity,
name: string,
domain: string,
owner: Address,
targets: readonly ChainAddressPair[],
): Promise<RegisterAccountTx> => {
Expand Down Expand Up @@ -196,15 +230,15 @@ export const generateTransferAccountTxWithFee = async (

export const generateReplaceAccountTargetsTxWithFee = async (
creator: Identity,
domain: string,
name: string,
domain: string,
newTargets: readonly ChainAddressPair[],
): Promise<ReplaceAccountTargetsTx> => {
const regAccountTx: ReplaceAccountTargetsTx = {
kind: "bns/replace_account_targets",
chainId: creator.chainId,
name: name ? name : undefined,
domain: domain,
name: name,
newTargets: newTargets,
};

Expand Down Expand Up @@ -284,25 +318,44 @@ export const generateTransferAccountTxRequest = async (
return generateJsonPrcRequest(creator, transactionWithFee);
};

export const generateRegisterAccountTxRequest = async (
export const generateDeleteDomainTxRequest = async (
creator: Identity,
domain: string,
): Promise<JsonRpcRequest> => {
const transactionWithFee = await generateDeleteDomainTxWithFee(creator, domain);

return generateJsonPrcRequest(creator, transactionWithFee);
};

export const generateDeleteAccountTxRequest = async (
creator: Identity,
name: string,
domain: string,
): Promise<JsonRpcRequest> => {
const transactionWithFee = await generateDeleteAccountTxWithFee(creator, name, domain);

return generateJsonPrcRequest(creator, transactionWithFee);
};

export const generateRegisterAccountTxRequest = async (
creator: Identity,
name: string,
domain: string,
owner: Address,
targets: readonly ChainAddressPair[],
): Promise<JsonRpcRequest> => {
const transactionWithFee = await generateRegisterAccountTxWithFee(creator, domain, name, owner, targets);
const transactionWithFee = await generateRegisterAccountTxWithFee(creator, name, domain, owner, targets);

return generateJsonPrcRequest(creator, transactionWithFee);
};

export const generateReplaceAccountTargetsTxRequest = async (
creator: Identity,
domain: string,
name: string,
domain: string,
newTargets: readonly ChainAddressPair[],
): Promise<JsonRpcRequest> => {
const transactionWithFee = await generateReplaceAccountTargetsTxWithFee(creator, domain, name, newTargets);
const transactionWithFee = await generateReplaceAccountTargetsTxWithFee(creator, name, domain, newTargets);

return generateJsonPrcRequest(creator, transactionWithFee);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { Address, Algorithm, ChainId, Identity, PubkeyBytes, Token, TokenTicker } from "@iov/bcp";
import { JsonRpcRequest } from "@iov/jsonrpc";
import { action } from "@storybook/addon-actions";
import { storiesOf } from "@storybook/react";
import { Typography } from "medulas-react-components";
import React from "react";
import { stringToAmount } from "ui-logic";

import { extensionRpcEndpoint } from "../../communication/extensionRpcEndpoint";
import { generateDeleteDomainTxRequest } from "../../communication/requestgenerators";
import { ChainAddressPairWithName } from "../../components/AddressesTable";
import DecoratedStorybook, { bierzoRoot } from "../../utils/storybook";
import { BwAccountWithChainName } from "../AccountManage";
import AccountTransfer from ".";

const chainAddresses: ChainAddressPairWithName[] = [
{
chainId: "local-iov-devnet" as ChainId,
address: "tiov1dcg3fat5zrvw00xezzjk3jgedm7pg70y222af3" as Address,
chainName: "IOV Devnet",
},
{
chainId: "lisk-198f2b61a8" as ChainId,
address: "1349293588603668134L" as Address,
chainName: "Lisk Devnet",
},
{
chainId: "ethereum-eip155-5777" as ChainId,
address: "0xD383382350F9f190Bd2608D6381B15b4e1cec0f3" as Address,
chainName: "Ganache",
},
];

const account: BwAccountWithChainName = {
name: "albert",
domain: "iov",
expiryDate: new Date("June 5, 2120 03:00:00"),
owner: "tiov1dcg3fat5zrvw00xezzjk3jgedm7pg70y222af3" as Address,
addresses: chainAddresses,
};

export const ACCOUNT_DELETE_STORY_PATH = `${bierzoRoot}/Account Delete`;
export const ACCOUNT_DELETE_SAMPLE_STORY_PATH = "Delete sample";

const iov: Pick<Token, "tokenTicker" | "fractionalDigits"> = {
fractionalDigits: 9,
tokenTicker: "IOV" as TokenTicker,
};

const bnsIdentity: Identity = {
chainId: "local-iov-devnet" as ChainId,
pubkey: {
algo: Algorithm.Ed25519,
data: new Uint8Array([]) as PubkeyBytes,
},
};

storiesOf(ACCOUNT_DELETE_STORY_PATH, module)
.addParameters({ viewport: { defaultViewport: "responsive" } })
.add(ACCOUNT_DELETE_SAMPLE_STORY_PATH, () => (
<DecoratedStorybook>
<AccountTransfer
id="account-delete-id"
account={account}
getRequest={async (): Promise<JsonRpcRequest> => {
action("getRequest")();
return await generateDeleteDomainTxRequest(bnsIdentity, account.domain);
}}
onCancel={action("Transfer cancel")}
getFee={async () => {
action("get fee")();
return { tokens: stringToAmount("5", iov) };
}}
bnsChainId={"local-iov-devnet" as ChainId}
rpcEndpoint={extensionRpcEndpoint}
setTransactionId={value => {
action("setTransactionId")(value);
}}
>
<Typography>Some additional description</Typography>
</AccountTransfer>
</DecoratedStorybook>
));
73 changes: 73 additions & 0 deletions packages/bierzo-wallet/src/components/AccountDelete/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ChainId, Fee, TransactionId } from "@iov/bcp";
import { JsonRpcRequest } from "@iov/jsonrpc";
import { Typography } from "medulas-react-components";
import React from "react";

import { RpcEndpoint } from "../../communication/rpcEndpoint";
import { AccountModuleMixedType, isAccountData } from "../AccountManage";
import AccountOperation from "../AccountOperation";

interface HeaderProps {
readonly account: AccountModuleMixedType;
}

const Header: React.FunctionComponent<HeaderProps> = ({ account }): JSX.Element => (
<React.Fragment>
<Typography color="default" variant="h5" inline>
You are deleting{" "}
</Typography>
<Typography color="primary" variant="h5" inline>
{isAccountData(account) ? `${account.name}*${account.domain}` : account.username}
</Typography>
</React.Fragment>
);

interface Props {
readonly id: string;
readonly account: AccountModuleMixedType;
readonly children: React.ReactNode;
readonly bnsChainId: ChainId;
readonly onCancel: () => void;
readonly getFee: () => Promise<Fee | undefined>;
readonly getRequest: () => Promise<JsonRpcRequest>;
readonly rpcEndpoint: RpcEndpoint;
readonly setTransactionId: React.Dispatch<React.SetStateAction<TransactionId | null>>;
}

const AccountDelete = ({
account,
id,
onCancel,
getFee,
getRequest,
bnsChainId,
children,
rpcEndpoint,
setTransactionId,
}: Props): JSX.Element => {
const getDeleteRequest = async (): Promise<JsonRpcRequest> => {
return await getRequest();
};

const getDeleteFee = async (): Promise<Fee | undefined> => {
return await getFee();
};

return (
<AccountOperation
id={id}
submitCaption="Delete"
onCancel={onCancel}
getFee={getDeleteFee}
getRequest={getDeleteRequest}
bnsChainId={bnsChainId}
rpcEndpoint={rpcEndpoint}
setTransactionId={setTransactionId}
header={<Header account={account} />}
>
{children}
</AccountOperation>
);
};

export default AccountDelete;
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { Address, Algorithm, ChainId, Identity, PubkeyBytes, Token, TokenTicker } from "@iov/bcp";
import { JsonRpcRequest } from "@iov/jsonrpc";
import { action } from "@storybook/addon-actions";
import { storiesOf } from "@storybook/react";
import { FormValues, Typography } from "medulas-react-components";
import React from "react";
import { stringToAmount } from "ui-logic";

import { extensionRpcEndpoint } from "../../communication/extensionRpcEndpoint";
import { generateTransferDomainTxRequest } from "../../communication/requestgenerators";
import { ChainAddressPairWithName } from "../../components/AddressesTable";
import DecoratedStorybook, { bierzoRoot } from "../../utils/storybook";
import { BwAccountWithChainName } from "../AccountManage";
import AccountOperation, { RECEPIENT_ADDRESS } from ".";

const chainAddresses: ChainAddressPairWithName[] = [
{
chainId: "local-iov-devnet" as ChainId,
address: "tiov1dcg3fat5zrvw00xezzjk3jgedm7pg70y222af3" as Address,
chainName: "IOV Devnet",
},
{
chainId: "lisk-198f2b61a8" as ChainId,
address: "1349293588603668134L" as Address,
chainName: "Lisk Devnet",
},
{
chainId: "ethereum-eip155-5777" as ChainId,
address: "0xD383382350F9f190Bd2608D6381B15b4e1cec0f3" as Address,
chainName: "Ganache",
},
];

const account: BwAccountWithChainName = {
name: "albert",
domain: "iov",
expiryDate: new Date("June 5, 2120 03:00:00"),
owner: "tiov1dcg3fat5zrvw00xezzjk3jgedm7pg70y222af3" as Address,
addresses: chainAddresses,
};

export const ACCOUNT_TRANSFER_STORY_PATH = `${bierzoRoot}/Account Transfer`;
export const ACCOUNT_TRANSFER_SAMPLE_STORY_PATH = "Transfer sample";

const iov: Pick<Token, "tokenTicker" | "fractionalDigits"> = {
fractionalDigits: 9,
tokenTicker: "IOV" as TokenTicker,
};

const bnsIdentity: Identity = {
chainId: "local-iov-devnet" as ChainId,
pubkey: {
algo: Algorithm.Ed25519,
data: new Uint8Array([]) as PubkeyBytes,
},
};

const Header: React.FunctionComponent = (): JSX.Element => (
<React.Fragment>
<Typography color="default" variant="h5" inline>
You are makeing operation with{" "}
</Typography>
<Typography color="primary" variant="h5" inline>
albert*iov
</Typography>
<Typography color="default" variant="h5" inline>
{" "}
account
</Typography>
</React.Fragment>
);

storiesOf(`${bierzoRoot}/Account Operation`, module)
.addParameters({ viewport: { defaultViewport: "responsive" } })
.add("Sample", () => (
<DecoratedStorybook>
<AccountOperation
id="account-operation-id"
submitCaption="Operation"
getRequest={async (formValues: FormValues): Promise<JsonRpcRequest> => {
action("getRequest")(formValues);
return await generateTransferDomainTxRequest(
bnsIdentity,
account.domain,
formValues[RECEPIENT_ADDRESS] as Address,
);
}}
onCancel={action("Transfer cancel")}
getFee={async newOwner => {
action("get fee")(newOwner);
return { tokens: stringToAmount("5", iov) };
}}
bnsChainId={"local-iov-devnet" as ChainId}
rpcEndpoint={extensionRpcEndpoint}
setTransactionId={value => {
action("setTransactionId")(value);
}}
header={<Header />}
>
<Typography>Some additional description</Typography>
</AccountOperation>
</DecoratedStorybook>
));
Loading