Skip to content

Commit

Permalink
Merge branch 'develop' into fix-typos-2
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Jul 3, 2024
2 parents 328f9d5 + 1ec56b5 commit 8e9bba4
Show file tree
Hide file tree
Showing 38 changed files with 1,076 additions and 122 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ docs/content/references/framework/**
lcov.info
**/venv/

*storybook.log

# iota-private-network
docker/iota-private-network/data
docker/iota-private-network/configs/validators/validator*
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions apps/ui-kit/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
storybook-static/
31 changes: 31 additions & 0 deletions apps/ui-kit/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { dirname, join } from 'path';
import type { StorybookConfig } from '@storybook/react-vite';

function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, 'package.json')));
}

const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: [
getAbsolutePath('@storybook/addon-a11y'),
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-interactions'),
'@chromatic-com/storybook',
],

framework: {
name: getAbsolutePath('@storybook/react-vite'),
options: {},
},
typescript: {
reactDocgen: 'react-docgen-typescript',
},
docs: {},
};

export default config;
17 changes: 17 additions & 0 deletions apps/ui-kit/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import type { Preview } from '@storybook/react';

const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
},
};

export default preview;
44 changes: 44 additions & 0 deletions apps/ui-kit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@iota/apps-ui-kit",
"private": true,
"sideEffects": false,
"repository": {
"type": "git",
"url": "github.com:iotaledger/iota.git"
},
"license": "Apache-2.0",
"scripts": {
"prettier:check": "prettier -c --ignore-unknown .",
"prettier:fix": "prettier -w --ignore-unknown .",
"eslint:check": "eslint --max-warnings=0 .",
"eslint:fix": "pnpm run eslint:check --fix",
"lint": "pnpm run eslint:check && pnpm run prettier:check",
"lint:fix": "pnpm run eslint:fix && pnpm run prettier:fix",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"dev": "pnpm run storybook"
},
"dependencies": {
"@iota/core": "workspace:*",
"@iota/icons": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.6.0",
"@storybook/addon-essentials": "^7.1.0",
"@storybook/addon-interactions": "^7.1.0",
"@storybook/addon-links": "^7.1.0",
"@storybook/addon-onboarding": "^8.1.11",
"@storybook/blocks": "^7.1.0",
"@storybook/react": "^7.1.0",
"@storybook/react-vite": "^7.1.0",
"@storybook/test": "^8.1.11",
"@types/react": "^18.2.15",
"storybook": "^7.1.0",
"tailwindcss": "^3.3.3",
"typescript": "^5.3.3",
"vite": "^4.4.4",
"vite-tsconfig-paths": "^4.2.0"
}
}
9 changes: 9 additions & 0 deletions apps/ui-kit/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
12 changes: 12 additions & 0 deletions apps/ui-kit/src/lib/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import React from 'react';

export interface ButtonProps {
label: string;
}

export function Button({ label }: ButtonProps): React.JSX.Element {
return <button className="p-2 border rounded-full border-blue-500">{label}</button>;
}
4 changes: 4 additions & 0 deletions apps/ui-kit/src/lib/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

export * from './Button';
26 changes: 26 additions & 0 deletions apps/ui-kit/src/stories/Button.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import type { Meta, StoryObj } from '@storybook/react';

import { Button } from '@/components';

const meta = {
component: Button,
tags: ['autodocs'],
render: (props) => {
return (
<div className="flex flex-col gap-2 items-start">
<Button {...props}>Primary</Button>
</div>
);
},
} satisfies Meta<typeof Button>;
export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
label: 'Button',
},
};
9 changes: 9 additions & 0 deletions apps/ui-kit/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import preset from '@iota/core/tailwind.config';
import { type Config } from 'tailwindcss';

export default {
presets: [preset],
} satisfies Partial<Config>;
25 changes: 25 additions & 0 deletions apps/ui-kit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es2020",
"module": "esnext",
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"noEmit": true,
"isolatedModules": true,
"sourceMap": true,
"jsx": "react-jsx",
"paths": {
"@/*": ["./src/*"],
"@/components": ["./src/lib/components"],
"@/components/*": ["./src/lib/components/*"]
}
},
"include": ["src"],
"exclude": ["node_modules"]
}
10 changes: 10 additions & 0 deletions apps/ui-kit/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
plugins: [
tsconfigPaths({
root: __dirname,
}),
],
});
4 changes: 2 additions & 2 deletions apps/wallet/src/background/accounts/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import { accountsEvents } from './events';
export enum AccountType {
MnemonicDerived = 'mnemonic-derived',
SeedDerived = 'seed-derived',
Imported = 'imported',
Ledger = 'ledger',
PrivateKeyDerived = 'private-key-derived',
LedgerDerived = 'ledger-derived',
}

export abstract class Account<
Expand Down
12 changes: 6 additions & 6 deletions apps/wallet/src/background/accounts/ImportedAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ type SessionStorageData = { keyPair: string };
type EncryptedData = { keyPair: string };

export interface ImportedAccountSerialized extends SerializedAccount {
type: AccountType.Imported;
type: AccountType.PrivateKeyDerived;
encrypted: string;
publicKey: string;
}

export interface ImportedAccountSerializedUI extends SerializedUIAccount {
type: AccountType.Imported;
type: AccountType.PrivateKeyDerived;
publicKey: string;
}

export function isImportedAccountSerializedUI(
account: SerializedUIAccount,
): account is ImportedAccountSerializedUI {
return account.type === AccountType.Imported;
return account.type === AccountType.PrivateKeyDerived;
}

