Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import {
} from "./styles.css";
import { Tab } from "./tab";

type RouteTab = "manage" | "activity";
type RouteTab = "earn" | "manage" | "activity";

const TABS_MAP = {
earn: "/",
manage: "/manage",
activity: "/activity",
};
Expand Down Expand Up @@ -63,27 +64,37 @@ export const Tabs = () => {
Match.orElse(() => "earn")
);

const { variant } = useSettings();
const { variant, yieldGrouping } = useSettings();
const dashboardYieldCategoryGroupingEnabled = yieldGrouping === "category";

return (
<Box className={combineRecipeWithVariant({ rec: tabsWrapper, variant })}>
<Box
data-rk="tabs-section"
className={combineRecipeWithVariant({ rec: tabsContainer, variant })}
>
{availableDashboardYieldCategories.map((category) => (
{dashboardYieldCategoryGroupingEnabled ? (
availableDashboardYieldCategories.map((category) => (
<Tab
isSelected={
selectedTab === "earn" &&
selectedDashboardYieldCategory === category
}
key={category}
onTabPress={() => onYieldCategoryPress(category)}
variant={category}
/>
))
) : (
<Tab
isSelected={
selectedTab === "earn" &&
selectedDashboardYieldCategory === category
}
key={category}
onTabPress={() => onYieldCategoryPress(category)}
variant={category}
isSelected={selectedTab === "earn"}
onTabPress={() => onRouteTabPress("earn")}
variant="earn"
/>
))}
)}

{availableDashboardYieldCategories.length > 0 ? (
{dashboardYieldCategoryGroupingEnabled &&
availableDashboardYieldCategories.length > 0 ? (
<Box className={tabsGroupDivider} />
) : null}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { tab, tabBorder, tabContainer, tabText } from "./styles.css";
type Props = {
isSelected: boolean;
onTabPress: () => void;
variant: "stake" | "defi" | "rwa" | "manage" | "activity";
variant: "earn" | "stake" | "defi" | "rwa" | "manage" | "activity";
};

export const Tab = ({ isSelected, variant, onTabPress }: Props) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { queryFn } from "../../../../hooks/api/use-yield-opportunity/get-yield-o
import type { usePositions } from "../../../../pages/details/positions-page/hooks/use-positions";
import { useApiClient } from "../../../../providers/api/api-client-provider";
import { useSKQueryClient } from "../../../../providers/query-client";
import { useSettings } from "../../../../providers/settings";
import { useSKWallet } from "../../../../providers/sk-wallet";

type PositionItem = ReturnType<
Expand All @@ -32,19 +33,30 @@ export const useGroupedPositions = (
const { isLedgerLive } = useSKWallet();
const apiClient = useApiClient();
const queryClient = useSKQueryClient();
const { yieldGrouping } = useSettings();
const dashboardYieldCategoryGroupingEnabled = yieldGrouping === "category";

const integrationIds = [...new Set(positions.map((p) => p.integrationId))];
const integrationIds = dashboardYieldCategoryGroupingEnabled
? [...new Set(positions.map((p) => p.integrationId))]
: [];

const categoryQueries = useQueries({
queries: integrationIds.map((yieldId) => ({
queryKey: ["yield-opportunity", yieldId, isLedgerLive],
enabled: !!yieldId,
enabled: dashboardYieldCategoryGroupingEnabled && !!yieldId,
staleTime,
queryFn: ({ signal }: { signal: AbortSignal }) =>
queryFn({ yieldId, isLedgerLive, apiClient, queryClient, signal }),
})),
});

if (!dashboardYieldCategoryGroupingEnabled) {
return [
{ kind: "chain-modal" },
...positions.map((item) => ({ kind: "position" as const, item })),
];
}

const categoryByIntegrationId = new Map<
string,
DashboardYieldCategory | null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ export const EarnPageContextProvider = ({
const { t } = useTranslation();
const initParams = useInitParams();

const { dashboardVariant, externalProviders, variant } = useSettings();
const { dashboardVariant, externalProviders, variant, yieldGrouping } =
useSettings();
const dashboardYieldCategoryGroupingEnabled =
dashboardVariant && yieldGrouping === "category";

const { isConnected, isConnecting, isLedgerLiveAccountPlaceholder, chain } =
useSKWallet();
Expand Down Expand Up @@ -298,7 +301,8 @@ export const EarnPageContextProvider = ({
)
.map(({ all, filteredDtos }) => {
const dashboardFilteredDtos =
dashboardVariant && selectedDashboardYieldCategory
dashboardYieldCategoryGroupingEnabled &&
selectedDashboardYieldCategory
? filteredDtos.filter(
(yieldDto) =>
getDashboardYieldCategory(yieldDto) ===
Expand Down Expand Up @@ -358,7 +362,7 @@ export const EarnPageContextProvider = ({
};
}),
[
dashboardVariant,
dashboardYieldCategoryGroupingEnabled,
deferredStakeSearch,
selectedStake,
yieldSummaries,
Expand Down Expand Up @@ -482,6 +486,8 @@ export const EarnPageContextProvider = ({
};

const onDashboardYieldCategorySelect = (category: DashboardYieldCategory) => {
if (!dashboardYieldCategoryGroupingEnabled) return;

if (selectedDashboardYieldCategory === category) return;

dispatch({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ const getInitialState = (): State => ({

export const EarnPageStateProvider = ({ children }: PropsWithChildren) => {
const { network, isConnected } = useSKWallet();
const { dashboardVariant } = useSettings();
const { dashboardVariant, yieldGrouping } = useSettings();
const dashboardYieldCategoryGroupingEnabled =
dashboardVariant && yieldGrouping === "category";
const dashboardYieldCategorySelectionEnabled =
!dashboardVariant || dashboardYieldCategoryGroupingEnabled;

const getInitYield = useGetInitYield();

const positionsData = usePositionsData();
const dashboardYieldCatalog = useDashboardYieldCatalog({
enabled: dashboardVariant,
enabled: dashboardYieldCategoryGroupingEnabled,
});

const reducer = (state: State, action: Actions): State => {
Expand All @@ -86,15 +90,19 @@ export const EarnPageStateProvider = ({ children }: PropsWithChildren) => {
.chain(() =>
getInitYield({
selectedDashboardYieldCategory:
state.selectedDashboardYieldCategory,
dashboardYieldCategorySelectionEnabled
? state.selectedDashboardYieldCategory
: null,
selectedToken: action.data,
})
.map<{
selectedDashboardYieldCategory: DashboardYieldCategory | null;
yieldState: ReturnType<typeof onYieldSelectState> | null;
}>((yieldDto) => ({
selectedDashboardYieldCategory:
state.selectedDashboardYieldCategory,
dashboardYieldCategorySelectionEnabled
? state.selectedDashboardYieldCategory
: null,
yieldState: onYieldSelectState({
yieldDto,
positionsData: positionsData.data,
Expand All @@ -103,7 +111,9 @@ export const EarnPageStateProvider = ({ children }: PropsWithChildren) => {
.alt(
Maybe.of({
selectedDashboardYieldCategory:
state.selectedDashboardYieldCategory,
dashboardYieldCategorySelectionEnabled
? state.selectedDashboardYieldCategory
: null,
yieldState: null,
})
)
Expand All @@ -118,6 +128,8 @@ export const EarnPageStateProvider = ({ children }: PropsWithChildren) => {
}

case "dashboard/yield-category/select": {
if (!dashboardYieldCategoryGroupingEnabled) return state;

const target = dashboardYieldCatalog.initialSelectionByCategory.get(
action.data
);
Expand Down Expand Up @@ -171,9 +183,10 @@ export const EarnPageStateProvider = ({ children }: PropsWithChildren) => {
.map<State>((val) => ({
...getInitialState(),
selectedToken: Maybe.of(action.data.token),
selectedDashboardYieldCategory: getDashboardYieldCategory(
action.data
),
selectedDashboardYieldCategory:
dashboardYieldCategorySelectionEnabled
? getDashboardYieldCategory(action.data)
: null,
...val,
}))
.orDefault(state);
Expand All @@ -192,9 +205,10 @@ export const EarnPageStateProvider = ({ children }: PropsWithChildren) => {
.map<State>((val) => ({
...getInitialState(),
selectedToken: state.selectedToken,
selectedDashboardYieldCategory: getDashboardYieldCategory(
action.data
),
selectedDashboardYieldCategory:
dashboardYieldCategorySelectionEnabled
? getDashboardYieldCategory(action.data)
: null,
...val,
}))
.orDefault(state);
Expand Down Expand Up @@ -291,7 +305,9 @@ export const EarnPageStateProvider = ({ children }: PropsWithChildren) => {
);

const initYieldRes = useInitYield({
selectedDashboardYieldCategory: selectedDashboardYieldCategoryFallback,
selectedDashboardYieldCategory: dashboardYieldCategorySelectionEnabled
? selectedDashboardYieldCategoryFallback
: null,
selectedToken,
});
const initYield = useMemo(
Expand Down Expand Up @@ -320,9 +336,10 @@ export const EarnPageStateProvider = ({ children }: PropsWithChildren) => {
const selectedStakeDashboardYieldCategory = selectedStake
.chainNullable(getDashboardYieldCategory)
.extractNullable();
const selectedDashboardYieldCategory =
selectedStakeDashboardYieldCategory ??
selectedDashboardYieldCategoryFallback;
const selectedDashboardYieldCategory = dashboardYieldCategorySelectionEnabled
? (selectedStakeDashboardYieldCategory ??
selectedDashboardYieldCategoryFallback)
: null;

/**
* If stake amount is less then min, use min
Expand Down Expand Up @@ -478,8 +495,9 @@ export const EarnPageStateProvider = ({ children }: PropsWithChildren) => {
hasNotYieldsForToken,
selectedProviderYieldId,
selectedDashboardYieldCategory,
availableDashboardYieldCategories:
dashboardYieldCatalog.availableCategories,
availableDashboardYieldCategories: dashboardYieldCategoryGroupingEnabled
? dashboardYieldCatalog.availableCategories
: [],
}),
[
selectedStakeId,
Expand All @@ -500,6 +518,7 @@ export const EarnPageStateProvider = ({ children }: PropsWithChildren) => {
hasNotYieldsForToken,
selectedProviderYieldId,
selectedDashboardYieldCategory,
dashboardYieldCategoryGroupingEnabled,
dashboardYieldCatalog.availableCategories,
]
);
Expand Down
1 change: 1 addition & 0 deletions packages/widget/src/providers/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export type SettingsProps = {
| Record<SupportedSKChains, string>
| ((chain: SupportedSKChains) => string);
dashboardVariant?: boolean;
yieldGrouping?: "flat" | "category";
institutionalWallets?: boolean;
hideChainSelector?: boolean;
hideAccountAndChainSelector?: boolean;
Expand Down
18 changes: 18 additions & 0 deletions packages/widget/tests/use-cases/renders-initial-page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,22 @@ describe("Renders initial page", () => {

app.unmount();
});

it("uses flat dashboard yield grouping by default", async () => {
const app = await renderApp({
skProps: {
apiKey: import.meta.env.VITE_API_KEY,
dashboardVariant: true,
},
});

await expect.element(app.getByText("Earn")).toBeInTheDocument();
await expect.element(app.getByText("Manage")).toBeInTheDocument();
await expect.element(app.getByText("Activity")).toBeInTheDocument();
await expect.element(app.getByText("Stake")).not.toBeInTheDocument();
await expect.element(app.getByText("DeFi")).not.toBeInTheDocument();
await expect.element(app.getByText("RWA")).not.toBeInTheDocument();

app.unmount();
});
});