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

Layout for "Manage starnames/iovnames/names" views #1048

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
209 commits
Select commit Hold shift + click to select a range
b38b708
Changes from previous branch
albertandrejev Mar 4, 2020
db9c730
Storybook snapshot update
albertandrejev Mar 4, 2020
dfb284c
Restore after revert
albertandrejev Mar 4, 2020
b2ade1d
Fix after revert
albertandrejev Mar 4, 2020
041584a
Fixes
albertandrejev Mar 4, 2020
d6344c0
Storybook snapshot update
albertandrejev Mar 4, 2020
89d478e
Remove not used file
albertandrejev Mar 4, 2020
c97235d
Use new "iovnames" naming
abefernan Feb 21, 2020
419aaa8
Fixes typo in test
abefernan Feb 21, 2020
534447d
Adds accounts reducer
abefernan Feb 21, 2020
f3126f9
Add accounts actions
abefernan Feb 21, 2020
7d66a2f
Exports accounts reducer and adds it to RootState
abefernan Feb 21, 2020
9a542ac
Adds unit tests for accounts reducer
abefernan Feb 21, 2020
47fe595
Adds accounts loading to loginBootSequence
abefernan Feb 21, 2020
c2b772a
Adapt to new names
abefernan Feb 21, 2020
340abcf
Adds query to Redux for starnames. Removes unneeded data.
abefernan Feb 21, 2020
148cc87
Add logos for iovnames and starnames
abefernan Feb 21, 2020
b6e973c
Adds new design to iovname list
abefernan Feb 21, 2020
cd0fd35
Adds new design to starnames list
abefernan Feb 21, 2020
3e079f0
Fixes key prop
abefernan Feb 21, 2020
6067c57
Updates storybook snapshots
abefernan Feb 21, 2020
b848a7c
Fixes e2e test to expect "iovnames"
abefernan Feb 24, 2020
2cca2b8
Fixes e2e test to remove copy functionality
abefernan Feb 24, 2020
7959eab
Fixes test util to search for "Manage"
abefernan Feb 24, 2020
fae5f4b
Sorts iovnames
abefernan Feb 26, 2020
8e29cfb
Sorts starnames
abefernan Feb 26, 2020
19c4a7c
Adds temporary Register Name link
abefernan Feb 26, 2020
10c70c4
Adds account dispatch to Tx subscription
abefernan Feb 26, 2020
3fb6c31
Changes from previous branch
albertandrejev Mar 4, 2020
49e1c08
Refactor transaction assets
albertandrejev Feb 20, 2020
978be1a
Refactor parse method
albertandrejev Feb 20, 2020
3d8942f
Add RegisterDomainTx to storybook
albertandrejev Feb 20, 2020
fb5332d
Add RegisterDomainTx parser and components
albertandrejev Feb 20, 2020
49ea576
Add date duration formatter
albertandrejev Feb 25, 2020
85fb8d9
Add TX additional fields
albertandrejev Feb 25, 2020
79b2a78
Storybook snapshot update
albertandrejev Feb 25, 2020
9755ac1
Add CreateAccount TX support
albertandrejev Feb 26, 2020
3c98aac
Storybook snapshot update
albertandrejev Feb 26, 2020
bce7bb6
Support for UpdateAccountConfigurationTx
abefernan Mar 6, 2020
21bd5a9
Support for TransferDomainTx
abefernan Mar 6, 2020
d9a538e
Support for RenewDomainTx
abefernan Mar 6, 2020
8c5e678
Support for DeleteDomainTx
abefernan Mar 6, 2020
67ab5e2
Support for TransferAccountTx
abefernan Mar 6, 2020
a1d7421
Support for ReplaceAccountTargetsTx
abefernan Mar 6, 2020
ef0b49a
Support for DeleteAccountTx
abefernan Mar 6, 2020
994c1ca
Support for DeleteAllAccountsTx
abefernan Mar 6, 2020
d6154a1
Support for RenewAccountTx
abefernan Mar 6, 2020
f20d089
Support for AddAccountCertificateTx
abefernan Mar 6, 2020
a703271
Support for ReplaceAccountMsgFeesTx
abefernan Mar 6, 2020
0cbb336
Support for DeleteAccountCertificateTx
abefernan Mar 6, 2020
66e6516
Adds parsing support for new Tx types
abefernan Mar 6, 2020
d704cae
Adds new Tx types to storybook
abefernan Mar 6, 2020
72410d5
Adds layout fix for Certificate character overflow
abefernan Mar 6, 2020
9e623ae
Update storybook snapshots
abefernan Mar 6, 2020
a24fcd3
Updates Travis config for milestone branches support
abefernan Mar 6, 2020
a54979d
Skip tests that will be reimplemented in #1039
abefernan Mar 9, 2020
a38cc50
Improve url naming
abefernan Mar 9, 2020
2938cea
Compare names with localeCompare
abefernan Mar 9, 2020
caa21cf
Removes faulty route introduced when rebasing
abefernan Mar 9, 2020
d481d5c
Updates storybook snapshot
abefernan Mar 9, 2020
7e2bca2
Fix invalid selector in e2e test
abefernan Mar 11, 2020
c1317fd
Updates storybook snapshots
abefernan Mar 11, 2020
d700865
Merge pull request #1033 from iov-one/feature/#1008-account-txs-support
abefernan Mar 11, 2020
4e7b62d
Changes from previous branch
albertandrejev Mar 4, 2020
deef628
Storybook snapshot update
albertandrejev Mar 4, 2020
a278dca
Restore after revert
albertandrejev Mar 4, 2020
a3480cc
Fix after revert
albertandrejev Mar 4, 2020
36e6c5b
Fixes
albertandrejev Mar 4, 2020
86e0bef
Storybook snapshot update
albertandrejev Mar 4, 2020
785fe44
Remove not used file
albertandrejev Mar 4, 2020
e126cd7
Use new "iovnames" naming
abefernan Feb 21, 2020
a96b6e0
Fixes typo in test
abefernan Feb 21, 2020
8895b8a
Adds accounts reducer
abefernan Feb 21, 2020
2c42329
Add accounts actions
abefernan Feb 21, 2020
8da35d9
Exports accounts reducer and adds it to RootState
abefernan Feb 21, 2020
479bbdf
Adds unit tests for accounts reducer
abefernan Feb 21, 2020
2eee2cd
Adds accounts loading to loginBootSequence
abefernan Feb 21, 2020
a44e598
Adapt to new names
abefernan Feb 21, 2020
68db4da
Adds query to Redux for starnames. Removes unneeded data.
abefernan Feb 21, 2020
d19c7c3
Add logos for iovnames and starnames
abefernan Feb 21, 2020
f28540a
Adds new design to iovname list
abefernan Feb 21, 2020
3fc736e
Adds new design to starnames list
abefernan Feb 21, 2020
dcf912f
Fixes key prop
abefernan Feb 21, 2020
9466819
Updates storybook snapshots
abefernan Feb 21, 2020
1fddf1d
Fixes e2e test to expect "iovnames"
abefernan Feb 24, 2020
76ee136
Fixes e2e test to remove copy functionality
abefernan Feb 24, 2020
f9b940b
Fixes test util to search for "Manage"
abefernan Feb 24, 2020
701f7f6
Sorts iovnames
abefernan Feb 26, 2020
6c7e621
Sorts starnames
abefernan Feb 26, 2020
f73db4b
Adds temporary Register Name link
abefernan Feb 26, 2020
7bdb6b2
Adds account dispatch to Tx subscription
abefernan Feb 26, 2020
14e60c3
Changes from previous branch
albertandrejev Mar 4, 2020
b90200f
Refactor transaction assets
albertandrejev Feb 20, 2020
98b5196
Refactor parse method
albertandrejev Feb 20, 2020
70b42a1
Add RegisterDomainTx to storybook
albertandrejev Feb 20, 2020
8aa8254
Add RegisterDomainTx parser and components
albertandrejev Feb 20, 2020
d7b4b83
Add date duration formatter
albertandrejev Feb 25, 2020
8815669
Add TX additional fields
albertandrejev Feb 25, 2020
8850a87
Storybook snapshot update
albertandrejev Feb 25, 2020
e625570
Add CreateAccount TX support
albertandrejev Feb 26, 2020
c0c45bb
Storybook snapshot update
albertandrejev Feb 26, 2020
bfa82fb
Support for UpdateAccountConfigurationTx
abefernan Mar 6, 2020
fd15599
Support for TransferDomainTx
abefernan Mar 6, 2020
4210b7b
Support for RenewDomainTx
abefernan Mar 6, 2020
2eecf86
Support for DeleteDomainTx
abefernan Mar 6, 2020
c4cac05
Support for TransferAccountTx
abefernan Mar 6, 2020
f71c015
Support for ReplaceAccountTargetsTx
abefernan Mar 6, 2020
2d9b201
Support for DeleteAccountTx
abefernan Mar 6, 2020
481b9c6
Support for DeleteAllAccountsTx
abefernan Mar 6, 2020
281cd51
Support for RenewAccountTx
abefernan Mar 6, 2020
9f43626
Support for AddAccountCertificateTx
abefernan Mar 6, 2020
a4ed9f7
Support for ReplaceAccountMsgFeesTx
abefernan Mar 6, 2020
cb40846
Support for DeleteAccountCertificateTx
abefernan Mar 6, 2020
355bd20
Adds parsing support for new Tx types
abefernan Mar 6, 2020
23a0e10
Adds new Tx types to storybook
abefernan Mar 6, 2020
cf7d6b4
Adds layout fix for Certificate character overflow
abefernan Mar 6, 2020
801dca3
Update storybook snapshots
abefernan Mar 6, 2020
2c4a1b6
Updates Travis config for milestone branches support
abefernan Mar 6, 2020
2378da9
Skip tests that will be reimplemented in #1039
abefernan Mar 9, 2020
4d7e3e8
Improve url naming
abefernan Mar 9, 2020
92c66ff
Compare names with localeCompare
abefernan Mar 9, 2020
0b31e72
Removes faulty route introduced when rebasing
abefernan Mar 9, 2020
3909f91
Updates storybook snapshot
abefernan Mar 9, 2020
7a26ac9
Fix invalid selector in e2e test
abefernan Mar 11, 2020
b39742e
Updates storybook snapshots
abefernan Mar 11, 2020
95e2b92
Adds starnames to listing storybook
abefernan Mar 2, 2020
e9e02d1
Adapts forms to tests
abefernan Mar 2, 2020
63abe00
Adds forms to storybook tests
abefernan Mar 2, 2020
866f776
Updates storybook snapshots
abefernan Mar 2, 2020
3c3d0f0
Updates storybook snapshots after rebase
abefernan Mar 11, 2020
1d4a5e6
Merge branch 'milestone/account-module-support' of github.com:iov-one…
albertandrejev Mar 12, 2020
cc86683
Merge pull request #1043 from iov-one/fix/adapt-storybook-starnames
abefernan Mar 12, 2020
36db8ba
Merge branch 'milestone/account-module-support' of github.com:iov-one…
albertandrejev Mar 12, 2020
6a027af
Merge branch 'milestone/account-module-support' of github.com:iov-one…
albertandrejev Mar 12, 2020
2262e52
Changes from previous branch
albertandrejev Mar 4, 2020
b137b3a
Add local eslint support
albertandrejev Feb 17, 2020
168b279
lock file update
albertandrejev Feb 18, 2020
6c7d6e2
Add ActionMenu component
albertandrejev Feb 19, 2020
df979b9
Add typescirpt definitions
albertandrejev Feb 19, 2020
7804d06
Add ActionMenu component export
albertandrejev Feb 19, 2020
b047b72
Add ManageNames component
albertandrejev Feb 19, 2020
9ce6be4
Move Address manage component to another route
albertandrejev Feb 20, 2020
756ebe4
Fix after rebase
albertandrejev Mar 9, 2020
07621fc
Remove not used props spreading
albertandrejev Mar 9, 2020
713ed2e
Recover yarn lock
albertandrejev Mar 9, 2020
936495e
Pick out common manage component
albertandrejev Mar 10, 2020
076cbc5
Pick out account update component
albertandrejev Mar 10, 2020
e1ada68
Add Iovname manage route
albertandrejev Mar 10, 2020
98982ae
Add name manage route
albertandrejev Mar 10, 2020
7612d20
Add Iov name edit route
albertandrejev Mar 10, 2020
b6e7b40
Add route paths and configure Router
albertandrejev Mar 10, 2020
953a477
Change REGISTER_IOVNAME_ROUTE->IOVNAME_MANAGE_ROUTE
albertandrejev Mar 10, 2020
385b93a
Refactor commonly used functions
albertandrejev Mar 10, 2020
d38f500
Add Account Edit story
albertandrejev Mar 10, 2020
905fd20
Add link to other stories
albertandrejev Mar 10, 2020
2b2451e
Fix account name
albertandrejev Mar 10, 2020
7bb8bc6
Add shield image
albertandrejev Mar 10, 2020
ae12fe0
Refactor Account related routes
albertandrejev Mar 11, 2020
8174b3a
Fix imports
albertandrejev Mar 11, 2020
e8fbfd5
Add iovname update form
albertandrejev Mar 11, 2020
739d809
Update account storybook
albertandrejev Mar 11, 2020
a3bdb11
Update account main component
albertandrejev Mar 11, 2020
a955ae7
Copy account name
albertandrejev Mar 11, 2020
1db0432
Addititonal account edit paths
albertandrejev Mar 12, 2020
011999a
Hide account expiration date
albertandrejev Mar 12, 2020
ed4cec1
Add associated with starname accounts list
albertandrejev Mar 12, 2020
b30642e
Asscoiated names list
albertandrejev Mar 12, 2020
087429b
Up and down arrows
albertandrejev Mar 12, 2020
73e4625
Remove not used menu items
albertandrejev Mar 12, 2020
6c55773
Add starname manage form
albertandrejev Mar 12, 2020
6d2d82b
Fixes after rebase
albertandrejev Mar 12, 2020
1a0066a
Remove not used imports
albertandrejev Mar 12, 2020
79cc515
Rename route REGISTER_STARNAME_ROUTE -> STARNAME_REGISTER_ROUTE
albertandrejev Mar 13, 2020
05acde6
Reaname REGISTER_NAME_ROUTE->NAME_REGISTER_ROUTE
albertandrejev Mar 13, 2020
e326c5d
Rename REGISTER_IOVNAME_ROUTE->IOVNAME_REGISTER_ROUTE
albertandrejev Mar 13, 2020
868cc61
Redirect to starname manage route
albertandrejev Mar 13, 2020
93d2a7b
Need to update account renew time
albertandrejev Mar 13, 2020
7477394
Show only exists account data
albertandrejev Mar 13, 2020
43e1d4b
Remove not required field validator
albertandrejev Mar 13, 2020
15d7ff0
Refactor callback name onEditAccount->onEdit
albertandrejev Mar 13, 2020
afcee62
Change sorting behaviour
albertandrejev Mar 13, 2020
aa4d2c7
Fix getAccounts query
albertandrejev Mar 13, 2020
7106587
Reorganize Routes
albertandrejev Mar 13, 2020
b17a521
Add starname account management support
albertandrejev Mar 13, 2020
d68a296
Add collapse animation
albertandrejev Mar 13, 2020
5a5a2c4
Do not check account undefined
albertandrejev Mar 13, 2020
f610f10
Manage starname account
albertandrejev Mar 13, 2020
6571850
Replace name account component
albertandrejev Mar 13, 2020
b540a48
Add Name update support
albertandrejev Mar 13, 2020
e7b2f20
Add Chain name to account
albertandrejev Mar 13, 2020
671c123
Choose right action on account manage
albertandrejev Mar 13, 2020
2be9c65
Remove not used import and fix account subtitle
albertandrejev Mar 16, 2020
6b89d89
Refactor AccountEntity
albertandrejev Mar 16, 2020
cd4c029
Change Arrow behaviour
albertandrejev Mar 16, 2020
99d8c5a
Hide expriration date
albertandrejev Mar 16, 2020
128c5cb
Storybook snapshots update
albertandrejev Mar 16, 2020
62259e3
Upgrade storybook
albertandrejev Mar 16, 2020
1eadd78
Fix for https://github.com/babel/babel/issues/11212#issuecomment-5953…
albertandrejev Mar 16, 2020
7f53e78
Add key prop
albertandrejev Mar 16, 2020
f8ef60c
Cast `jsonValue` to string
albertandrejev Mar 16, 2020
39b9356
Fix quotes
albertandrejev Mar 16, 2020
a1b1106
Add create-react-app preset
albertandrejev Mar 16, 2020
60085bd
Add `createNodMock` and `createPortal` mocks
albertandrejev Mar 16, 2020
accea92
Storybook snapshot update
albertandrejev Mar 16, 2020
3b6f831
Fix lint warnings
albertandrejev Mar 16, 2020
4863684
Update transactions time
albertandrejev Mar 16, 2020
2bbd2fc
Storybook snapshot update
albertandrejev Mar 16, 2020
3703caf
Update TX time
albertandrejev Mar 16, 2020
b57b673
Rever puppeteer version
albertandrejev Mar 16, 2020
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
20 changes: 9 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@
},
"devDependencies": {
"@babel/core": "^7.3.4",
"@storybook/addon-actions": "^5.2.1",
"@storybook/addon-links": "^5.2.1",
"@storybook/addon-storyshots": "^5.2.1",
"@storybook/addon-viewport": "^5.2.1",
"@storybook/addons": "^5.2.1",
"@storybook/react": "^5.2.1",
"@storybook/addon-actions": "^5.3.17",
"@storybook/addon-links": "^5.3.17",
"@storybook/addon-storyshots": "^5.3.17",
"@storybook/addon-viewport": "^5.3.17",
"@storybook/addons": "^5.3.17",
"@storybook/preset-create-react-app": "^2.0.0",
"@storybook/react": "^5.3.17",
"@types/chrome": "^0.0.82",
"@types/classnames": "^2.2.7",
"@types/jest": "24.0.14",
Expand All @@ -57,11 +58,8 @@
"@types/react": "16.8.19",
"@types/react-dom": "16.8.4",
"@types/react-redux": "7.1.0",
"@types/react-test-renderer": "^16.8.1",
"@types/storybook__addon-actions": "^3.4.3",
"@types/storybook__addon-storyshots": "^5.1.1",
"@types/storybook__addon-viewport": "^4.1.1",
"@types/storybook__react": "^4.0.2",
"@types/react-test-renderer": "^16.9.2",
"@types/puppeteer": "^1.13.0",
"eslint": "^6",
"eslint-config-prettier": "^6.2.0",
"eslint-plugin-prettier": "^3.0.1",
Expand Down
1 change: 1 addition & 0 deletions packages/bierzo-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
},
"browserslist": [
">0.2%",
"chrome 45",
"not dead",
"not ie <= 11",
"not op_mini all"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const generateRegisterDomainTxWithFee = async (
domain: string,
): Promise<RegisterDomainTx> => {
const creatorAddress = bnsCodec.identityToAddress(creator);
const TwoHoursInSeconds = 2 * 3600;
const TwoHoursInSeconds = 2 * 3600; // FIXME: I think we need to change this before release.

const regDomainTx: RegisterDomainTx = {
kind: "bns/register_domain",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import React from "react";
import { randomString } from "ui-logic";

import { ChainAddressPairWithName } from "../../../components/AddressesTable";
import { ChainAddressPairWithName } from "../AddressesTable";

export const addressValueField = "address-value-field";
export const blockchainValueField = "blockchain-value-field";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Address, ChainId, Fee, Token, TokenTicker } from "@iov/bcp";
import { action } from "@storybook/addon-actions";
import { linkTo } from "@storybook/addon-links";
import { storiesOf } from "@storybook/react";
import React from "react";
import { stringToAmount } from "ui-logic";

import AccountEdit from "../../components/AccountEdit";
import {
ACCOUNT_MANAGE_SAMPLE_STORY_PATH,
ACCOUNT_MANAGE_STORY_PATH,
} from "../../components/AccountManage/index.stories";
import { ChainAddressPairWithName } from "../../components/AddressesTable";
import DecoratedStorybook, { bierzoRoot } from "../../utils/storybook";
import { BwUsernameWithChainName } from "../AccountManage";

const addresses: 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 iov: Pick<Token, "tokenTicker" | "fractionalDigits"> = {
fractionalDigits: 9,
tokenTicker: "IOV" as TokenTicker,
};

const fee: Fee = {
tokens: stringToAmount("5", iov),
};

const account: BwUsernameWithChainName = {
username: "test*iov",
addresses: addresses,
};

export const UPDATE_ACCOUNT_STORY_PATH = `${bierzoRoot}/Update Account`;
export const UPDATE_ACCOUNT_SAMPLE_STORY_PATH = "Update sample";

storiesOf(UPDATE_ACCOUNT_STORY_PATH, module)
.addParameters({ viewport: { defaultViewport: "responsive" } })
.add(UPDATE_ACCOUNT_SAMPLE_STORY_PATH, () => (
<DecoratedStorybook>
<AccountEdit
chainAddresses={addresses}
account={account}
onCancel={linkTo(ACCOUNT_MANAGE_STORY_PATH, ACCOUNT_MANAGE_SAMPLE_STORY_PATH)}
transactionFee={fee}
onSubmit={async (values: object): Promise<void> => action("Account update submit")(values)}
/>
</DecoratedStorybook>
));
274 changes: 274 additions & 0 deletions packages/bierzo-wallet/src/components/AccountEdit/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
import { Address, Fee } from "@iov/bcp";
import clipboardCopy from "clipboard-copy";
import {
Back,
Block,
Button,
Form,
FormValues,
Hairline,
Image,
makeStyles,
ToastContext,
ToastVariant,
Tooltip,
Typography,
useForm,
} from "medulas-react-components";
import React from "react";
import { amountToString } from "ui-logic";

import { isIovname } from "../../logic/account";
import {
AddressesTooltipHeader,
BwAccountWithChainName,
BwUsernameWithChainName,
isAccountData,
TooltipContent,
} from "../AccountManage";
import { AddressesTableProps, ChainAddressPairWithName } from "../AddressesTable";
import copy from "../AddressesTable/assets/copy.svg";
import PageContent from "../PageContent";
import shield from "./assets/shield.svg";
import SelectAddressesTable, {
addressValueField,
blockchainValueField,
getAddressInputName,
getBlockchainInputName,
SelectAddressItem,
} from "./SelectAddressesTable";

export const EDIT_ACCOUNT_VIEW_ID = "edit-account-view-id";
export const EDIT_ACCOUNT_FIELD = "edit-account-field";

export function getChainAddressPairsFromValues(
values: FormValues,
addresses: readonly ChainAddressPairWithName[],
): readonly ChainAddressPairWithName[] {
const chainAddressMap: Map<string, Partial<ChainAddressPairWithName>> = new Map<
string,
Partial<ChainAddressPairWithName>
>();
Object.keys(values).forEach(key => {
const idxLenght = key.indexOf("-");
if (idxLenght === -1) return;

const index = key.substr(0, idxLenght);
let pair = chainAddressMap.get(index);
if (!pair) {
pair = {};
}

const type = key.substr(idxLenght + 1);
switch (type) {
case addressValueField: {
pair = { ...pair, address: values[key] as Address };
break;
}
case blockchainValueField: {
const chain = addresses.find(address => address.chainName === values[key]);
if (chain) {
pair = { ...pair, chainId: chain.chainId, chainName: chain.chainName };
}
break;
}
}

chainAddressMap.set(index, pair);
});

const chainAddressPair: ChainAddressPairWithName[] = [];
chainAddressMap.forEach(value => {
if (value.address && value.chainId && value.chainName) {
chainAddressPair.push({
address: value.address,
chainId: value.chainId,
chainName: value.chainName,
});
}
});

return chainAddressPair;
}

export function getSubmitButtonCaption(fee: Fee | undefined): string {
if (fee && fee.tokens) {
return `Register for ${amountToString(fee.tokens)}`;
}

return "Register";
}

export function getFormInitValues(addressItems: SelectAddressItem[]): FormValues {
const initialValues: FormValues = {};
addressItems.forEach(item => {
initialValues[getAddressInputName(item.id)] = item.chain.address;
initialValues[getBlockchainInputName(item.id)] = item.chain.chainName;
});

return initialValues;
}

export function getAddressItems(chainAddresses: readonly ChainAddressPairWithName[]): SelectAddressItem[] {
const addressItems: SelectAddressItem[] = [];
chainAddresses.forEach((chain, index) => {
if (chain.address) {
addressItems.push({
id: index.toString(),
chain,
});
}
});

return addressItems;
}

const registerIcon = <Image src={shield} alt="shield" />;

const useStyles = makeStyles({
iovnameHeader: {
boxShadow: "0px 0px 14px #EDEFF4",
},
link: {
cursor: "pointer",
},
});

export function NoIovnameHeader(): JSX.Element {
const classes = useStyles();
return (
<Block className={classes.iovnameHeader} borderRadius={40} width={145} padding={1}>
<Typography variant="subtitle1" weight="semibold" color="primary" align="center">
yourname*iov
</Typography>
</Block>
);
}

export interface AccountEditProps extends AddressesTableProps {
readonly onCancel: () => void;
readonly account: BwUsernameWithChainName | BwAccountWithChainName;
readonly transactionFee: Fee | undefined;
}

interface Props extends AccountEditProps {
readonly onSubmit: (values: object) => Promise<void>;
}

const AccountEdit = ({ chainAddresses, account, onCancel, transactionFee, onSubmit }: Props): JSX.Element => {
const classes = useStyles();
const toast = React.useContext(ToastContext);

const chainAddressesItems = React.useMemo(() => {
return getAddressItems(account.addresses);
}, [account]);

const initialValues = React.useMemo(() => getFormInitValues(chainAddressesItems), [chainAddressesItems]);
const { form, handleSubmit, invalid, submitting, validating } = useForm({
onSubmit,
initialValues,
});

const onAccountCopy = (): void => {
if (account) {
const name = isAccountData(account) ? account.name : account.username;
clipboardCopy(name);
toast.show("Account has been copied to clipboard.", ToastVariant.INFO);
}
};

const buttons = (
<Block
marginTop={4}
marginBottom={1}
justifyContent="center"
display="flex"
alignItems="center"
flexDirection="column"
>
<Block width="75%">
<Button
fullWidth
type="submit"
disabled={invalid || submitting || validating}
spinner={submitting || validating}
>
{getSubmitButtonCaption(transactionFee)}
</Button>
</Block>
<Block width="75%" marginTop={1}>
<Back fullWidth disabled={submitting} onClick={onCancel}>
Cancel
</Back>
</Block>
</Block>
);

return (
<Form onSubmit={handleSubmit}>
<PageContent id={EDIT_ACCOUNT_VIEW_ID} icon={registerIcon} buttons={buttons} avatarColor="#31E6C9">
<Block textAlign="left">
<Block display="flex" justifyContent="center">
<Typography variant="h4" align="center">
{isAccountData(account) ? `${account.name}*${account.domain}` : account.username}
</Typography>
<Block marginRight={2} />
<Block onClick={onAccountCopy} className={classes.link} marginTop={1}>
<Image src={copy} alt="Copy" width={20} />
</Block>
</Block>
{isAccountData(account) && (
<Block display="flex" justifyContent="center" marginTop={1}>
{isIovname(`${account.name}*${account.domain}`) || !account.name ? (
<Typography variant="body2" inline align="center" color="textSecondary">
Expires on {account.expiryDate.toLocaleDateString()}
</Typography>
) : (
<React.Fragment>
<Typography variant="body2" inline align="center" color="textSecondary">
Name assigned to you by
</Typography>
<Typography variant="body2" weight="semibold" inline align="center" color="textSecondary">
{` *${account.domain}`}
</Typography>
</React.Fragment>
)}
</Block>
)}

<Block width="100%" marginTop={3} marginBottom={1}>
<Block display="flex" alignItems="center" marginBottom={1}>
<Block width={440}>
<Typography variant="body2" weight="semibold" inline>
CHOOSE LINKED ADDRESSES
</Typography>
</Block>
<Block marginRight={1} />
<Block width={34}>
<Tooltip maxWidth={320}>
<TooltipContent header={<AddressesTooltipHeader />} title="Your linked addresses">
With Neuma you can have an universal blockchain address that is linked to all your
addresses. Just give your friends your iovname.
</TooltipContent>
</Tooltip>
</Block>
<Block width="100%" marginLeft={1} marginRight={1}>
<Hairline />
</Block>
<Typography variant="subtitle2" inline weight="regular">
Optional
</Typography>
</Block>
<SelectAddressesTable
availableBlockchains={chainAddresses}
chainAddressesItems={chainAddressesItems}
form={form}
/>
</Block>
</Block>
</PageContent>
</Form>
);
};

export default AccountEdit;
Loading