diff --git a/app/ts/components/pages/PersonalSign.tsx b/app/ts/components/pages/PersonalSign.tsx index 281e4588..e58ce998 100644 --- a/app/ts/components/pages/PersonalSign.tsx +++ b/app/ts/components/pages/PersonalSign.tsx @@ -122,29 +122,33 @@ 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 }

-
+ const decoded = decodeMessage(visualizedPersonalSignRequest.message) + const isDecodedAsciiOrNumbers = isNinetyFivePercentNumbersOrASCII(decoded) + return + + +
+

{ visualizedPersonalSignRequest.message }

+
+
+ +
+

{ decoded }

+
+
+
+ +
} 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 <> }