Skip to content
This repository was archived by the owner on Jul 20, 2025. It is now read-only.

Commit 7185628

Browse files
Merge branch 'main' into feat/menu-component
2 parents 9185462 + 776eb85 commit 7185628

37 files changed

+1565
-1
lines changed

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"@popperjs/core": "^2.11.8",
9999
"react-hook-form": "^7.54.0",
100100
"react-popper": "^2.3.0",
101+
"decimal.js-light": "^2.5.1",
101102
"tw-colors": "^3.3.2"
102103
}
103-
}
104+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
import { fn } from "@storybook/test";
3+
4+
import { CounterButton } from "./CounterButton";
5+
6+
const meta: Meta<typeof CounterButton> = {
7+
component: CounterButton,
8+
tags: ["autodocs"],
9+
args: {
10+
onAdd: fn(),
11+
},
12+
};
13+
14+
export default meta;
15+
16+
type Story = StoryObj<typeof meta>;
17+
18+
export const Default: Story = {
19+
args: {
20+
counter: 0,
21+
max: 5,
22+
},
23+
};
24+
25+
export const WithCounter: Story = {
26+
args: {
27+
counter: 2,
28+
max: 5,
29+
},
30+
};
31+
32+
export const AlmostAtMax: Story = {
33+
args: {
34+
counter: 4,
35+
max: 5,
36+
},
37+
};
38+
39+
export const AtMaxCapacity: Story = {
40+
args: {
41+
counter: 5,
42+
max: 5,
43+
},
44+
};
45+
46+
export const AlwaysShowCounter: Story = {
47+
args: {
48+
counter: 0,
49+
max: 3,
50+
alwaysShowCounter: true,
51+
},
52+
};
53+
54+
export const AlwaysShowCounterWithValue: Story = {
55+
args: {
56+
counter: 1,
57+
max: 3,
58+
alwaysShowCounter: true,
59+
},
60+
};
61+
62+
export const SingleMax: Story = {
63+
args: {
64+
counter: 0,
65+
max: 1,
66+
},
67+
};
68+
69+
export const SingleMaxAtCapacity: Story = {
70+
args: {
71+
counter: 1,
72+
max: 1,
73+
},
74+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { AiOutlinePlus } from "react-icons/ai";
2+
import { twJoin } from "tailwind-merge";
3+
4+
interface CounterButtonProps {
5+
counter: number;
6+
max: number;
7+
onAdd: () => void;
8+
alwaysShowCounter?: boolean;
9+
}
10+
11+
export function CounterButton({ counter, max, onAdd, alwaysShowCounter = false }: CounterButtonProps) {
12+
const isClickable = counter < max;
13+
const showsCounter = (0 < counter && 1 < max) || (alwaysShowCounter && counter === 0);
14+
15+
return (
16+
<div
17+
className={twJoin(
18+
"bg-primary-highlight flex overflow-hidden rounded-md border border-accent-primary",
19+
isClickable && "cursor-pointer",
20+
!showsCounter && !isClickable && "hidden",
21+
!showsCounter && "w-10",
22+
)}
23+
onClick={isClickable ? onAdd : undefined}
24+
>
25+
{isClickable && (
26+
<div className="flex h-10 w-10 items-center justify-center">
27+
<AiOutlinePlus size={20} />
28+
</div>
29+
)}
30+
{showsCounter && (
31+
<div className="flex h-10 items-center border-l border-accent-primary px-2 text-sm sm:px-4 sm:text-base">
32+
{counter}/{max}
33+
</div>
34+
)}
35+
</div>
36+
);
37+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { CounterButton } from "./CounterButton";
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
3+
import { FinalityProviderItem } from "./FinalityProviderItem";
4+
5+
const meta: Meta<typeof FinalityProviderItem> = {
6+
component: FinalityProviderItem,
7+
tags: ["autodocs"],
8+
parameters: {
9+
layout: "centered",
10+
},
11+
};
12+
13+
export default meta;
14+
15+
type Story = StoryObj<typeof meta>;
16+
17+
const mockProvider = {
18+
logo_url: "/images/fps/lombard.jpeg",
19+
rank: 1,
20+
description: {
21+
moniker: "Lombard Protocol",
22+
},
23+
};
24+
25+
const mockProviderWithoutLogo = {
26+
logo_url: undefined,
27+
rank: 5,
28+
description: {
29+
moniker: "Bitcoin Staking Provider",
30+
},
31+
};
32+
33+
export const Default: Story = {
34+
args: {
35+
bsnId: "bsn123",
36+
bsnName: "Babylon",
37+
bsnLogoUrl: "/images/fps/pumpbtc.jpeg",
38+
provider: mockProvider,
39+
onRemove: (bsnId) => alert(`Remove clicked for ${bsnId}`),
40+
},
41+
};
42+
43+
export const WithoutBsnLogo: Story = {
44+
args: {
45+
bsnId: "bsn456",
46+
bsnName: "Babylon Chain",
47+
bsnLogoUrl: undefined,
48+
provider: mockProvider,
49+
onRemove: (bsnId) => alert(`Remove clicked for ${bsnId}`),
50+
},
51+
};
52+
53+
export const WithoutProviderLogo: Story = {
54+
args: {
55+
bsnId: "bsn789",
56+
bsnName: "Babylon Network",
57+
bsnLogoUrl: "/images/fps/solv.jpeg",
58+
provider: mockProviderWithoutLogo,
59+
onRemove: (bsnId) => alert(`Remove clicked for ${bsnId}`),
60+
},
61+
};
62+
63+
export const HighRankProvider: Story = {
64+
args: {
65+
bsnId: "bsn999",
66+
bsnName: "Babylon Testnet",
67+
bsnLogoUrl: "/images/fps/pumpbtc.jpeg",
68+
provider: {
69+
logo_url: "/images/fps/solv.jpeg",
70+
rank: 99,
71+
description: {
72+
moniker: "High Rank Provider",
73+
},
74+
},
75+
onRemove: (bsnId) => alert(`Remove clicked for ${bsnId}`),
76+
},
77+
};
78+
79+
export const LongNames: Story = {
80+
args: {
81+
bsnId: "bsn_very_long_id_123456789",
82+
bsnName: "Very Long Babylon Network Name That Might Wrap",
83+
bsnLogoUrl: "/images/fps/lombard.jpeg",
84+
provider: {
85+
logo_url: "/images/fps/pumpbtc.jpeg",
86+
rank: 42,
87+
description: {
88+
moniker: "Very Long Finality Provider Name That Should Handle Text Overflow",
89+
},
90+
},
91+
onRemove: (bsnId) => alert(`Remove clicked for ${bsnId}`),
92+
},
93+
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Avatar } from "../Avatar";
2+
import { Text } from "../Text";
3+
import { FinalityProviderLogo } from "../FinalityProviderLogo";
4+
5+
interface ProviderDescription {
6+
moniker?: string;
7+
}
8+
9+
interface Provider {
10+
logo_url?: string;
11+
rank: number;
12+
description?: ProviderDescription;
13+
}
14+
15+
interface FinalityProviderItemProps {
16+
bsnId: string;
17+
bsnName: string;
18+
bsnLogoUrl?: string;
19+
provider: Provider;
20+
onRemove: (bsnId?: string) => void;
21+
}
22+
23+
export function FinalityProviderItem({ bsnId, bsnName, bsnLogoUrl, provider, onRemove }: FinalityProviderItemProps) {
24+
if (!provider) return null;
25+
26+
const renderBsnLogo = () => {
27+
if (!bsnLogoUrl) return null;
28+
29+
return <Avatar url={bsnLogoUrl} alt={bsnName} variant="rounded" size="tiny" className="mr-1" />;
30+
};
31+
32+
return (
33+
<div className="flex flex-row items-center justify-between">
34+
<div className="flex h-10 flex-row gap-2">
35+
<FinalityProviderLogo
36+
logoUrl={provider.logo_url}
37+
rank={provider.rank}
38+
moniker={provider.description?.moniker}
39+
size="lg"
40+
/>
41+
<div className="flex flex-col justify-center text-accent-primary">
42+
<div className="flex items-center text-xs text-accent-secondary">
43+
{renderBsnLogo()}
44+
{bsnName}
45+
</div>
46+
<Text as="div" className="text-base font-medium text-accent-primary">
47+
{provider.description?.moniker}
48+
</Text>
49+
</div>
50+
</div>
51+
52+
<button
53+
onClick={() => onRemove(bsnId)}
54+
className="cursor-pointer rounded bg-accent-secondary/20 px-2 py-0.5 text-xs tracking-[0.4px] text-accent-primary"
55+
>
56+
Remove
57+
</button>
58+
</div>
59+
);
60+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./FinalityProviderItem";
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
3+
import { FinalityProviderLogo } from "./FinalityProviderLogo";
4+
5+
const meta: Meta<typeof FinalityProviderLogo> = {
6+
component: FinalityProviderLogo,
7+
tags: ["autodocs"],
8+
};
9+
10+
export default meta;
11+
12+
type Story = StoryObj<typeof meta>;
13+
14+
export const WithImage: Story = {
15+
args: {
16+
logoUrl: "/images/fps/lombard.jpeg",
17+
rank: 1,
18+
moniker: "Lombard Protocol",
19+
},
20+
};
21+
22+
export const WithImageLarge: Story = {
23+
args: {
24+
logoUrl: "/images/fps/pumpbtc.jpeg",
25+
rank: 2,
26+
moniker: "PumpBTC",
27+
size: "lg",
28+
},
29+
};
30+
31+
export const WithImageSmall: Story = {
32+
args: {
33+
logoUrl: "/images/fps/solv.jpeg",
34+
rank: 3,
35+
moniker: "Solv Protocol",
36+
size: "sm",
37+
},
38+
};
39+
40+
export const FallbackWithMoniker: Story = {
41+
args: {
42+
rank: 1,
43+
moniker: "Babylon Network",
44+
},
45+
};
46+
47+
export const FallbackWithoutMoniker: Story = {
48+
args: {
49+
rank: 5,
50+
},
51+
};
52+
53+
export const FallbackLarge: Story = {
54+
args: {
55+
rank: 2,
56+
moniker: "Large Provider",
57+
size: "lg",
58+
},
59+
};
60+
61+
export const FallbackSmall: Story = {
62+
args: {
63+
rank: 3,
64+
moniker: "Small Provider",
65+
size: "sm",
66+
},
67+
};
68+
69+
export const InvalidImage: Story = {
70+
args: {
71+
logoUrl: "/invalid-image-url.jpg",
72+
rank: 4,
73+
moniker: "Provider with Invalid Image",
74+
},
75+
};

0 commit comments

Comments
 (0)