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

UI update/amount picker #543

Merged
merged 23 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
97c367a
Add token amount input component
soerenbf Oct 17, 2024
b746b0a
Move styling from sendfunds component, add storybook story
soerenbf Oct 17, 2024
5454222
Express different amount input variants
soerenbf Oct 17, 2024
3137152
Change token amount component to depend on being fed a form context
soerenbf Oct 17, 2024
f3d1e2d
Amount input field
soerenbf Oct 17, 2024
3715b0f
Add expected sizes to storybook
soerenbf Oct 18, 2024
a1ea54b
Ensure consistent amount formatting
soerenbf Oct 18, 2024
fe467ab
Amount input validation
soerenbf Oct 18, 2024
12e7679
JSDoc
soerenbf Oct 18, 2024
40fefca
Add function for parsing the formatted token amounts
soerenbf Oct 21, 2024
a758001
Take in props for account and tokens
soerenbf Oct 21, 2024
d026fa1
Hook for extracting token info for `TokenAmount`
soerenbf Oct 21, 2024
c8b4953
Token images with fallback
soerenbf Oct 21, 2024
78e25c1
Create connected version of token amount component
soerenbf Oct 21, 2024
44436cd
Enable selection
soerenbf Oct 21, 2024
3ffd4dd
Merge branch 'browser-ui-update' into ui-update/amount-picker
soerenbf Oct 22, 2024
4bf06d9
Add to index file
soerenbf Oct 22, 2024
ca279d5
Change receiver input to textarea
soerenbf Oct 22, 2024
de2b407
Take account info as prop
soerenbf Oct 22, 2024
4a79c63
Use ccd metadata constant
soerenbf Oct 22, 2024
72062cb
clean up shared functionality
soerenbf Oct 24, 2024
db560e0
Remove token name from balance
soerenbf Oct 24, 2024
b7f576e
Merge branch 'browser-ui-update' into ui-update/amount-picker
soerenbf Oct 24, 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
18 changes: 17 additions & 1 deletion packages/browser-wallet/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ const pathToSvgAssets = path.resolve(__dirname, '../src/assets/svg');

module.exports = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
staticDirs: [{ from: '../src/assets', to: '/assets' }],

addons: [
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-interactions'),
getAbsolutePath('@storybook/preset-scss'),
getAbsolutePath('@storybook/addon-webpack5-compiler-swc'),
getAbsolutePath('@storybook/addon-viewport'),
],

