Skip to content

Commit

Permalink
Merge branch 'main' into feat/ui-tailwind
Browse files Browse the repository at this point in the history
# Conflicts:
#	pnpm-lock.yaml
  • Loading branch information
VanishMax committed Nov 7, 2024
2 parents 3a6ad97 + 9ec371b commit ed8563a
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 37 deletions.
20 changes: 20 additions & 0 deletions apps/minifront/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# minifront

## 6.24.5

### Patch Changes

- Updated dependencies [fcb025d]
- @penumbra-zone/ui@12.4.0

## 6.24.4

### Patch Changes

- Updated dependencies [2484bdc]
- @penumbra-zone/ui@12.3.0

## 6.24.3

### Patch Changes

- 6e3fc9d: Supporting forward compatible parsing of Metadata from remote registry

## 6.24.2

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions apps/minifront/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minifront",
"version": "6.24.2",
"version": "6.24.5",
"private": true,
"license": "(MIT OR Apache-2.0)",
"type": "module",
Expand All @@ -22,7 +22,7 @@
"@cosmos-kit/core": "^2.13.1",
"@cosmos-kit/react": "^2.18.0",
"@interchain-ui/react": "^1.23.29",
"@penumbra-labs/registry": "^11.3.1",
"@penumbra-labs/registry": "^12.0.0",
"@penumbra-zone/bech32m": "workspace:*",
"@penumbra-zone/client": "workspace:*",
"@penumbra-zone/crypto-web": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Button } from '@penumbra-zone/ui/components/ui/button';
import { Dialog, DialogContent, DialogHeader } from '@penumbra-zone/ui/components/ui/dialog';
import {
Dialog,
DialogClose,
DialogContent,
DialogHeader,
} from '@penumbra-zone/ui/components/ui/dialog';
import { IdentityKeyComponent } from '@penumbra-zone/ui/components/ui/identity-key-component';
import { InputBlock } from '../../../../shared/input-block';
import { Validator } from '@penumbra-zone/protobuf/penumbra/core/component/stake/v1/stake_pb';
Expand All @@ -9,10 +14,22 @@ import { getIdentityKey } from '@penumbra-zone/getters/validator';
import { getFormattedAmtFromValueView } from '@penumbra-zone/types/value-view';
import { BalanceValueView } from '@penumbra-zone/ui/components/ui/balance-value-view';
import { NumberInput } from '../../../../shared/number-input';
import { CircleAlert } from 'lucide-react';
import { useStoreShallow } from '../../../../../utils/use-store-shallow.ts';
import { AllSlices } from '../../../../../state';
import { bech32mIdentityKey } from '@penumbra-zone/bech32m/penumbravalid';

const getCapitalizedAction = (action: 'delegate' | 'undelegate') =>
action.replace(/^./, firstCharacter => firstCharacter.toLocaleUpperCase());

// If validator has > 5 voting power, show warning to user
const votingPowerSelector =
(validator: Validator, action?: 'delegate' | 'undelegate') => (state: AllSlices) => {
const votingPower =
state.staking.votingPowerByValidatorInfo[bech32mIdentityKey(getIdentityKey(validator))] ?? 0;
return action === 'delegate' && votingPower > 5;
};

/**
* Renders a dialog with a form for delegating to, or undelegating from, a
* validator.
Expand Down Expand Up @@ -51,6 +68,8 @@ export const FormDialog = ({
onClose: () => void;
onSubmit: () => void;
}) => {
const showDelegationWarning = useStoreShallow(votingPowerSelector(validator, action));

const handleOpenChange = (open: boolean) => {
if (!open) {
onClose();
Expand Down Expand Up @@ -87,8 +106,8 @@ export const FormDialog = ({
</div>

{/** @todo: Refactor this block to use `InputToken` (with a new
boolean `showSelectModal` prop) once asset balances are
refactored as `ValueView`s. */}
boolean `showSelectModal` prop) once asset balances are
refactored as `ValueView`s. */}
<InputBlock label={`Amount to ${action}`} className='mb-1' value={amount}>
<NumberInput
variant='transparent'
Expand All @@ -109,14 +128,46 @@ export const FormDialog = ({
)}
</div>
</InputBlock>

