Skip to content

Commit

Permalink
feat/60 - Extension: Account Creation (anoma#71)
Browse files Browse the repository at this point in the history
* Begin setting up KeyRing & accounts storage

* Adding a simple typed state class to keyring

* Address helper to obtain ImplicitAddress, cargo update

* Continue hooking up KeyRing to services

* Fix broken imports, confirm message works in popup

* Adding msg type for fetch generated mnemonic, update tests

* Beginning components package; get styled-components with theme working

* Disable devtool sourcemapping, add plugin for extension reloading (all browsers)

* Properly include svg assets, port additional components into shared
package

* Fix issue on reloader plugin

* fix module resolution, clean up imports

* Remove unnecessary assignment

* Consolidate types from Keplr into our own

* Validate mnemonic phrase before storing, better error handling in wasm

* Minor clean up, better type State class so as not to instantiate
directly

* Adding mnemonic/password creation screens, added README for types

* Split set-up flow into new tab for initial account

* Begin wiring up account derivation in service, generate implicit address
to store and return

* Add account derivation to completion process, load and display accounts

* Better error-handling, add user feedback on account creation

* Adding AccountListing components

* Clean up configs, layout, fixed bug in key storage

* KeyRing state is no longer duplicated, storage is only source of truth

* Add icon for copy to clipboard, additional styling, update styled config

* description -> alias to match cli, clean up

* Adding UI for adding a new derived account with basic validation

* Fix bug where alias is not being saved

* Add "alias" as a field during setup

* Updating for consistency, rough pass at styling derivation form

* Move path items to number, validate inputs, set primes appropriately

* Remove unnecessary folders, directly link build to App and Setup

* Minor changes per PR feedback

* Linting, final bit of PR feedback

* Commiting artifacts for legacy @anoma/wasm package, remove from build

* Fix e2e tests (don't run wasm:build - it's unnecessary)

* Disable unit test workflow on PR push (until we have updated wasm)

* Disable reporting on unit tests for now (until building against latest
Namada)

* Disable unit test reporting for now
  • Loading branch information
jurevans authored Oct 7, 2022
1 parent 6758a45 commit c1069da
Show file tree
Hide file tree
Showing 162 changed files with 6,987 additions and 335 deletions.
49 changes: 25 additions & 24 deletions .github/workflows/deploy-wallet-at-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,31 @@ jobs:
with:
version: "v0.10.3"

- name: Run unit tests
id: run-unit-tests
working-directory: ./apps/namada-interface
run: yarn test:coverage
env:
REACT_APP_ALIAS: "Namada Mainnet"
REACT_APP_CHAIN_ID: "anoma-masp-1.5.32ccad5356012a7"
REACT_APP_LEDGER_URL: "https://d3brk13lbhxfdb.cloudfront.net/anoma-masp-1.5.32ccad5356012a7"
REACT_APP_FAUCET: "atest1v4ehgw36gc6yxvpjxccyzvphxycrxw2xxsuyydesxgcnjs3cg9znwv3cxgmnj32yxy6rssf5tcqjm3"
# NOTE: Disabling unit tests until wasm dependencies are building against Namada v0.7.1+
# - name: Run unit tests
# id: run-unit-tests
# working-directory: ./apps/namada-interface
# run: yarn test:coverage
# env:
# REACT_APP_ALIAS: "Namada Mainnet"
# REACT_APP_CHAIN_ID: "anoma-masp-1.5.32ccad5356012a7"
# REACT_APP_LEDGER_URL: "https://d3brk13lbhxfdb.cloudfront.net/anoma-masp-1.5.32ccad5356012a7"
# REACT_APP_FAUCET: "atest1v4ehgw36gc6yxvpjxccyzvphxycrxw2xxsuyydesxgcnjs3cg9znwv3cxgmnj32yxy6rssf5tcqjm3"

- name: report success
if: steps.run-unit-tests.outcome == 'success'
run: |
curl --header "Content-Type: application/json" \
--request POST \
--data '{"message":"Unit tests succeeded ✅\n \n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n \nReview\nhttps://pull-request-${{ github.event.number }}--wallet-development-heliax-dev.netlify.app\n \nthe PR\nhttps://github.com/anoma/namada-interface/pull/${{ github.event.number }}"}' \
${{ secrets.SLACK_WEBHOOK_WALLET_PR }}
- name: report failure
if: steps.run-unit-tests.outcome != 'success'
run: |
curl --header "Content-Type: application/json" \
--request POST \
--data '{"message":"Unit tests failed ⛔️ \n \n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n \nReview\nhttps://pull-request-${{ github.event.number }}--wallet-development-heliax-dev.netlify.app\n \nthe PR\nhttps://github.com/anoma/namada-interface/pull/${{ github.event.number }}"}' \
${{ secrets.SLACK_WEBHOOK_WALLET_PR }}
# - name: report success
# if: steps.run-unit-tests.outcome == 'success'
# run: |
# curl --header "Content-Type: application/json" \
# --request POST \
# --data '{"message":"Unit tests succeeded ✅\n \n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n \nReview\nhttps://pull-request-${{ github.event.number }}--wallet-development-heliax-dev.netlify.app\n \nthe PR\nhttps://github.com/anoma/namada-interface/pull/${{ github.event.number }}"}' \
# ${{ secrets.SLACK_WEBHOOK_WALLET_PR }}
# - name: report failure
# if: steps.run-unit-tests.outcome != 'success'
# run: |
# curl --header "Content-Type: application/json" \
# --request POST \
# --data '{"message":"Unit tests failed ⛔️ \n \n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n \nReview\nhttps://pull-request-${{ github.event.number }}--wallet-development-heliax-dev.netlify.app\n \nthe PR\nhttps://github.com/anoma/namada-interface/pull/${{ github.event.number }}"}' \
# ${{ secrets.SLACK_WEBHOOK_WALLET_PR }}
build:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -119,7 +120,7 @@ jobs:
with:
version: "v0.10.3"
- name: Install dependencies
run: yarn wasm:build && yarn
run: yarn
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
Expand Down
1 change: 1 addition & 0 deletions apps/extension/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.css
*.svg
webpack.config.js
6 changes: 0 additions & 6 deletions apps/extension/babel-plugin-macros.config.js

This file was deleted.

21 changes: 15 additions & 6 deletions apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,46 @@
"wasm:build": "./scripts/build.sh"
},
"dependencies": {
"@anoma/components": "0.1.0",
"@anoma/crypto": "0.1.0",
"@anoma/rpc": "0.1.0",
"@anoma/shared": "0.1.0",
"@anoma/storage": "0.1.0",
"@anoma/types": "0.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"@anoma/utils": "0.1.0",
"framer-motion": "6.2.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "6",
"styled-components": "^5.3.5",
"typescript": "^4.8.2",
"uuid": "^9.0.0",
"webextension-polyfill": "^0.10.0"
},
"devDependencies": {
"@svgr/webpack": "^6.3.1",
"@types/chrome": "^0.0.196",
"@types/firefox-webext-browser": "^94.0.1",
"@types/jest": "^29.0.0",
"@types/node": "^18.7.14",
"@types/react": "^18.0.18",
"@types/react-dom": "^18.0.6",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"@types/styled-components": "^5.1.26",
"@types/uuid": "^8.3.4",
"@types/webextension-polyfill": "^0.9.0",
"babel-plugin-styled-components": "^2.0.7",
"copy-webpack-plugin": "^11.0.0",
"eslint": "^8.23.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.5.0",
"file-loader": "^6.2.0",
"jest": "^29.0.1",
"merge-jsons-webpack-plugin": "^2.0.1",
"rimraf": "^3.0.2",
"ts-loader": "^9.3.1",
"ts-node": "^10.9.1",
"webpack-cli": "^4.10.0"
"typescript-plugin-styled-components": "^2.0.0",
"webpack-cli": "^4.10.0",
"webpack-extension-reloader": "^1.1.4"
}
}
52 changes: 52 additions & 0 deletions apps/extension/src/App/Accounts/AccountListing.components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import styled from "styled-components";

