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
5 changes: 5 additions & 0 deletions .changeset/chatty-ideas-post.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stakekit/widget": patch
---

feat: ledger disabled accounts if on priority list
5 changes: 5 additions & 0 deletions .changeset/cute-suits-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stakekit/with-vite-bundled": patch
---

chore: rename package to @stakekit/with-vite-bundled
5 changes: 5 additions & 0 deletions .changeset/tiny-crabs-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stakekit/widget": patch
---

feat(earn-page): add tracking for initial token and yield selection events
2 changes: 1 addition & 1 deletion packages/examples/with-vite-bundled/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "with-vite-bundled",
"name": "@stakekit/with-vite-bundled",
"private": true,
"version": "0.2.1",
"type": "module",
Expand Down
9 changes: 9 additions & 0 deletions packages/widget/src/domain/types/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ export const supportedLedgerFamiliesWithCurrency = {
},
} as const satisfies SupportedLedgerFamiliesWithCurrency;

export const ledgerChainPriority = new Map<SupportedSKChains, number>([
[SubstrateNetworks.Polkadot, 1],
[EvmNetworks.AvalancheC, 2],
[MiscNetworks.Tron, 3],
[EvmNetworks.Binance, 4],
[CosmosNetworks.Cronos, 5],
[EvmNetworks.Polygon, 6],
]);

export type SupportedLedgerFamiliesWithCurrency = Record<
SupportedLedgerLiveFamilies,
Record<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isNetworkWithEnterMinBasedOnPosition } from "@sk-widget/domain/types/stake";
import { usePositionsData } from "@sk-widget/hooks/use-positions-data";
import { useTrackStateEvents } from "@sk-widget/pages/details/earn-page/state/use-track-state-events";
import type { TokenDto, YieldDto } from "@stakekit/api-hooks";
import type { Networks } from "@stakekit/common";
import BigNumber from "bignumber.js";
Expand Down Expand Up @@ -309,6 +310,8 @@ export const EarnPageStateProvider = ({ children }: PropsWithChildren) => {
);
}, [initToken, selectedToken]);

useTrackStateEvents({ initToken, initYield });

const actions = useMemo(
() => ({
onMaxClick: () =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useTrackEvent } from "@sk-widget/hooks/tracking/use-track-event";
import type { TokenDto, YieldDto } from "@stakekit/api-hooks";
import type { Maybe } from "purify-ts";
import { useEffect } from "react";

export const useTrackStateEvents = ({
initToken,
initYield,
}: {
initToken: Maybe<TokenDto>;
initYield: Maybe<YieldDto>;
}) => {
const trackEvent = useTrackEvent();

/**
* Track init yield selected event
*/
useEffect(() => {
initYield.ifJust((v) =>
trackEvent("initYield", {
yieldId: v.id,
network: v.token.network,
tokenName: v.token.name,
tokenAddress: v.token.address,
tokenSymbol: v.token.symbol,
})
);
}, [initYield, trackEvent]);

/**
* Track init token selected event
*/
useEffect(() => {
initToken.ifJust((v) =>
trackEvent("initToken", {
name: v.name,
network: v.network,
address: v.address,
symbol: v.symbol,
decimals: v.decimals,
})
);
}, [initToken, trackEvent]);
};
23 changes: 8 additions & 15 deletions packages/widget/src/providers/ledger/ledger-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
WindowMessageTransport,
deserializeTransaction,
} from "@ledgerhq/wallet-api-client";
import { Networks } from "@stakekit/common";
import type {
Chain,
WalletDetailsParams,
Expand All @@ -17,9 +16,10 @@ import type { CreateConnectorFn } from "wagmi";
import { createConnector } from "wagmi";
import { images } from "../../assets/images";
import { skNormalizeChainId } from "../../domain";
import type {
SupportedLedgerLiveFamilies,
SupportedSKChains,
import {
type SupportedLedgerLiveFamilies,
type SupportedSKChains,
ledgerChainPriority,
} from "../../domain/types/chains";
import type { InitParams } from "../../domain/types/init-params";
import { isLedgerDappBrowserProvider } from "../../utils";
Expand Down Expand Up @@ -118,15 +118,6 @@ const createLedgerLiveConnector = ({

ledgerAccounts = accounts;

const chainPriority = new Map<SupportedSKChains, number>([
[Networks.Polkadot, 1],
[Networks.AvalancheC, 2],
[Networks.Tron, 3],
[Networks.Binance, 4],
[Networks.Cronos, 5],
[Networks.Polygon, 6],
]);

const accountsWithChain = accounts
.reduce(
(acc, next) => {
Expand All @@ -151,8 +142,10 @@ const createLedgerLiveConnector = ({
[] as { account: Account; chainItem: ChainItem }[]
)
.sort((a, b) => {
const aPriority = chainPriority.get(a.chainItem.skChainName) || 999;
const bPriority = chainPriority.get(b.chainItem.skChainName) || 999;
const aPriority =
ledgerChainPriority.get(a.chainItem.skChainName) || 999;
const bPriority =
ledgerChainPriority.get(b.chainItem.skChainName) || 999;

return aPriority - bPriority;
});
Expand Down
17 changes: 14 additions & 3 deletions packages/widget/src/providers/ledger/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import type {
SupportedLedgerLiveFamilies,
SupportedSKChains,
} from "../../domain/types/chains";
import { supportedLedgerFamiliesWithCurrency } from "../../domain/types/chains";
import {
ledgerChainPriority,
supportedLedgerFamiliesWithCurrency,
} from "../../domain/types/chains";
import type { GetEitherAsyncRight } from "../../types";
import { typeSafeObjectEntries } from "../../utils";

Expand Down Expand Up @@ -75,8 +78,16 @@ export const getFilteredSupportedLedgerFamiliesWithCurrency = ({
return { ...acc, [key]: { ...item, chain, enabled: true } };
}

// biome-ignore lint/performance/noAccumulatingSpread: <explanation>
return { ...acc, [key]: { ...item, chain, enabled: false } };
if (
ledgerChainPriority.has(
item.skChainName as unknown as SupportedSKChains
)
) {
// biome-ignore lint/performance/noAccumulatingSpread: <explanation>
return { ...acc, [key]: { ...item, chain, enabled: false } };
}

return acc;
}, {} as MappedSupportedLedgerFamiliesWithCurrency);

// biome-ignore lint/performance/noAccumulatingSpread: <explanation>
Expand Down
2 changes: 2 additions & 0 deletions packages/widget/src/providers/tracking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const trackEventMap = {
validatorsSubmitted: "Validators submitted",
validatorImported: "Validator imported",
viewTxClicked: "View transaction clicked",
initYield: "system/initYield",
initToken: "system/initToken",
} as const;

type TrackEventKey = keyof typeof trackEventMap;
Expand Down