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

Commit 1ecde55

Browse files
fix: resolve comments
1 parent 11c9719 commit 1ecde55

6 files changed

Lines changed: 195 additions & 116 deletions

File tree

src/ui/common/api/getBsn.ts

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,11 @@
1-
import { getNetworkConfigBBN } from "@/ui/common/config/network/bbn";
2-
3-
import { Bsn, BsnType } from "../types/bsn";
4-
import { getBsnLogoUrl } from "../utils/bsnLogo";
1+
import { BsnType } from "../types/bsn";
52

63
import { apiWrapper } from "./apiWrapper";
74

85
export const BSN_TYPE_COSMOS: BsnType = "COSMOS";
96
export const BSN_TYPE_ROLLUP: BsnType = "ROLLUP";
107

11-
const { chainId: BBN_CHAIN_ID } = getNetworkConfigBBN();
12-
13-
// BSN Configuration for different types and behaviors
14-
export interface BsnFilterOption {
15-
value: string;
16-
label: string;
17-
}
18-
19-
export interface BsnConfig {
20-
modalTitle: string;
21-
filterOptions: BsnFilterOption[];
22-
fpFilterBehavior: "status-based" | "allowlist-based";
23-
}
24-
25-
export const BSN_CONFIGS: Record<string, BsnConfig> = {
26-
// Babylon Genesis
27-
[BBN_CHAIN_ID]: {
28-
modalTitle: "Select Babylon Genesis Finality Provider",
29-
filterOptions: [
30-
{ value: "active", label: "Active" },
31-
{ value: "inactive", label: "Inactive" },
32-
{ value: "jailed", label: "Jailed" },
33-
{ value: "slashed", label: "Slashed" },
34-
],
35-
fpFilterBehavior: "status-based",
36-
},
37-
COSMOS: {
38-
modalTitle: "Select Cosmos Finality Provider",
39-
filterOptions: [
40-
{ value: "active", label: "Active" },
41-
{ value: "inactive", label: "Inactive" },
42-
],
43-
fpFilterBehavior: "status-based",
44-
},
45-
// Roll-up BSN config
46-
ROLLUP: {
47-
modalTitle: "Select Roll Up Finality Provider",
48-
filterOptions: [
49-
{ value: "active", label: "Allowlisted" },
50-
{ value: "inactive", label: "Not Allowlisted" },
51-
],
52-
fpFilterBehavior: "allowlist-based",
53-
},
54-
};
55-
56-
/**
57-
* Get BSN configuration based on BSN object
58-
*/
59-
export const getBsnConfig = (bsn?: Bsn): BsnConfig => {
60-
if (!bsn) return BSN_CONFIGS[BBN_CHAIN_ID];
61-
62-
// Check if it's Babylon Genesis first
63-
if (bsn.id === BBN_CHAIN_ID) {
64-
return BSN_CONFIGS[BBN_CHAIN_ID];
65-
}
66-
67-
// Use type-based config
68-
return BSN_CONFIGS[bsn.type] || BSN_CONFIGS[BBN_CHAIN_ID];
69-
};
70-
71-
interface BsnAPI {
8+
export interface BsnAPI {
729
id: string;
7310
name: string;
7411
description: string;
@@ -81,29 +18,12 @@ interface BsnDataResponse {
8118
data: BsnAPI[];
8219
}
8320

84-
const createBSN = (bsn: BsnAPI): Bsn => ({
85-
id: bsn.id,
86-
name: bsn.name,
87-
description: bsn.description,
88-
activeTvl: bsn.active_tvl,
89-
logoUrl: getBsnLogoUrl(bsn.id),
90-
type: bsn.type,
91-
allowlist: bsn.allowlist,
92-
});
93-
94-
/**
95-
* Determines if a BSN is Babylon Genesis
96-
*/
97-
export const isBabylonGenesisBsn = (bsn: Bsn): boolean =>
98-
bsn.id === BBN_CHAIN_ID;
99-
100-
export const getBSNs = async (): Promise<Bsn[]> => {
21+
export const getBsnAPI = async (): Promise<BsnAPI[]> => {
10122
const response = await apiWrapper<BsnDataResponse>(
10223
"GET",
10324
"/v2/bsn",
10425
"Error getting BSN list",
10526
);
10627

107-
const { data } = response.data;
108-
return data.map(createBSN);
28+
return response.data.data;
10929
};

src/ui/common/components/Multistaking/FinalityProviderField/FinalityProviderModal.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import {
44
DialogFooter,
55
DialogHeader,
66
} from "@babylonlabs-io/core-ui";
7-
import { useMemo, useState } from "react";
7+
import { useState } from "react";
88

9-
import { getBsnConfig } from "@/ui/common/api/getBsn";
109
import { ResponsiveDialog } from "@/ui/common/components/Modals/ResponsiveDialog";
1110
import { FinalityProviders } from "@/ui/common/components/Multistaking/FinalityProviderField/FinalityProviders";
1211
import { useFinalityProviderBsnState } from "@/ui/common/state/FinalityProviderBsnState";
@@ -29,9 +28,7 @@ export const FinalityProviderModal = ({
2928
onBack,
3029
}: Props) => {
3130
const [selectedFP, setSelectedFp] = useState(defaultFinalityProvider);
32-
const { selectedBsn } = useFinalityProviderBsnState();
33-
34-
const bsnConfig = useMemo(() => getBsnConfig(selectedBsn), [selectedBsn]);
31+
const { modalTitle } = useFinalityProviderBsnState();
3532

3633
const handleClose = () => {
3734
onClose();
@@ -41,7 +38,7 @@ export const FinalityProviderModal = ({
4138
return (
4239
<ResponsiveDialog open={open} onClose={handleClose} className="w-[52rem]">
4340
<DialogHeader
44-
title={bsnConfig.modalTitle}
41+
title={modalTitle}
4542
onClose={handleClose}
4643
className="text-accent-primary"
4744
/>

src/ui/common/components/Multistaking/FinalityProviders/FinalityProviderFilter.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
import { Select } from "@babylonlabs-io/core-ui";
2-
import { useMemo } from "react";
32

4-
import { getBsnConfig } from "@/ui/common/api/getBsn";
53
import { useFinalityProviderBsnState } from "@/ui/common/state/FinalityProviderBsnState";
64

75
export const FinalityProviderFilter = () => {
8-
const { filter, handleFilter, selectedBsn } = useFinalityProviderBsnState();
9-
10-
const bsnConfig = useMemo(() => getBsnConfig(selectedBsn), [selectedBsn]);
11-
12-
const options = useMemo(
13-
() => bsnConfig.filterOptions,
14-
[bsnConfig.filterOptions],
15-
);
6+
const { filter, handleFilter, filterOptions } = useFinalityProviderBsnState();
167

178
return (
189
<Select
19-
options={options}
10+
options={filterOptions}
2011
onSelect={(value) => handleFilter("providerStatus", value.toString())}
2112
placeholder="Select Status"
2213
value={filter.searchTerm ? "" : filter.providerStatus}

src/ui/common/hooks/client/api/useBsn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { getBSNs } from "@/ui/common/api/getBsn";
21
import { ONE_MINUTE } from "@/ui/common/constants";
32
import { useClientQuery } from "@/ui/common/hooks/client/useClient";
3+
import { getBSNs } from "@/ui/common/services/bsnService";
44
import { Bsn } from "@/ui/common/types/bsn";
55

66
export const BSN_KEY = "BSN";
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { getNetworkConfigBBN } from "@/ui/common/config/network/bbn";
2+
3+
import { getBsnAPI } from "../api/getBsn";
4+
import { Bsn, BsnType } from "../types/bsn";
5+
import { getBsnLogoUrl } from "../utils/bsnLogo";
6+
7+
const { chainId: BBN_CHAIN_ID } = getNetworkConfigBBN();
8+
9+
export interface BsnFilterOption {
10+
value: string;
11+
label: string;
12+
}
13+
14+
export interface BsnConfig {
15+
modalTitle: string;
16+
filterOptions: BsnFilterOption[];
17+
fpFilterBehavior: "status-based" | "allowlist-based";
18+
}
19+
20+
export const BSN_CONFIGS: Record<string, BsnConfig> = {
21+
// Babylon Genesis
22+
[BBN_CHAIN_ID]: {
23+
modalTitle: "Select Babylon Genesis Finality Provider",
24+
filterOptions: [
25+
{ value: "active", label: "Active" },
26+
{ value: "inactive", label: "Inactive" },
27+
{ value: "jailed", label: "Jailed" },
28+
{ value: "slashed", label: "Slashed" },
29+
],
30+
fpFilterBehavior: "status-based",
31+
},
32+
COSMOS: {
33+
modalTitle: "Select Cosmos Finality Provider",
34+
filterOptions: [
35+
{ value: "active", label: "Active" },
36+
{ value: "inactive", label: "Inactive" },
37+
],
38+
fpFilterBehavior: "status-based",
39+
},
40+
// Roll-up BSN config
41+
ROLLUP: {
42+
modalTitle: "Select Roll Up Finality Provider",
43+
filterOptions: [
44+
{ value: "active", label: "Allowlisted" },
45+
{ value: "inactive", label: "Not Allowlisted" },
46+
],
47+
fpFilterBehavior: "allowlist-based",
48+
},
49+
};
50+
51+
/**
52+
* Get BSN configuration based on BSN type
53+
*/
54+
export const getBsnConfig = (bsn?: Bsn): BsnConfig => {
55+
if (!bsn) return BSN_CONFIGS[BBN_CHAIN_ID];
56+
57+
// Check if it's Babylon Genesis first
58+
if (bsn.id === BBN_CHAIN_ID) {
59+
return BSN_CONFIGS[BBN_CHAIN_ID];
60+
}
61+
62+
// Use type-based config
63+
return BSN_CONFIGS[bsn.type] || BSN_CONFIGS[BBN_CHAIN_ID];
64+
};
65+
66+
/**
67+
* Determines if a BSN is Babylon Genesis
68+
*/
69+
export const isBabylonGenesisBsn = (bsn: Bsn): boolean =>
70+
bsn.id === BBN_CHAIN_ID;
71+
72+
export const createBSN = (bsn: {
73+
id: string;
74+
name: string;
75+
description: string;
76+
active_tvl: number;
77+
type: BsnType;
78+
allowlist?: string[];
79+
}): Bsn => ({
80+
id: bsn.id,
81+
name: bsn.name,
82+
description: bsn.description,
83+
activeTvl: bsn.active_tvl,
84+
logoUrl: getBsnLogoUrl(bsn.id),
85+
type: bsn.type,
86+
allowlist: bsn.allowlist,
87+
});
88+
89+
/**
90+
*/
91+
export const getBSNs = async (): Promise<Bsn[]> => {
92+
const data = await getBsnAPI();
93+
return data.map(createBSN);
94+
};

0 commit comments

Comments
 (0)