<Button type='submit' disabled={amount.length === 0}>
{getCapitalizedAction(action)}
</Button>
{showDelegationWarning ? (
<DelegationVotingPowerWarning amount={amount} />
) : (
<Button type='submit' disabled={amount.length === 0}>
{getCapitalizedAction(action)}
</Button>
)}
</form>
</>
)}
</DialogContent>
</Dialog>
);
};

const DelegationVotingPowerWarning = ({ amount }: { amount: string }) => {
return (
<>
<div className='flex items-center gap-4 text-red'>
<CircleAlert size={50} />
<div>
The validator you’re delegating to has more than 5% of the current voting power. To
promote decentralization, it’s recommended to choose a smaller validator.
</div>
</div>
<div className='flex gap-2'>
<DialogClose className='w-full' asChild>
<Button type='submit' variant='secondary' className='w-1/2'>
Choose another validator
</Button>
</DialogClose>
<Button
type='submit'
disabled={amount.length === 0}
variant='destructive'
className='w-1/2'
>
Delegate anyway
</Button>
</div>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { render } from '@testing-library/react';
import { ValidatorInfo } from '@penumbra-zone/protobuf/penumbra/core/component/stake/v1/stake_pb';
import { ValueView } from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb';
import { AllSlices } from '../../../../../state';
import { IdentityKey } from '@penumbra-zone/protobuf/penumbra/core/keys/v1/keys_pb';

const nonZeroBalance = new ValueView({
valueView: {
Expand All @@ -23,7 +24,16 @@ const zeroBalance = new ValueView({
},
});

const validatorInfo = new ValidatorInfo({ validator: {} });
const validatorInfo = new ValidatorInfo({
validator: {
identityKey: new IdentityKey({
ik: new Uint8Array([
1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4,
5,
]),
}),
},
});

let MOCK_STAKING_TOKENS_AND_FILTER: {
stakingTokens: ValueView | undefined;
Expand All @@ -44,7 +54,7 @@ type RecursivePartial<T> = {
vi.mock('../../../../../utils/use-store-shallow', async () => ({
...(await vi.importActual('../../../../../utils/use-store-shallow')),
useStoreShallow: (selector: (state: RecursivePartial<AllSlices>) => unknown) =>
selector({ staking: { account: 0 } }),
selector({ staking: { account: 0, votingPowerByValidatorInfo: { '': 0 } } }),
}));

describe('<StakingActions />', () => {
Expand Down
14 changes: 14 additions & 0 deletions apps/node-status/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# node-status

## 4.1.39

### Patch Changes

- Updated dependencies [fcb025d]
- @penumbra-zone/ui@12.4.0

## 4.1.38

### Patch Changes

- Updated dependencies [2484bdc]
- @penumbra-zone/ui@12.3.0

## 4.1.37

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/node-status/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-status",
"version": "4.1.37",
"version": "4.1.39",
"private": true,
"license": "(MIT OR Apache-2.0)",
"type": "module",
Expand Down
7 changes: 7 additions & 0 deletions packages/services/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @penumbra-zone/router

## 41.0.1

### Patch Changes

- Updated dependencies [6e3fc9d]
- @penumbra-zone/storage@36.0.1

## 41.0.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/services/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@penumbra-zone/services",
"version": "41.0.0",
"version": "41.0.1",
"license": "(MIT OR Apache-2.0)",
"type": "module",
"engine": {
Expand Down
6 changes: 6 additions & 0 deletions packages/storage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @penumbra-zone/storage

## 36.0.1

### Patch Changes

- 6e3fc9d: Supporting forward compatible parsing of Metadata from remote registry

## 36.0.0

### Minor Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/storage/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@penumbra-zone/storage",
"version": "36.0.0",
"version": "36.0.1",
"license": "(MIT OR Apache-2.0)",
"type": "module",
"engine": {
Expand Down Expand Up @@ -39,13 +39,13 @@
"idb": "^8.0.0"
},
"devDependencies": {
"@penumbra-labs/registry": "^11.3.1",
"@penumbra-labs/registry": "^12.0.0",
"@penumbra-zone/protobuf": "workspace:*",
"fetch-mock": "^10.0.7"
},
"peerDependencies": {
"@bufbuild/protobuf": "^1.10.0",
"@penumbra-labs/registry": "^11.3.1",
"@penumbra-labs/registry": "^12.0.0",
"@penumbra-zone/bech32m": "workspace:*",
"@penumbra-zone/getters": "workspace:*",
"@penumbra-zone/protobuf": "workspace:*",
Expand Down
14 changes: 14 additions & 0 deletions packages/tailwind-config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @penumbra-zone/tailwind-config

## 3.1.14

### Patch Changes

- Updated dependencies [fcb025d]
- @penumbra-zone/ui@12.4.0

## 3.1.13

### Patch Changes

- Updated dependencies [2484bdc]
- @penumbra-zone/ui@12.3.0

## 3.1.12

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/tailwind-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@repo/tailwind-config",
"version": "3.1.12",
"version": "3.1.14",
"private": true,
"license": "(MIT OR Apache-2.0)",
"main": "index.js",
Expand Down
12 changes: 12 additions & 0 deletions packages/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @penumbra-zone/ui

## 12.4.0

### Minor Changes

- fcb025d: Update @penumbra-zone/ui exports

## 12.3.0

### Minor Changes

- 2484bdc: Add ReactNode proptype to description Toast prop

## 12.2.1

### Patch Changes
Expand Down
16 changes: 4 additions & 12 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@penumbra-zone/ui",
"version": "12.2.1",
"version": "12.4.0",
"license": "(MIT OR Apache-2.0)",
"description": "UI components for Penumbra",
"type": "module",
Expand Down Expand Up @@ -48,17 +48,9 @@
"types": "./dist/components/ui/*.d.ts",
"default": "./dist/components/ui/*.js"
},
"./theme": {
"types": "./dist/src/PenumbraUIProvider/theme.d.ts",
"default": "./dist/src/PenumbraUIProvider/theme.js"
},
"./lib/toast/*": {
"types": "./dist/lib/toast/*.d.ts",
"default": "./dist/lib/toast/*.js"
},
"./utils/*": {
"types": "./dist/src/utils/*.d.ts",
"default": "./dist/src/utils/*.js"
"./utils/typography": {
"types": "./dist/src/utils/typography.d.ts",
"default": "./dist/src/utils/typography.js"
},
"./*": {
"types": "./dist/src/*/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/PenumbraUIProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export const PenumbraUIProvider = ({ children }: PropsWithChildren) => (
</MotionConfig>
</ThemeProvider>
);

export { theme } from './theme';
2 changes: 1 addition & 1 deletion packages/ui/src/Toast/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const toastFnMap: Record<ToastType, ToastFn> = {
export interface ToastProps {
type: ToastType;
message: string;
description?: string;
description?: ReactNode;
persistent?: boolean;
dismissible?: boolean;
action?: ExternalToast['action'];
Expand Down
8 changes: 1 addition & 7 deletions packages/ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ const getAllUIComponents = (): Record<string, string> => {
);
};

const getAllLibToastComponents = (): Record<string, string> => {
const source = resolve(__dirname, 'lib', 'toast');
return getRecursiveTsxFiles(source, 'lib/toast');
};

const getDeprecatedUIComponents = (): Record<string, string> => {
const source = resolve(__dirname, 'components/ui');
return getRecursiveTsxFiles(source, 'components/ui');
Expand Down Expand Up @@ -59,8 +54,7 @@ const getAllEntries = (): Record<string, string> => {
return {
tailwindconfig: resolve('../tailwind-config'),
'src/tailwindConfig': join(__dirname, 'src', 'tailwindConfig.ts'),
'src/PenumbraUIProvider/theme': join(__dirname, 'src', 'PenumbraUIProvider', 'theme.ts'),
...getAllLibToastComponents(),
'src/utils/typography': join(__dirname, 'src', 'utils', 'typography.ts'),
...getDeprecatedUIComponents(),
...getAllUIComponents(),
};
Expand Down

0 comments on commit ed8563a

Please sign in to comment.