framework: {
Expand All @@ -34,7 +36,21 @@ module.exports = {
rules.push({
test: /\.svg$/,
include: pathToSvgAssets,
use: ['@svgr/webpack'],
use: [
{
loader: '@svgr/webpack',
options: {
svgoConfig: {
plugins: [
{
name: 'removeViewBox',
active: false,
},
],
},
},
},
],
});

config.resolve.plugins = [new TsconfigPathsPlugin()];
Expand Down
42 changes: 41 additions & 1 deletion packages/browser-wallet/.storybook/preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import React, { useEffect } from 'react';
import '../src/popup/index.scss';
import '../src/popup/shell/i18n';

// Workaround for bigint serialization error: https://github.com/storybookjs/storybook/issues/22452
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line no-extend-native, func-names
BigInt.prototype.toJSON = function () {
return this.toString();
};

document.getElementsByTagName('html').item(0)?.classList.add('ui-scale-large');

/**
Expand Down Expand Up @@ -30,14 +38,46 @@ const themeDecorator = (Story, { globals, parameters }) => {
return <Story />;
};

/**
* Adds custom styling to the HTML surrounding individual stories.
*/
const customStyleDecorator = (Story) => {
return (
<div style={{ padding: '0.5rem' }}>
<Story />
</div>
);
};

export const parameters = {
viewport: {
viewports: {
Small: {
name: 'Small',
styles: {
width: '312px',
height: '528px',
},
},
Normal: {
name: 'Normal',
styles: {
width: '375px',
height: '600px',
},
},
},
// Optionally, you can set default viewports
defaultViewport: 'Normal',
},
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
backgrounds: { default: 'dark' },
};

export const decorators = [themeDecorator];
export const decorators = [themeDecorator, customStyleDecorator];
export const tags = ['autodocs'];
1 change: 1 addition & 0 deletions packages/browser-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@storybook/addon-essentials": "^8.3.5",
"@storybook/addon-interactions": "^8.3.5",
"@storybook/addon-links": "^8.3.5",
"@storybook/addon-viewport": "^8.3.5",
"@storybook/addon-webpack5-compiler-swc": "^1.0.5",
"@storybook/preset-scss": "^1.0.3",
"@storybook/react": "^8.3.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import FileText from '@assets/svgX/file-text.svg';
import ConcordiumLogo from '@assets/svgX/concordium-logo.svg';
import Plant from '@assets/svgX/plant.svg';
import Gear from '@assets/svgX/gear.svg';
import { formatTokenAmount } from '@popup/popupX/shared/utils/helpers';

/** Hook loading every fungible token added to the account. */
function useAccountFungibleTokens(account: WalletCredential) {
Expand All @@ -34,22 +35,11 @@ function useAccountTokenBalance(accountAddress: string, contractAddress: string,
return balance;
}

/** Display a token balance with a number of decimals. Localized. */
function formatBalance(balance: bigint, decimals: number = 0) {
const padded = balance.toString().padStart(decimals + 1, '0');
const integer = padded.slice(0, -decimals);
const fraction = padded.slice(-decimals);
const balanceFormatter = new Intl.NumberFormat(undefined, { minimumFractionDigits: decimals });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore format below supports strings, TypeScript is just not aware.
return balanceFormatter.format(`${integer}.${fraction}`);
}

type TokenBalanceProps = { decimals?: number; tokenId: string; contractAddress: string; accountAddress: string };
/** Component for fetching and displaying a CIS-2 token balance of an account. */
function AccountTokenBalance({ decimals, tokenId, contractAddress, accountAddress }: TokenBalanceProps) {
const balanceRaw = useAccountTokenBalance(accountAddress, contractAddress, tokenId) ?? 0n;
const balance = useMemo(() => formatBalance(balanceRaw, decimals), [balanceRaw]);
const balance = useMemo(() => formatTokenAmount(balanceRaw, decimals), [balanceRaw]);
return <span>{balance}</span>;
}

Expand Down
19 changes: 13 additions & 6 deletions packages/browser-wallet/src/popup/popupX/shared/Form/Form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
margin-bottom: rem(8px);
width: 100%;
outline: none;
font-size: rem(14px); /* override base style, remove after release */
transform: unset; /* override base style, remove after release */
font-size: rem(14px);
/* override base style, remove after release */
transform: unset;
/* override base style, remove after release */
@include transition(border-color);

&:focus {
Expand Down Expand Up @@ -76,6 +78,7 @@
transform: unset;

svg {

g,
path {
fill: $color-mineral-3;
Expand Down Expand Up @@ -110,11 +113,11 @@ $handle-size: rem(20px);

.form-toggle-x {
&__root {
input:checked + .form-toggle-x__slider {
input:checked+.form-toggle-x__slider {
background-color: $color-green-toggle;
}

input:checked + .form-toggle-x__slider::before {
input:checked+.form-toggle-x__slider::before {
transform: translateX(rem(24px));
}
}
Expand Down Expand Up @@ -191,11 +194,11 @@ $handle-size: rem(20px);
}
}

&:hover input ~ .checkmark {
&:hover input~.checkmark {
background-color: $color-grey-3;
}

input:checked ~ .checkmark::after {
input:checked~.checkmark::after {
display: block;
}

Expand All @@ -206,3 +209,7 @@ $handle-size: rem(20px);
}
}
}

.form-error-message {
color: $color-red-attention !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Props = Pick<InputHTMLAttributes<HTMLInputElement>, 'className' | 'autoFocu
* Password input with reveal button and optional strength check.
*/
export function Password({ showStrength = false, value, className, autoFocus, ...props }: Props) {
const { t } = useTranslation();
const { t } = useTranslation('x', { keyPrefix: 'sharedX' });
const [reveal, setReveal] = useState(false);

const strength = useMemo(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
.token-amount {
display: flex;
flex-direction: column;
border-radius: rem(16px);
background: $gradient-card-bg;
margin-top: rem(16px);
padding: rem(20px) rem(16px);

.text__main_medium,
.text__main {
color: $color-black;
}

.capture__main_small {
color: $color-grey-3
}

.capture__additional_small {
padding: rem(4px);
border-radius: rem(4px);
color: $color-black;
background: $secondary-button-bg;
}

&_token,
&_amount,
&_receiver {
display: flex;
flex-direction: column;
}

&_token {
.token-selector-container {
flex-wrap: wrap;
display: flex;
align-items: center;
margin-top: rem(12px);
padding-bottom: rem(12px);
border-bottom: 1px solid rgba($color-black, 0.1);

.token-selector {
display: flex;
cursor: pointer;
position: relative;
}

.text__additional_small {
margin-left: auto;
text-wrap: nowrap;
}

.token-icon {
display: flex;
padding: rem(5px);
margin-right: rem(8px);
border-radius: rem(6px);
background: $color-grey-1;

svg,
img {
width: rem(14px);
height: rem(14px);
}
}

select {
appearance: none;
background: none;
border: none;
position: absolute;
z-index: 0;
color: transparent;
width: 100%;
height: 100%;

&::selection {
background-color: transparent;
}
}
}
}

&_amount {
position: relative;
margin-top: rem(24px);

&_selector {
display: flex;
align-items: center;
justify-content: space-between;
padding: rem(8px) 0;
margin-bottom: rem(4px);
border-bottom: 1px solid rgba($color-black, 0.1);

.heading_medium {
color: $color-black;
}
}

&_field {
flex: 1;
min-width: 0;
margin-right: rem(4px);
}

&_max {
flex: 0;
text-wrap: nowrap;
}
}

&_field {
border: none;
width: 100%;
background: none;

&--invalid {
color: $color-red-attention !important;
}
}

button.capture__additional_small {
border: unset;
cursor: pointer;
}

&_receiver {
margin-top: rem(24px);

.address-selector {
display: flex;
justify-content: space-between;
margin-top: rem(12px);
}

textarea {
resize: none;
}
}
}
Loading
Loading