export class ImportedAccount
Expand All @@ -52,7 +52,7 @@ export class ImportedAccount
keyPair: inputs.keyPair,
};
return {
type: AccountType.Imported,
type: AccountType.PrivateKeyDerived,
address: keyPair.getPublicKey().toIotaAddress(),
publicKey: keyPair.getPublicKey().toBase64(),
encrypted: await encrypt(inputs.password, dataToEncrypt),
Expand All @@ -64,11 +64,11 @@ export class ImportedAccount
}

static isOfType(serialized: SerializedAccount): serialized is ImportedAccountSerialized {
return serialized.type === AccountType.Imported;
return serialized.type === AccountType.PrivateKeyDerived;
}

constructor({ id, cachedData }: { id: string; cachedData?: ImportedAccountSerialized }) {
super({ type: AccountType.Imported, id, cachedData });
super({ type: AccountType.PrivateKeyDerived, id, cachedData });
}

async lock(allowRead = false): Promise<void> {
Expand Down
12 changes: 6 additions & 6 deletions apps/wallet/src/background/accounts/LedgerAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import {
} from './Account';

export interface LedgerAccountSerialized extends SerializedAccount {
type: AccountType.Ledger;
type: AccountType.LedgerDerived;
derivationPath: string;
// just used for authentication nothing is stored here at the moment
encrypted: string;
}

export interface LedgerAccountSerializedUI extends SerializedUIAccount {
type: AccountType.Ledger;
type: AccountType.LedgerDerived;
derivationPath: string;
}

export function isLedgerAccountSerializedUI(
account: SerializedUIAccount,
): account is LedgerAccountSerializedUI {
return account.type === AccountType.Ledger;
return account.type === AccountType.LedgerDerived;
}

type EphemeralData = {
Expand All @@ -52,7 +52,7 @@ export class LedgerAccount
derivationPath: string;
}): Promise<Omit<LedgerAccountSerialized, 'id'>> {
return {
type: AccountType.Ledger,
type: AccountType.LedgerDerived,
address,
publicKey,
encrypted: await encrypt(password, {}),
Expand All @@ -65,11 +65,11 @@ export class LedgerAccount
}

static isOfType(serialized: SerializedAccount): serialized is LedgerAccountSerialized {
return serialized.type === AccountType.Ledger;
return serialized.type === AccountType.LedgerDerived;
}

constructor({ id, cachedData }: { id: string; cachedData?: LedgerAccountSerialized }) {
super({ type: AccountType.Ledger, id, cachedData });
super({ type: AccountType.LedgerDerived, id, cachedData });
}

async lock(allowRead = false): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet/src/background/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ export async function accountsHandleUIMessage(msg: Message, uiConnection: UiConn
throw new Error(`Invalid account source type`);
}
newSerializedAccounts.push(await accountSource.deriveAccount());
} else if (type === AccountType.Imported) {
} else if (type === AccountType.PrivateKeyDerived) {
newSerializedAccounts.push(await ImportedAccount.createNew(payload.args));
} else if (type === AccountType.Ledger) {
} else if (type === AccountType.LedgerDerived) {
const { password, accounts } = payload.args;
for (const aLedgerAccount of accounts) {
newSerializedAccounts.push(
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet/src/shared/analytics/ampli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ export interface AddedAccountsProperties {
*
* | Rule | Value |
* |---|---|
* | Enum Values | Ledger, Derived, Imported|
* | Enum Values | Ledger, Derived, Private Key|
*/
accountType: 'Ledger' | 'Derived' | 'Imported';
accountType: 'Ledger' | 'Derived' | 'Private Key';
/**
* The number of accounts imported.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ type MethodPayloads = {
createAccounts:
| { type: AccountType.MnemonicDerived; sourceID: string }
| { type: AccountType.SeedDerived; sourceID: string }
| { type: AccountType.Imported; keyPair: string; password: string }
| { type: AccountType.PrivateKeyDerived; keyPair: string; password: string }
| {
type: AccountType.Ledger;
type: AccountType.LedgerDerived;
accounts: { publicKey: string; derivationPath: string; address: string }[];
password: string;
};
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet/src/ui/app/ApiProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { type WalletSigner } from './WalletSigner';
const ACCOUNT_TYPES_WITH_BACKGROUND_SIGNER: AccountType[] = [
AccountType.MnemonicDerived,
AccountType.SeedDerived,
AccountType.Imported,
AccountType.PrivateKeyDerived,
];

export default class ApiProvider {
Expand Down Expand Up @@ -60,7 +60,7 @@ export default class ApiProvider {
if (ACCOUNT_TYPES_WITH_BACKGROUND_SIGNER.includes(account.type)) {
return this.getBackgroundSignerInstance(account, backgroundClient);
}
if (AccountType.Ledger === account.type) {
if (AccountType.LedgerDerived === account.type) {
// Ideally, Ledger transactions would be signed in the background
// and exist as an asynchronous keypair; however, this isn't possible
// because you can't connect to a Ledger device from the background
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet/src/ui/app/components/AccountBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ interface AccountBadgeProps {
}

const TYPE_TO_TEXT: Record<AccountType, string | null> = {
[AccountType.Ledger]: 'Ledger',
[AccountType.Imported]: 'Imported',
[AccountType.LedgerDerived]: 'Ledger',
[AccountType.PrivateKeyDerived]: 'Private Key',
[AccountType.MnemonicDerived]: null,
[AccountType.SeedDerived]: null,
};
Expand Down
Loading

0 comments on commit 8e9bba4

Please sign in to comment.