From ff09ba6c1c2f9e1d57d54ef1aee7877bbfe242e8 Mon Sep 17 00:00:00 2001 From: KillariDev Date: Mon, 29 Jul 2024 13:41:41 +0300 Subject: [PATCH 1/2] guess the default option to show --- app/ts/components/pages/PersonalSign.tsx | 42 ++++++++++--------- .../subcomponents/ParsedInputData.tsx | 8 ++-- .../components/subcomponents/ViewSelector.tsx | 25 +++++++---- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/app/ts/components/pages/PersonalSign.tsx b/app/ts/components/pages/PersonalSign.tsx index 281e4588..df04aa5d 100644 --- a/app/ts/components/pages/PersonalSign.tsx +++ b/app/ts/components/pages/PersonalSign.tsx @@ -122,29 +122,31 @@ const decodeMessage = (message: string) => { return message } +function isNinetyFivePercentNumbersOrASCII(input: string): boolean { + const asciiCount = input.split('').filter(char => char.charCodeAt(0) <= 127).length + const numberCount = input.split('').filter(char => !isNaN(Number(char))).length + const validCount = asciiCount + numberCount + return validCount / input.length >= 0.95 +} + function SignRequest({ visualizedPersonalSignRequest, renameAddressCallBack, editEnsNamedHashCallBack }: SignRequestParams) { switch (visualizedPersonalSignRequest.type) { case 'NotParsed': { - if (visualizedPersonalSignRequest.method === 'personal_sign') return ( - - - -
-

{ visualizedPersonalSignRequest.message }

-
-
- -
-

{ decodeMessage(visualizedPersonalSignRequest.message) }

-
-
-
- -
- ) - return
-

{ visualizedPersonalSignRequest.message }

-
+ return + + +
+

{ visualizedPersonalSignRequest.message }

+
+
+ +
+

{ decodeMessage(visualizedPersonalSignRequest.message) }

+
+
+
+ +
} case 'SafeTx': return { parsedInputData?.type === 'Parsed' ? ( <> - + - +
{ dataStringWith0xStart(input) }
) : <> - +
{ to !== undefined ? <>

No ABI available for 

@@ -37,7 +37,7 @@ export function TransactionInput({ parsedInputData, input, to, addressMetaData, }
- +
{ dataStringWith0xStart(input) }
diff --git a/app/ts/components/subcomponents/ViewSelector.tsx b/app/ts/components/subcomponents/ViewSelector.tsx index b9c18fc8..2ef77783 100644 --- a/app/ts/components/subcomponents/ViewSelector.tsx +++ b/app/ts/components/subcomponents/ViewSelector.tsx @@ -1,5 +1,5 @@ -import { Signal, useComputed, useSignal } from '@preact/signals' -import { ComponentChildren, createContext } from 'preact' +import { Signal, useComputed, useSignal, useSignalEffect } from '@preact/signals' +import { ComponentChildren, createContext, toChildArray } from 'preact' import { useContext, useEffect } from 'preact/hooks' type ViewConfig = { @@ -35,21 +35,28 @@ const useViewSwitcher = () => { } const List = ({ children }: { children: ComponentChildren }) => { + const { views } = useViewSwitcher() + + const isActiveViewDefined = useComputed(() => views.value.some(view => view.isActive === true)) + const hasAllChildrenRendered = useComputed(() => toChildArray(children).length === views.value.length) + + useSignalEffect(() => { + if (!hasAllChildrenRendered.value || isActiveViewDefined.value) return + const [firstChild, ...restOfChildren] = views.peek() + if (firstChild === undefined) return + views.value = [{ ...firstChild, isActive: true }, ...restOfChildren] + }) + return
{ children }
} -const View = ({ children, title, value }: ViewConfig & { children: ComponentChildren }) => { +const View = ({ children, title, value, isActive }: ViewConfig & { children: ComponentChildren }) => { const context = useViewSwitcher() - const activeView = useComputed(() => context.views.value.find(view => view.isActive === true)) - useEffect(() => { - const isActiveSet = context.views.value.length < 1 - context.views.value = [...context.views.peek(), { title, value, isActive: isActiveSet }] + context.views.value = [...context.views.peek(), { title, value, isActive }] }, []) - if (activeView.value?.value === value) return
{ children }
- return <> } From fe8e1e9b372306348ae8f1810a4610414505a987 Mon Sep 17 00:00:00 2001 From: KillariDev Date: Mon, 29 Jul 2024 13:43:46 +0300 Subject: [PATCH 2/2] cleanup --- app/ts/components/pages/PersonalSign.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/ts/components/pages/PersonalSign.tsx b/app/ts/components/pages/PersonalSign.tsx index df04aa5d..e58ce998 100644 --- a/app/ts/components/pages/PersonalSign.tsx +++ b/app/ts/components/pages/PersonalSign.tsx @@ -132,16 +132,18 @@ function isNinetyFivePercentNumbersOrASCII(input: string): boolean { function SignRequest({ visualizedPersonalSignRequest, renameAddressCallBack, editEnsNamedHashCallBack }: SignRequestParams) { switch (visualizedPersonalSignRequest.type) { case 'NotParsed': { + const decoded = decodeMessage(visualizedPersonalSignRequest.message) + const isDecodedAsciiOrNumbers = isNinetyFivePercentNumbersOrASCII(decoded) return - +

{ visualizedPersonalSignRequest.message }

- +
-

{ decodeMessage(visualizedPersonalSignRequest.message) }

+

{ decoded }