diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index d7976df2f591..bc0145e70edb 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -104,9 +104,6 @@ "finish": { "message": "Finish" }, - "retry_decryption": { - "message": "Try again" - }, "welcome_0_close_button": { "message": "I'll do it later" }, diff --git a/src/_locales/zh/messages.json b/src/_locales/zh/messages.json index aa86b21c555d..bc9ce8fe5894 100644 --- a/src/_locales/zh/messages.json +++ b/src/_locales/zh/messages.json @@ -105,9 +105,6 @@ "finish": { "message": "完成" }, - "retry_decryption": { - "message": "再試一次" - }, "welcome_0_close_button": { "message": "我想以後再做" }, diff --git a/src/components/DebugModeUI/DebugList.tsx b/src/components/DebugModeUI/DebugList.tsx new file mode 100644 index 000000000000..3a14e6f04671 --- /dev/null +++ b/src/components/DebugModeUI/DebugList.tsx @@ -0,0 +1,16 @@ +import React from 'react' +const F = (props: { hint: string; content: string | number }) => ( +
  • + {props.hint}: + {props.content} +
  • +) +export function DebugList(props: { items: readonly (readonly [string, string | number | undefined] | JSX.Element)[] }) { + return ( + + ) +} diff --git a/src/components/InjectedComponents/DecryptedPost.tsx b/src/components/InjectedComponents/DecryptedPost.tsx index ff109006976b..9c0a7d9263dd 100644 --- a/src/components/InjectedComponents/DecryptedPost.tsx +++ b/src/components/InjectedComponents/DecryptedPost.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useState } from 'react' +import React, { useCallback, useState, useMemo } from 'react' import AsyncComponent from '../../utils/components/AsyncComponent' import { AdditionalContent } from './AdditionalPostContent' import { useShareMenu } from './SelectPeopleDialog' @@ -18,6 +18,9 @@ import { import { useValueRef } from '../../utils/hooks/useValueRef' import { debugModeSetting } from '../shared-settings/debugMode' import { DebugModeUI_PostHashDialog } from '../DebugModeUI/PostHashDialog' +import { GetContext } from '@holoflows/kit/es' +import { deconstructPayload } from '../../utils/type-transform/Payload' +import { DebugList } from '../DebugModeUI/DebugList' interface DecryptPostSuccessProps { data: { signatureVerifyResult: boolean; content: string } @@ -86,17 +89,12 @@ const useDecryptPostFailedStyles = makeStyles({ maxWidth: '50em', }, }) -export function DecryptPostFailed({ error, retry }: { error: Error; retry?: () => void }) { +export function DecryptPostFailed({ error }: { error: Error }) { const styles = useDecryptPostFailedStyles() if (error && error.message === geti18nString('service_not_setup_yet')) { return } - const button = retry ? ( - - ) : null - return + return } interface DecryptPostProps { @@ -108,6 +106,7 @@ interface DecryptPostProps { people: Person[] alreadySelectedPreviously: Person[] requestAppendRecipients(to: Person[]): Promise + disableSuccessDecryptionCache?: boolean } function DecryptPost(props: DecryptPostProps) { const { postBy, whoAmI, encryptedText, people, alreadySelectedPreviously, requestAppendRecipients } = props @@ -116,10 +115,10 @@ function DecryptPost(props: DecryptPostProps) { const [decryptingStatus, setDecryptingStatus] = useState( undefined, ) - const [__, forceReDecrypt] = useState() const [debugHash, setDebugHash] = useState('Unknown') - const isDebugging = useValueRef(debugModeSetting) + const setting = useValueRef(debugModeSetting) + const isDebugging = GetContext() === 'options' ? true : setting const rAD = useCallback( async (people: Person[]) => { @@ -128,22 +127,26 @@ function DecryptPost(props: DecryptPostProps) { }, [requestAppendRecipients], ) - const debugHashJSX = ( -
      - {postBy.equals(whoAmI) ? ( - - ) : ( -
    • - Hash of this post: {debugHash} -
      - It should be same on your friend's Maskbook, if it isn't the same, that means your friend does not - receive your crypto key correctly or you didn't set your Maskbook correctly. -
    • - )} -
    • Decrypted reason: {decryptedResult ? decryptedResult.through.join(',') : 'Unknown'}
    • -
    - ) - if (decryptedResult) { + const debugHashJSX = useMemo(() => { + if (!isDebugging) return null + const postPayload = deconstructPayload(encryptedText) + if (!postPayload) return null + const postByMyself = + return ( + + ) + }, [debugHash, whoAmI, decryptedResult, postBy, encryptedText, isDebugging]) + if (decryptedResult && !props.disableSuccessDecryptionCache) { return ( <> { if ('error' in result.data) { - return ( - forceReDecrypt(Math.random())} - error={new Error(result.data.error)} - /> - ) + return } setDecryptedResult(result.data) props.onDecrypted(result.data.content) diff --git a/src/components/InjectedComponents/PostInspector.tsx b/src/components/InjectedComponents/PostInspector.tsx index fa55bba31467..b269ec96209e 100644 --- a/src/components/InjectedComponents/PostInspector.tsx +++ b/src/components/InjectedComponents/PostInspector.tsx @@ -10,6 +10,7 @@ import { useCurrentIdentity, useFriendsList } from '../DataSource/useActivatedUI import { getActivatedUI } from '../../social-network/ui' import { useValueRef } from '../../utils/hooks/useValueRef' import { debugModeSetting } from '../shared-settings/debugMode' +import { DebugList } from '../DebugModeUI/DebugList' interface PostInspectorProps { onDecrypted(post: string): void @@ -41,15 +42,17 @@ export function PostInspector(props: PostInspectorProps) { if (postBy.isUnknown) return null const debugInfo = isDebugging ? ( -
      -
    • Post content: {props.post}
    • -
    • Post by: {props.postBy.userId}
    • -
    • - Who am I:{' '} - {whoAmI ? `Nickname ${whoAmI.nickname || 'unknown'}, UserID ${whoAmI.identifier.userId}` : 'Unknown'} -
    • -
    • Post ID: {props.postId || 'Unknown'}
    • -
    + ) : null if (type.encryptedPost) { diff --git a/src/extension/options-page/Developer.tsx b/src/extension/options-page/Developer.tsx index 4225f49ccea4..76bd3ac96c52 100644 --- a/src/extension/options-page/Developer.tsx +++ b/src/extension/options-page/Developer.tsx @@ -6,6 +6,7 @@ import { useCurrentIdentity } from '../../components/DataSource/useActivatedUI' import { Person } from '../../database' import React from 'react' import { AddProve } from './DeveloperComponents/AddProve' +import { DecryptPostDeveloperMode } from './DeveloperComponents/DecryptPost' async function swallowGoo(me: Person | null) { const boxElem = document.querySelector('#raw-box') as HTMLTextAreaElement @@ -57,6 +58,9 @@ const DevPage = () => { + + + diff --git a/src/extension/options-page/DeveloperComponents/DecryptPost.tsx b/src/extension/options-page/DeveloperComponents/DecryptPost.tsx new file mode 100644 index 000000000000..b5eb90fc955d --- /dev/null +++ b/src/extension/options-page/DeveloperComponents/DecryptPost.tsx @@ -0,0 +1,58 @@ +import React, { useState, useMemo } from 'react' +import { makeStyles } from '@material-ui/core/styles' +import Card from '@material-ui/core/Card' +import CardContent from '@material-ui/core/CardContent' +import Typography from '@material-ui/core/Typography' +import { PersonIdentifier } from '../../../database/type' +import { useTextField } from '../../../utils/components/useForms' +import { DecryptPostUI } from '../../../components/InjectedComponents/DecryptedPost' +import { Person } from '../../../database' +import { useMyIdentities } from '../../../components/DataSource/useActivatedUI' +import { ChooseIdentity } from '../../../components/shared/ChooseIdentity' + +const useStyles = makeStyles(theme => ({})) + +export function DecryptPostDeveloperMode() { + const classes = useStyles() + const myIdentities = useMyIdentities() + const [whoAmISelected, setWhoAmI] = useState() + // const [network, networkInput] = useTextField('Network', { defaultValue: 'facebook.com', required: true }) + const [author, authorInput] = useTextField('Author ID of this post', { required: true }) + const [encryptedText, encryptedTextInput] = useTextField('Encrypted post', { + placeholder: '🎼3/4|ownersAESKeyEncrypted|iv|encryptedText|signature:||', + required: true, + }) + const whoAmI = whoAmISelected + ? whoAmISelected.identifier + : myIdentities[0] + ? myIdentities[0].identifier + : PersonIdentifier.unknown + const network = whoAmI.network + const authorIdentifier = useMemo(() => new PersonIdentifier(network, author), [network, author]) + return ( + + + + Decrypt post manually + + + Your identity? + + setWhoAmI(who)} /> + {/* {networkInput} */} + {authorInput} + {encryptedTextInput} + alert('Not available in this mode')} + encryptedText={encryptedText} + onDecrypted={post => {}} + people={[]} + postBy={authorIdentifier} + whoAmI={whoAmI} + /> + + + ) +} diff --git a/src/stories/Injections.tsx b/src/stories/Injections.tsx index 3fe57d60d483..3356a0f1512d 100644 --- a/src/stories/Injections.tsx +++ b/src/stories/Injections.tsx @@ -84,7 +84,7 @@ storiesOf('Injections', module) - + )