Skip to content

Commit

Permalink
Merge branch 'x' into fix/wallet-issues
Browse files Browse the repository at this point in the history
  • Loading branch information
weatherstar committed Jan 11, 2025
2 parents 8920633 + afef291 commit 081af28
Show file tree
Hide file tree
Showing 41 changed files with 176 additions and 63 deletions.
9 changes: 9 additions & 0 deletions packages/kit-bg/src/services/ServiceStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ class ServiceStaking extends ServiceBase {
networkId: string;
symbol: string;
provider: string;
vault?: string;
}) {
const { networkId, accountId, indexedAccountId, ...rest } = params;
const client = await this.getClient(EServiceEndpointEnum.Earn);
Expand All @@ -365,6 +366,7 @@ class ServiceStaking extends ServiceBase {
symbol: string;
provider: string;
publicKey?: string;
vault?: string;
} = { networkId, ...rest };
const account = await this.getEarnAccount({
accountId: accountId ?? '',
Expand Down Expand Up @@ -1136,6 +1138,13 @@ class ServiceStaking extends ServiceBase {
params,
);
}

@backgroundMethod()
async getFetchHistoryPollingInterval({ networkId }: { networkId: string }) {
const vaultSettings =
await this.backgroundApi.serviceNetwork.getVaultSettings({ networkId });
return vaultSettings.stakingResultPollingInterval ?? 30;
}
}

export default ServiceStaking;
1 change: 1 addition & 0 deletions packages/kit-bg/src/vaults/impls/aptos/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const settings: IVaultSettings = {
},
},
},
stakingResultPollingInterval: 5,
};

export default Object.freeze(settings);
1 change: 1 addition & 0 deletions packages/kit-bg/src/vaults/impls/btc/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const settings: IVaultSettings = {
},
},
},
stakingResultPollingInterval: 60,
};

export default Object.freeze(settings);
1 change: 1 addition & 0 deletions packages/kit-bg/src/vaults/impls/cosmos/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const settings: IVaultSettings = {
},
},
},
stakingResultPollingInterval: 5,
};

export default Object.freeze(settings);
1 change: 1 addition & 0 deletions packages/kit-bg/src/vaults/impls/evm/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ const settings: IVaultSettings = {
customRpcEnabled: true,

stakingConfig,
stakingResultPollingInterval: 5,

withTxMessage: true,

Expand Down
1 change: 1 addition & 0 deletions packages/kit-bg/src/vaults/impls/sol/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const settings: IVaultSettings = {
},
},
},
stakingResultPollingInterval: 5,
};

export default Object.freeze(settings);
1 change: 1 addition & 0 deletions packages/kit-bg/src/vaults/impls/tbtc/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const settings: IVaultSettings = {
},
},
},
stakingResultPollingInterval: 60,
};