export const AccountListingContainer = styled.div`
display: flex;
flex-direction: row;
width: 100%;
background-color: ${(props) => props.theme.colors.utility1.main};
color: ${(props) => props.theme.colors.utility1.main40};
box-sizing: border-box;
border: 1px solid ${(props) => props.theme.colors.utility1.main};
border-radius: 8px;
box-sizing: border-box;
font-size: 10px;
padding: 4px 8px;
`;

export const Details = styled.div`
display: flex;
flex-direction: column;
justify-content: flex-start;
flex: 3;
`;

export const Buttons = styled.div`
display: flex;
flex-direction: row;
justify-content: flex-end;
flex: 1;
`;

export const DerivationPath = styled.div``;

export const Address = styled.div``;

export const Alias = styled.div``;

export const CopyToClipboard = styled.a`
text-decoration: underline;
padding: 5px;
transition: "1 sec";
border-radius: 4px;
& > div > svg > path {
fill: ${(props) => props.theme.colors.utility1.main40};
stroke: ${(props) => props.theme.colors.utility1.main40};
}
&:active {
border: 1px solid ${(props) => props.theme.colors.primary.main};
background-color: ${(props) => props.theme.colors.primary.main};
}
`;
51 changes: 51 additions & 0 deletions apps/extension/src/App/Accounts/AccountListing.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Icon, IconName } from "@anoma/components";
import {
AccountListingContainer,
Address,
Buttons,
Details,
Alias,
DerivationPath,
CopyToClipboard,
} from "./AccountListing.components";

