Skip to content

Commit 8477ad1

Browse files
committed
feat: report ux
1 parent 7e5ccfc commit 8477ad1

5 files changed

Lines changed: 42 additions & 14 deletions

File tree

features/adjustment/mint/form/submit-button/submit-button.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { useVaultInfo, type VAULT_OWNER_ROLES } from 'modules/vaults';
2-
import { MultiplePermissionedSubmitButton } from 'modules/vaults/components';
2+
import {
3+
MultiplePermissionedSubmitButton,
4+
OracleReportButton,
5+
} from 'modules/vaults/components';
36
import { useMemo } from 'react';
47
import { useFormContext, useWatch } from 'react-hook-form';
58

@@ -20,6 +23,7 @@ export const SubmitButton = () => {
2023
name: ['amount', 'token'],
2124
});
2225

26+
// TODO: move this check to upper context
2327
const roles: VAULT_OWNER_ROLES[] = useMemo(() => {
2428
if (!activeVault || !amount) return NON_INCREASE_LOCK_ROLES;
2529
const isSteth = token === 'stETH';
@@ -37,12 +41,14 @@ export const SubmitButton = () => {
3741
const disabled = isSubmitting && !isValid;
3842

3943
return (
40-
<MultiplePermissionedSubmitButton
41-
dashboardRoles={roles}
42-
type="submit"
43-
disabled={disabled}
44-
>
45-
Mint
46-
</MultiplePermissionedSubmitButton>
44+
<OracleReportButton>
45+
<MultiplePermissionedSubmitButton
46+
dashboardRoles={roles}
47+
type="submit"
48+
disabled={disabled}
49+
>
50+
Mint
51+
</MultiplePermissionedSubmitButton>
52+
</OracleReportButton>
4753
);
4854
};

modules/vaults/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export {
22
PermissionedSubmitButton,
33
MultiplePermissionedSubmitButton,
44
} from './permissioned-submit-button';
5+
export { OracleReportButton } from './oracle-report-button';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Button } from '@lidofinance/lido-ui';
2+
import { useReportStatus } from '../hooks';
3+
4+
export type OracleReportButtonProps = React.PropsWithChildren<{
5+
ensureFreshReport?: boolean;
6+
}>;
7+
8+
export const OracleReportButton = ({
9+
ensureFreshReport = true,
10+
children,
11+
}: OracleReportButtonProps) => {
12+
const { shouldApplyReport } = useReportStatus();
13+
14+
if (shouldApplyReport && ensureFreshReport) {
15+
return <Button>Apply Oracle Report</Button>;
16+
}
17+
18+
return <>{children}</>;
19+
};

modules/vaults/hooks/use-report.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ export const useReportStatus = () => {
7676
query: { ...STRATEGY_EAGER },
7777
});
7878

79-
const shouldSkipCheck = !!(time == null || report.data);
79+
const shouldSkipCheck = !!(time == null || !report.data);
8080

8181
// optimistically say the report is fresh if we don't have data just yet
8282
const isReportFresh =
83-
shouldSkipCheck &&
84-
Number(report.data?.timestamp) + reportFreshnessDelta < time!;
83+
shouldSkipCheck ||
84+
time - Number(report.data.timestamp) < reportFreshnessDelta;
8585

8686
const isReportAvailable =
8787
report.data && vaultHubReport.data
@@ -90,12 +90,13 @@ export const useReportStatus = () => {
9090

9191
// when new report is available but old is still fresh
9292
// we can show suggestive reporting UI
93-
const shouldApplyReport =
93+
const shouldApplyReport = !!(
9494
isReportAvailable &&
9595
time &&
9696
report.data &&
97-
(time - Number(report.data.timestamp)) / reportFreshnessDelta >
98-
VAULT_SHOULD_REPORT_THRESHOLD;
97+
(time - Number(report.data.timestamp)) / reportFreshnessDelta >=
98+
VAULT_SHOULD_REPORT_THRESHOLD
99+
);
99100

100101
return {
101102
...report,

modules/vaults/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './consts';
22
export * from './hooks';
33
export * from './contracts/weth';
44
export * from './vault-context';
5+
export * from './components';

0 commit comments

Comments
 (0)