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

feat(wallet-template): accounts #1965

Merged
merged 25 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
55a7680
Merge remote-tracking branch 'origin/main'
ryanleecode Mar 9, 2024
142caed
gogogogogo
ryanleecode Mar 10, 2024
dfbbc5e
more
ryanleecode Mar 11, 2024
6438305
more
ryanleecode Mar 11, 2024
3816175
more
ryanleecode Mar 11, 2024
0c83e88
prevent conflicts
ryanleecode Mar 11, 2024
455066a
more
ryanleecode Mar 11, 2024
06d18d1
gogogogogo
ryanleecode Mar 12, 2024
11399e2
Merge remote-tracking branch 'origin/main' into feat/wallet-template/…
ryanleecode Mar 12, 2024
1f2c9d5
gogo
ryanleecode Mar 13, 2024
7f7d0d8
Merge remote-tracking branch 'origin/main' into feat/wallet-template/…
ryanleecode Mar 13, 2024
3e3dc75
remove react-select
ryanleecode Mar 14, 2024
d0d1954
delete accounts tsx
ryanleecode Mar 14, 2024
55a4710
add useSWR
ryanleecode Mar 14, 2024
96b2737
Merge remote-tracking branch 'origin/main' into feat/wallet-template/…
ryanleecode Mar 14, 2024
a78a64c
remove
ryanleecode Mar 14, 2024
1550f78
add chain ids
ryanleecode Mar 15, 2024
5873506
Merge remote-tracking branch 'origin/main' into feat/wallet-template/…
ryanleecode Mar 15, 2024
be651e1
chore: add type checking
ryanleecode Mar 15, 2024
515a877
fix
ryanleecode Mar 15, 2024
e0946aa
Merge branch 'chore/add-typechecks' into feat/wallet-template/accounts
ryanleecode Mar 15, 2024
7651100
Merge remote-tracking branch 'origin/main' into feat/wallet-template/…
ryanleecode Mar 15, 2024
19f7557
gogo
ryanleecode Mar 15, 2024
1ee061f
extract components
ryanleecode Mar 15, 2024
2f23a04
Merge branch 'main' into feat/wallet-template/accounts
ryanleecode Mar 15, 2024
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
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions projects/wallet-template/assets/accounts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<title>Substrate Connect Accounts</title>
<meta charset="utf-8" />
</head>
<body style="background-color: #f9f9f9">
<div id="accounts"></div>
<script type="module" src="../src/accounts.tsx"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions projects/wallet-template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,20 @@
"@polkadot-api/substrate-client": "0.0.1-492c132563ea6b40ae1fc5470dec4cd18768d182.1.0",
"@polkadot-api/tx-helper": "0.0.1-492c132563ea6b40ae1fc5470dec4cd18768d182.1.0",
"@polkadot-api/utils": "0.0.1-492c132563ea6b40ae1fc5470dec4cd18768d182.1.0",
"@substrate/connect-known-chains": "workspace:^",
"@polkadot-labs/hdkd": "^0.0.5",
"@polkadot-labs/hdkd-helpers": "^0.0.5",
"@react-rxjs/core": "^0.10.7",
"@react-rxjs/utils": "^0.9.7",
"@substrate/connect-extension-protocol": "workspace:*",
"@substrate/light-client-extension-helpers": "workspace:^",
"lucide-react": "^0.352.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.51.0",
"react-icons": "^4.11.0",
"react-router-dom": "^6.22.3",
"react-select": "^5.8.0",
ryanleecode marked this conversation as resolved.
Show resolved Hide resolved
"rxjs": "^7.8.1",
"smoldot": "2.0.22",
"swr": "^2.2.5"
Expand Down
5 changes: 5 additions & 0 deletions projects/wallet-template/src/accounts.tsx
ryanleecode marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { render } from "react-dom"
import { Accounts } from "./containers/Accounts"
import "./style.css"

render(<Accounts />, document.getElementById("accounts"))
30 changes: 29 additions & 1 deletion projects/wallet-template/src/background/createBackgroundRpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
getTxCreator,
} from "@polkadot-api/tx-helper"

import type { BackgroundRpcSpec, SignRequest } from "./types"
import type { BackgroundRpcSpec, Keyset, SignRequest } from "./types"

Check warning on line 23 in projects/wallet-template/src/background/createBackgroundRpc.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

'Keyset' is defined but never used

Check warning on line 23 in projects/wallet-template/src/background/createBackgroundRpc.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'Keyset' is defined but never used

Check warning on line 23 in projects/wallet-template/src/background/createBackgroundRpc.ts

View workflow job for this annotation

GitHub Actions / playwright-test-wallet-template

'Keyset' is defined but never used

Check warning on line 23 in projects/wallet-template/src/background/createBackgroundRpc.ts

View workflow job for this annotation

GitHub Actions / playwright-test-extension

'Keyset' is defined but never used

Check warning on line 23 in projects/wallet-template/src/background/createBackgroundRpc.ts

View workflow job for this annotation

GitHub Actions / zombienet-tests

'Keyset' is defined but never used

Check warning on line 23 in projects/wallet-template/src/background/createBackgroundRpc.ts

View workflow job for this annotation

GitHub Actions / playwright-test-examples