import { DerivedAccount } from "background/keyring";

type Props = {
account: DerivedAccount;
};

const textToClipboard = (content: string): void => {
navigator.clipboard.writeText(content);
};

const AccountListing = ({ account }: Props): JSX.Element => {
const { address, alias, bip44Path, establishedAddress } = account;
const coinType = "0'";

return (
<AccountListingContainer>
<Details>
{alias && <Alias>{alias}</Alias>}
<DerivationPath>
m/44'/{coinType}/{`${bip44Path.account}'`}/{bip44Path.change}/
{bip44Path.index}
</DerivationPath>
<Address>{address}</Address>
{establishedAddress && <Address>{establishedAddress}</Address>}
</Details>
<Buttons>
<CopyToClipboard
onClick={() => {
textToClipboard(address);
}}
href="#"
>
<Icon iconName={IconName.Copy} />
</CopyToClipboard>
</Buttons>
</AccountListingContainer>
);
};

export default AccountListing;
51 changes: 51 additions & 0 deletions apps/extension/src/App/Accounts/Accounts.components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import styled from "styled-components";

export const AccountsContainer = styled.div`
display: flex;
flex-direction: column;
height: 100%;
width: 100%;
box-sizing: border-box;
padding: 0 8px;
`;

export const AccountsList = styled.ul`
list-style-type: none;
padding: 0;
margin: 0 0 8px;
width: 100%;
`;

export const AccountsListItem = styled.li`
padding: 2px 0;
background-color: ${(props) => props.theme.colors.utility1.main80};
color: ${(props) => props.theme.colors.utility1.main60};
`;

export const ButtonContainer = styled.div`
display: flex;
flex-direction: row;
justify-content: flex-end;
box-sizing: border-box;
`;

export const Button = styled.button`
display: flex;
flex-direction: row;
justify-contents: start;
align-items: center;
cursor: pointer;
color: ${(props) => props.theme.colors.utility1.main40};
background-color: ${(props) => props.theme.colors.utility1.main};
border: 1px solid ${(props) => props.theme.colors.utility1.main};
border-radius: 8px;
& > div > svg > path {
fill: ${(props) => props.theme.colors.utility1.main40};
stroke: ${(props) => props.theme.colors.utility1.main40};
}
`;

export const ButtonText = styled.span`
padding: 8px;
`;
42 changes: 42 additions & 0 deletions apps/extension/src/App/Accounts/Accounts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { useNavigate } from "react-router-dom";
import { Icon, IconName } from "@anoma/components";

import { TopLevelRoute } from "App/types";
import { DerivedAccount } from "background/keyring";
import {
AccountsContainer,
AccountsList,
AccountsListItem,
ButtonContainer,
Button,
ButtonText,
} from "./Accounts.components";
import { AccountListing } from "App/Accounts";

type Props = {
accounts: DerivedAccount[];
};

const Accounts = ({ accounts }: Props): JSX.Element => {
const navigate = useNavigate();

return (
<AccountsContainer>
<AccountsList>
{accounts.map((account) => (
<AccountsListItem key={`account-${account.id}`}>
<AccountListing account={account} />
</AccountsListItem>
))}
</AccountsList>
<ButtonContainer>
<Button onClick={() => navigate(TopLevelRoute.WalletAddAccount)}>
<ButtonText>Derive new account</ButtonText>
<Icon iconName={IconName.Plus} />
</Button>
</ButtonContainer>
</AccountsContainer>
);
};

export default Accounts;
Loading

0 comments on commit c1069da

Please sign in to comment.