-
Notifications
You must be signed in to change notification settings - Fork 3
feat(widget): defer yield hydration for dashboard flows #529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ import BigNumber from "bignumber.js"; | |
| import { Array as EArray, pipe } from "effect"; | ||
| import type { TFunction } from "i18next"; | ||
| import { Maybe } from "purify-ts"; | ||
| import type { YieldDto as OldYieldDto } from "../../generated/api/legacy"; | ||
| import type { | ||
| YieldType as ApiYieldType, | ||
| ArgumentFieldDto, | ||
|
|
@@ -15,12 +14,14 @@ import type { SupportedSKChains } from "./chains"; | |
| import { EvmNetworks } from "./chains/networks"; | ||
| import { equalTokens, tokenString } from "./tokens"; | ||
|
|
||
| export type YieldProviderDetails = ProviderDto; | ||
|
|
||
| export type Yield = YieldApiYieldDto & { | ||
| __fallback__: OldYieldDto; | ||
| provider?: YieldProviderDetails; | ||
| }; | ||
|
|
||
| export type YieldProviderDetails = ProviderDto; | ||
| export type YieldBase = Yield; | ||
|
|
||
| type YieldRiskRatingTone = "positive" | "warning" | "danger" | "neutral"; | ||
| type KnownYieldRiskRatingSource = YieldRiskEntryDto["source"]; | ||
| type YieldRiskRatingSource = KnownYieldRiskRatingSource | (string & {}); | ||
|
|
@@ -110,7 +111,7 @@ export const getDashboardYieldCategoryForApiYieldType = ( | |
| ): DashboardYieldCategory => apiYieldTypeToDashboardCategory[yieldType]; | ||
|
|
||
| export const getDashboardYieldCategory = ( | ||
| yieldDto: Yield | ||
| yieldDto: YieldBase | ||
| ): DashboardYieldCategory | null => { | ||
| const yieldType = getExtendedYieldType(yieldDto); | ||
|
|
||
|
|
@@ -192,7 +193,7 @@ const secondsToDays = (seconds: number | undefined) => { | |
| }; | ||
|
|
||
| export const getYieldActionArg = ( | ||
| yieldDto: Yield, | ||
| yieldDto: YieldBase, | ||
| type: YieldActionType, | ||
| name: YieldArgumentName | ||
| ): YieldArgumentConfig | null => { | ||
|
|
@@ -213,12 +214,12 @@ export const getYieldActionArg = ( | |
| }; | ||
|
|
||
| export const isYieldActionArgRequired = ( | ||
| yieldDto: Yield, | ||
| yieldDto: YieldBase, | ||
| type: YieldActionType, | ||
| name: YieldArgumentName | ||
| ) => !!getYieldActionArg(yieldDto, type, name)?.required; | ||
|
|
||
| export const getYieldRewardTokens = (yieldDto: Yield) => | ||
| export const getYieldRewardTokens = (yieldDto: YieldBase) => | ||
| pipe( | ||
| yieldDto.rewardRate?.components?.map((component) => component.token) ?? [], | ||
| EArray.dedupeWith((a, b) => tokenString(a) === tokenString(b)), | ||
|
|
@@ -277,9 +278,6 @@ export const getYieldCooldownPeriod = (yieldDto: Yield) => | |
| export const getYieldWarmupPeriod = (yieldDto: Yield) => | ||
| secondsToDays(yieldDto.mechanics.warmupPeriod?.seconds); | ||
|
|
||
| export const getYieldCommission = (yieldDto: Yield) => | ||
| yieldDto.__fallback__.metadata.commission; | ||
|
|
||
| export const getYieldTvlUsd = (yieldDto: Yield) => { | ||
| const tvlUsd = yieldDto.statistics?.tvlUsd; | ||
|
|
||
|
|
@@ -307,10 +305,9 @@ export const getYieldFeePercent = (yieldDto: Yield): number | null => { | |
| export const getYieldLockupPeriod = (yieldDto: Yield) => | ||
| secondsToDays(yieldDto.mechanics.lockupPeriod?.seconds); | ||
|
|
||
| export const hasYieldExitSignatureVerification = (yieldDto: Yield) => | ||
| !!yieldDto.__fallback__.args.exit?.args?.signatureVerification?.required; | ||
|
|
||
| export const getExtendedYieldType = (yieldDto: Yield): ExtendedYieldType => { | ||
| export const getExtendedYieldType = ( | ||
| yieldDto: YieldBase | ||
| ): ExtendedYieldType => { | ||
| if (isNativeStaking(yieldDto)) { | ||
| return "native_staking"; | ||
| } | ||
|
|
@@ -322,7 +319,7 @@ export const getExtendedYieldType = (yieldDto: Yield): ExtendedYieldType => { | |
| return yieldDto.mechanics.type; | ||
| }; | ||
|
|
||
| export const getYieldOutputToken = (yieldDto: Yield) => | ||
| export const getYieldOutputToken = (yieldDto: YieldBase) => | ||
| Maybe.fromNullable(yieldDto.outputToken).filter( | ||
| (outputToken) => !equalTokens(outputToken, yieldDto.token) | ||
| ); | ||
|
|
@@ -344,7 +341,7 @@ export const isDepositYieldType = (yieldType: ExtendedYieldType) => | |
| yieldType === "liquidity_pool"; | ||
|
|
||
| export const getYieldTypeLabels = ( | ||
| yieldDto: Yield, | ||
| yieldDto: YieldBase, | ||
| t: TFunction | ||
| ): YieldTypeLabelsMap[keyof YieldTypeLabelsMap] => { | ||
| const map = { | ||
|
|
@@ -426,15 +423,15 @@ const yieldTypesSortRank: { [Key in ExtendedYieldType]: number } = { | |
| concentrated_liquidity_pool: 10, | ||
| }; | ||
|
|
||
| export const getYieldTypesSortRank = (yieldDto: Yield) => | ||
| export const getYieldTypesSortRank = (yieldDto: YieldBase) => | ||
| yieldTypesSortRank[getExtendedYieldType(yieldDto)]; | ||
|
|
||
| const isEthereumStaking = (yieldDto: Yield) => | ||
| const isEthereumStaking = (yieldDto: YieldBase) => | ||
| yieldDto.mechanics.type === "staking" && | ||
| yieldDto.token.network === EvmNetworks.Ethereum && | ||
| yieldDto.token.symbol === "ETH"; | ||
|
|
||
| const isNativeStaking = (yieldDto: Yield) => | ||
| const isNativeStaking = (yieldDto: YieldBase) => | ||
| Maybe.fromFalsy(isEthereumStaking(yieldDto)) | ||
| .chain(() => | ||
| Maybe.fromFalsy( | ||
|
|
@@ -449,22 +446,18 @@ const isNativeStaking = (yieldDto: Yield) => | |
| .filter((v) => v.isEqualTo(32)) | ||
| .isJust(); | ||
|
|
||
| const isPooledStaking = (yieldDto: Yield) => | ||
| const isPooledStaking = (yieldDto: YieldBase) => | ||
| isEthereumStaking(yieldDto) && !isNativeStaking(yieldDto); | ||
|
|
||
| export const isYieldWithProviderOptions = (yieldDto: Yield) => | ||
| export const isYieldWithProviderOptions = (yieldDto: YieldBase) => | ||
| !!getYieldActionArg(yieldDto, "enter", "providerId")?.required; | ||
|
|
||
| export const getYieldProviderYieldIds = (yieldDto: Yield) => | ||
| export const getYieldProviderYieldIds = (yieldDto: YieldBase) => | ||
| getYieldActionArg(yieldDto, "enter", "providerId")?.options ?? []; | ||
|
|
||
| export const isYieldIntegrationAggregator = (yieldDto: Yield) => | ||
| !!yieldDto.__fallback__.metadata.isIntegrationAggregator; | ||
|
|
||
| export const isYieldValidatorSelectionRequired = (yieldDto: Yield) => | ||
| !!( | ||
| yieldDto.mechanics.requiresValidatorSelection || | ||
| isYieldIntegrationAggregator(yieldDto) || | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just double check, this validator is not needed anymore? |
||
| isYieldActionArgRequired(yieldDto, "enter", "validatorAddress") || | ||
| isYieldActionArgRequired(yieldDto, "enter", "validatorAddresses") | ||
| ); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: stakekit/widget
Length of output: 10380
🏁 Script executed:
Repository: stakekit/widget
Length of output: 197
🏁 Script executed:
Repository: stakekit/widget
Length of output: 21728
🏁 Script executed:
Repository: stakekit/widget
Length of output: 224
🏁 Script executed:
Repository: stakekit/widget
Length of output: 18123
🏁 Script executed:
Repository: stakekit/widget
Length of output: 1092
Guard the legacy networks response before casting to
NetworksYieldControllerGetMyNetworksis typed in the generated legacy API asReadonlyArray<string>, and theNetworksdomain type isTokenDto["network"](string-literal union). The current(network) => network as Networkscast is unchecked. Since consumers only use the resulting set forSet.has(v.skChainName)-based filtering, invalid strings won’t break execution, but they will silently pollute a value typed asSet<Networks>.Consider filtering/validating each returned string against the known
Networksvalues before inserting into theSetinpackages/widget/src/common/get-enabled-networks.ts(lines 20-21).🤖 Prompt for AI Agents