'Keyset' is defined but never used

Check warning on line 23 in projects/wallet-template/src/background/createBackgroundRpc.ts

View workflow job for this annotation

GitHub Actions / connect-flaky-tests

'Keyset' is defined but never used

const entropy = mnemonicToEntropy(DEV_PHRASE)
const miniSecret = entropyToMiniSecret(entropy)
Expand Down Expand Up @@ -79,6 +79,12 @@
signRequests: Record<string, InternalSignRequest>
port: chrome.runtime.Port
}

const listKeysets = async () => {
const keysets = (await chrome.storage.local.get("keysets")) || {}
return keysets["keysets"] || {}
}
ryanleecode marked this conversation as resolved.
Show resolved Hide resolved

const handlers: RpcMethodHandlers<BackgroundRpcSpec, Context> = {
async getAccounts([chainId], { lightClientPageHelper }) {
const chains = await lightClientPageHelper.getChains()
Expand Down Expand Up @@ -215,6 +221,28 @@
async changePassword([currentPassword, newPassword]) {
keyring.changePassword(currentPassword, newPassword)
},
async insertKeyset([keysetName, keyset]) {
const existingKeysets = await listKeysets()
await chrome.storage.local.set({
keysets: {
...existingKeysets,
[keysetName]: keyset,
ryanleecode marked this conversation as resolved.
Show resolved Hide resolved
},
})
},
async getKeyset([keysetName]) {
const keysets = await listKeysets()
return keysets[keysetName]
},
listKeysets,
async removeKeyset([keysetName]) {
const keysets = await listKeysets()
delete keysets[keysetName]
await chrome.storage.local.set({ keysets })
},
async clearKeysets() {
await chrome.storage.local.remove("keysets")
},
}

type Method = keyof BackgroundRpcSpec
Expand Down
11 changes: 11 additions & 0 deletions projects/wallet-template/src/background/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export type Account = {
address: string
}

export type Keyset = {
scheme: string
entropy: string
derivationPaths: string[]
ryanleecode marked this conversation as resolved.
Show resolved Hide resolved
}

export type SignRequest = {
url: string
chainId: string
Expand All @@ -29,4 +35,9 @@ export type BackgroundRpcSpec = {
unlockKeyring(password: string): Promise<void>
isKeyringLocked(): Promise<boolean>
changePassword(currentPassword: string, newPassword: string): Promise<void>
insertKeyset(keysetName: string, keyset: Keyset): Promise<void>
getKeyset(keysetName: string): Promise<Keyset | undefined>
listKeysets(): Promise<Record<string, Keyset>>
removeKeyset(keysetName: string): Promise<void>
clearKeysets(): Promise<void>
}
27 changes: 27 additions & 0 deletions projects/wallet-template/src/components/StepIndicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CheckCircle } from "lucide-react"

const range = (start: number, end: number) => {
return Array.from({ length: end - start + 1 }, (_, i) => start + i)
}

type StepIndicatorProps = {
currentStep: number
steps: number
}

export const StepIndicator = ({ currentStep, steps }: StepIndicatorProps) => (
<div className="flex justify-center my-6 space-x-4">
{range(1, Math.max(1, steps)).map((step) => (
<div
key={step}
className={`w-8 h-8 rounded-full flex items-center justify-center ${
currentStep >= step
? "bg-blue-500 text-white"
: "bg-gray-200 text-gray-500"
}`}
>
{currentStep > step ? <CheckCircle size="20" /> : step}
</div>
))}
</div>
)
1 change: 1 addition & 0 deletions projects/wallet-template/src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export { IconWeb3 } from "./IconWeb3"
export { Bootnodes } from "./Bootnodes"
export { Title } from "./Title"
export { Switch } from "./Switch"
export { StepIndicator } from "./StepIndicator"
13 changes: 13 additions & 0 deletions projects/wallet-template/src/containers/Accounts/index.tsx
ryanleecode marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { HashRouter, Routes, Route } from "react-router-dom"
import { AddAccount, Home } from "./pages"

export const Accounts = () => {
return (
<HashRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/add" element={<AddAccount />} />
</Routes>
</HashRouter>
)
}
38 changes: 38 additions & 0 deletions projects/wallet-template/src/containers/Accounts/networks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export type Network = {
label: string
value: string
logo: string
}

export const networks: Network[] = [
{
value: "polkadot",
label: "Polkadot",
logo: "https://cryptologos.cc/logos/polkadot-new-dot-logo.svg",
},
{
value: "westend2",
label: "Westend",
logo: "https://i.imgur.com/Dwb1yMS.png",
},
{
value: "ksmcc3",
label: "Kusama",
logo: "https://cryptologos.cc/logos/kusama-ksm-logo.svg",
},
{
value: "polkadot_asset_hub",
label: "Polkadot Asset Hub",
logo: "https://i.imgur.com/Vu3xpq2.png",
},
{
value: "westend_asset_hub",
label: "Westend Asset Hub",
logo: "https://i.imgur.com/RkU4UQQ.png",
},
{
value: "kusama_asset_hub",
label: "Kusama Asset Hub",
logo: "https://i.imgur.com/Q1bH3U9.png",
},
]
Loading
Loading