Skip to content
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

chore: sign page performance #2193

Merged
merged 1 commit into from
Apr 12, 2024
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
16 changes: 16 additions & 0 deletions src/ui/views/Approval/components/SignText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import {
TextActionData,
formatSecurityEngineCtx,
parseAction,
getActionTypeText,
} from './TextActions/utils';
import { WaitingSignMessageComponent } from './map';
import stats from '@/stats';

interface SignTextProps {
data: string[];
Expand All @@ -47,6 +49,7 @@ interface SignTextProps {
}

const SignText = ({ params }: { params: SignTextProps }) => {
const renderStartAt = useRef(0);
const [, resolveApproval, rejectApproval] = useApproval();
const wallet = useWallet();
const { t } = useTranslation();
Expand Down Expand Up @@ -336,13 +339,26 @@ const SignText = ({ params }: { params: SignTextProps }) => {
}, [rules]);

useEffect(() => {
renderStartAt.current = Date.now();
checkWachMode();
}, []);

useEffect(() => {
report('createSignText');
}, []);

useEffect(() => {
if (!isLoading) {
const duration = Date.now() - renderStartAt.current;
stats.report('signPageRenderTime', {
type: 'text',
actionType: getActionTypeText(parsedActionData),
chain: '',
duration,
});
}
}, [isLoading]);

return (
<>
<div className="approval-text">
Expand Down
10 changes: 10 additions & 0 deletions src/ui/views/Approval/components/SignTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
fetchActionRequiredData,
ActionRequireData,
formatSecurityEngineCtx,
getActionTypeText,
} from '../components/Actions/utils';
import Actions from './Actions';
import { useSecurityEngine } from 'ui/utils/securityEngine';
Expand Down Expand Up @@ -628,6 +629,7 @@ interface BlockInfo {

const SignTx = ({ params, origin }: SignTxProps) => {
const { isGnosis, account } = params;
const renderStartAt = useRef(0);
const [isReady, setIsReady] = useState(false);
const [nonceChanged, setNonceChanged] = useState(false);
const [canProcess, setCanProcess] = useState(true);
Expand Down Expand Up @@ -1847,6 +1849,7 @@ const SignTx = ({ params, origin }: SignTxProps) => {
}, [engineResults, currentTx]);

useEffect(() => {
renderStartAt.current = Date.now();
init();
}, []);

Expand All @@ -1855,6 +1858,13 @@ const SignTx = ({ params, origin }: SignTxProps) => {
if (scrollRef.current && scrollRef.current.scrollTop > 0) {
scrollRef.current && (scrollRef.current.scrollTop = 0);
}
const duration = Date.now() - renderStartAt.current;
stats.report('signPageRenderTime', {
type: 'transaction',
actionType: getActionTypeText(actionData),
chain: chain?.serverId || '',
duration,
});
}
}, [isReady]);

Expand Down
16 changes: 16 additions & 0 deletions src/ui/views/Approval/components/SignTypedData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
TypedDataActionData,
formatSecurityEngineCtx,
normalizeTypeData,
getActionTypeText,
} from './TypedDataActions/utils';
import { Level } from '@rabby-wallet/rabby-security-engine/dist/rules';
import { isTestnetChainId, findChainByID, findChain } from '@/utils/chain';
Expand All @@ -43,6 +44,7 @@ import { useSignPermissionCheck } from '../hooks/useSignPermissionCheck';
import { useTestnetCheck } from '../hooks/useTestnetCheck';
import { useEnterPassphraseModal } from '@/ui/hooks/useEnterPassphraseModal';
import clsx from 'clsx';
import stats from '@/stats';

interface SignTypedDataProps {
method: string;
Expand All @@ -58,6 +60,7 @@ interface SignTypedDataProps {
}

const SignTypedData = ({ params }: { params: SignTypedDataProps }) => {
const renderStartAt = useRef(0);
const [, resolveApproval, rejectApproval] = useApproval();
const { t } = useTranslation();
const wallet = useWallet();
Expand Down Expand Up @@ -513,11 +516,24 @@ const SignTypedData = ({ params }: { params: SignTypedDataProps }) => {
}, [scrollInfo, scrollRefSize]);

useEffect(() => {
renderStartAt.current = Date.now();
init();
checkWachMode();
report('createSignText');
}, []);

useEffect(() => {
if (!isLoading) {
const duration = Date.now() - renderStartAt.current;
stats.report('signPageRenderTime', {
type: 'typedata',
actionType: getActionTypeText(parsedActionData),
chain: chain?.serverId || '',
duration,
});
}
}, [isLoading]);

return (
<>
<div className="approval-text relative">
Expand Down
Loading