export default Object.freeze(settings);
2 changes: 2 additions & 0 deletions packages/kit-bg/src/vaults/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ export type IVaultSettings = {
sendZeroWithZeroTokenBalanceDisabled?: boolean;

stakingConfig?: IStakingConfig;
stakingResultPollingInterval?: number;

editApproveAmountEnabled?: boolean;
useRemoteTxId?: boolean;
isNativeTokenContractAddressEmpty?: boolean;
Expand Down
12 changes: 8 additions & 4 deletions packages/kit/src/views/Earn/EarnHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { EAccountSelectorSceneName } from '@onekeyhq/shared/types';
import type {
IEarnAccount,
IEarnAccountToken,
IEarnRewardUnit,
} from '@onekeyhq/shared/types/staking';

import backgroundApiProxy from '../../background/instance/backgroundApiProxy';
Expand All @@ -65,7 +66,7 @@ interface ITokenAccount extends IEarnAccountToken {
account: IEarnAccount;
}

const buildAprText = (apr: string) => (apr.endsWith('%') ? `${apr} APR` : apr);
const buildAprText = (apr: string, unit: IEarnRewardUnit) => `${apr} ${unit}`;
const getNumberColor = (
value: string | number,
defaultColor: ISizableTextProps['color'] = '$textSuccess',
Expand Down Expand Up @@ -211,7 +212,7 @@ function RecommendedItem({
</SizableText>
</XStack>
<SizableText size="$headingXl" pt="$4" pb="$1">
{buildAprText(token.apr)}
{buildAprText(token.apr, token.rewardUnit)}
</SizableText>
<SizableText size="$bodyMd" color="$textSubdued">
{`${intl.formatMessage({ id: ETranslations.global_available })}: `}
Expand Down Expand Up @@ -535,7 +536,10 @@ function AvailableAssets() {
}}
>
{assets.map(
({ name, logoURI, apr, networkId, symbol, tags = [] }, index) => (
(
{ name, logoURI, apr, networkId, symbol, rewardUnit, tags = [] },
index,
) => (
<ListItem
userSelect="none"
key={name}
Expand Down Expand Up @@ -599,7 +603,7 @@ function AvailableAssets() {
flexGrow: 1,
flexBasis: 0,
}}
primary={buildAprText(apr)}
primary={buildAprText(apr, rewardUnit)}
/>
</ListItem>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export const ApproveBaseStake = ({
{apr && Number(apr) > 0 ? (
<CalculationListItem>
<CalculationListItem.Label>
{intl.formatMessage({ id: ETranslations.global_apr })}
{details.provider.rewardUnit}
</CalculationListItem.Label>
<CalculationListItem.Value color="$textSuccess">{`${apr}%`}</CalculationListItem.Value>
</CalculationListItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,19 @@ export const StakeShouldUnderstand = ({
),
true,
),
createTypography(
intl.formatMessage(
{ id: ETranslations.earn_rewards_automatically_restaked },
{
automatically: (
<SizableText color="$textSuccess">
{intl.formatMessage({ id: ETranslations.earn_automatically })}
</SizableText>
),
},
),
true,
),
intl.formatMessage({
id: ETranslations.earn_rewards_dynamic_real_time,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { useSettingsPersistAtom } from '@onekeyhq/kit-bg/src/states/jotai/atoms';
import { ETranslations } from '@onekeyhq/shared/src/locale';
import type {
IEarnRewardUnit,
IRewardApys,
IStakeProtocolDetails,
} from '@onekeyhq/shared/types/staking';
Expand All @@ -25,6 +26,7 @@ import { MorphoApy } from './MorphoApy';
type IProfitInfoProps = {
apr?: string;
apys?: IRewardApys;
rewardUnit: IEarnRewardUnit;
rewardAssets?: Record<string, IToken>;
earningsIn24h?: string;
rewardToken?: string;
Expand All @@ -47,6 +49,7 @@ function ProfitInfo({
unstakingPeriod,
stakingTime,
earnPoints,
rewardUnit,
}: IProfitInfoProps) {
const intl = useIntl();

Expand Down Expand Up @@ -77,9 +80,7 @@ function ProfitInfo({
>
<XStack gap="$1" alignItems="center">
<SizableText size="$bodyLgMedium" color="$textSuccess">
{`${apr}% ${intl.formatMessage({
id: ETranslations.global_apr,
})}`}
{`${apr}% ${rewardUnit}`}
</SizableText>
{apys ? (
<Popover
Expand All @@ -88,7 +89,7 @@ function ProfitInfo({
})}
renderTrigger={
<IconButton
icon="InfoCircleOutline"
icon="CoinsAddOutline"
size="small"
variant="tertiary"
/>
Expand Down Expand Up @@ -196,6 +197,7 @@ export const ProfitSection = ({
unstakingPeriod: details.unstakingPeriod,
stakingTime: details.provider.stakingTime,
nextLaunchLeft: details.provider.nextLaunchLeft,
rewardUnit: details.provider.rewardUnit,
};
return <ProfitInfo {...props} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type IProviderInfoProps = {
babylonConfirmedCap?: {
value: string;
};
poolFee?: {
value: string;
};
};

function ProviderInfo({
Expand All @@ -42,6 +45,7 @@ function ProviderInfo({
network,
babylonConfirmedCap,
babylonStakingCap,
poolFee,
}: IProviderInfoProps) {
const intl = useIntl();
let minOrMaxStakingItem: { label: string; value: string } | undefined;
Expand Down Expand Up @@ -129,6 +133,16 @@ function ProviderInfo({
{babylonConfirmedCap.value} BTC
</GridItem>
) : null}
{poolFee?.value ? (
<GridItem
title={intl.formatMessage({ id: ETranslations.earn_commission })}
tooltip={intl.formatMessage({
id: ETranslations.earn_commission_tooltip,
})}
>
{poolFee.value}%
</GridItem>
) : null}
</XStack>
</YStack>
);
Expand Down Expand Up @@ -180,6 +194,11 @@ export const ProviderSection = ({
};
}
}
if (details.provider.poolFee) {
providerProps.poolFee = {
value: details.provider.poolFee,
};
}
}
if (details.network) {
providerProps.network = details.network;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ export const StakingTransactionIndicator = ({
}
}, [isFocused, run]);

const { result: pollingInterval } = usePromiseResult(
async () => {
const time =
await backgroundApiProxy.serviceStaking.getFetchHistoryPollingInterval({
networkId,
});
return timerUtils.getTimeDurationMs({ seconds: time });
},
[networkId],
{ initResult: timerUtils.getTimeDurationMs({ seconds: 30 }) },
);

usePromiseResult(
async () => {
if (!isPending) {
Expand All @@ -118,7 +130,7 @@ export const StakingTransactionIndicator = ({
},
[accountId, isPending, networkId, run],
{
pollingInterval: timerUtils.getTimeDurationMs({ seconds: 50 }),
pollingInterval,
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export const UniversalStake = ({
{apr && Number(apr) > 0 ? (
<CalculationListItem>
<CalculationListItem.Label>
{intl.formatMessage({ id: ETranslations.global_apr })}
{details.provider.rewardUnit}
</CalculationListItem.Label>
<CalculationListItem.Value color="$textSuccess">
{`${apr}%`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ export const UniversalWithdraw = ({

const intl = useIntl();

const isInsufficientBalance = useMemo<boolean>(
() => new BigNumber(amountValue).gt(balance),
[amountValue, balance],
);

const isMorphoProvider = earnUtils.isMorphoProvider({
providerName: providerName ?? '',
});
Expand Down Expand Up @@ -222,8 +227,9 @@ export const UniversalWithdraw = ({
() =>
isNaN(amountValue) ||
BigNumber(amountValue).isLessThanOrEqualTo(0) ||
isCheckAmountMessageError,
[amountValue, isCheckAmountMessageError],
isCheckAmountMessageError ||
isInsufficientBalance,
[amountValue, isCheckAmountMessageError, isInsufficientBalance],
);

const editable = initialAmount === undefined;
Expand Down Expand Up @@ -277,6 +283,15 @@ export const UniversalWithdraw = ({
title={checkAmountMessage}
/>
) : null}
{isInsufficientBalance ? (
<Alert
icon="InfoCircleOutline"
type="critical"
title={intl.formatMessage({
id: ETranslations.earn_insufficient_staked_balance,
})}
/>
) : null}
<CalculationList>
{amountValue && !hideReceived ? (
<CalculationListItem>
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/views/Staking/hooks/useUtilsHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function useTxTrack({
accountId,
networkId,
timeout = timerUtils.getTimeDurationMs({ minute: 60 }),
interval = timerUtils.getTimeDurationMs({ seconds: 30 }),
interval = timerUtils.getTimeDurationMs({ seconds: 5 }),
}: {
accountId: string;
networkId: string;
Expand Down
Loading

0 comments on commit 081af28

Please sign in to comment.