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

feat: External signature verification for Roomful client #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
35 changes: 32 additions & 3 deletions components/sections/Signatures/MessageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ import { TextArea, Input, Form } from '@/components/elements/FormFields'
import { StyledFormArea } from './FormArea.style'
import VerifyResult from './VerifyResult'

interface IMessageContent {
export interface IMessageContent {
message: string
verusId: string
signature: string
filled: boolean
}

const MessageContent = () => {
const MessageContent = ({ iMessageContent }: { iMessageContent: IMessageContent }) => {
const { t } = useTranslation('signatures')
const methods = useForm<IMessageContent>({ mode: 'onBlur' })
const [verusSignature, setVerusSignature] = useState<Record<
string,
string
> | null>(null)
const [filledVerusSignature, setFilledVerusSignature] = useState(iMessageContent.filled)
const [sigResult, setSigResult] = useState<any>()

const onSubmit: SubmitHandler<IMessageContent> = async (values) => {
Expand Down Expand Up @@ -52,12 +54,13 @@ const MessageContent = () => {

const _handleReset = () => {
setVerusSignature(null)
setFilledVerusSignature(false)
setSigResult(null)
methods.reset()
}
return (
<>
{!verusSignature && (
{!verusSignature && !filledVerusSignature && (
<StyledFormArea>
<FormProvider {...methods}>
<Form SubmitHandler={methods.handleSubmit(onSubmit)}>
Expand All @@ -80,6 +83,32 @@ const MessageContent = () => {
</FormProvider>
</StyledFormArea>
)}
{!verusSignature && filledVerusSignature && (
<StyledFormArea>
<FormProvider {...methods}>
<Form SubmitHandler={methods.handleSubmit(onSubmit)}>
<TextArea
name="message"
label={t('tab.message.input')}
validate={{ required: t('tab.message.validate') }}
value={iMessageContent.message}
/>
<Input
name="verusId"
label={t('formField.verusID.input')}
validate={{ required: t('formField.verusID.validate') }}
value={iMessageContent.verusId}
/>
<Input
name="signature"
label={t('formField.signature.input')}
validate={{ required: t('formField.signature.validate') }}
value={iMessageContent.signature}
/>
</Form>
</FormProvider>
</StyledFormArea>
)}
{verusSignature && (
<VerifyResult
sigResult={sigResult}
Expand Down
8 changes: 5 additions & 3 deletions components/sections/Signatures/SigTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import {
import MessageContent from './MessageContent'
import HashContent from './HashContent'
import FileContent from './FileContent'
import { IMessageContent } from './MessageContent'


const StyledContainer = styled.div`
padding: ${(props) => props.theme.spaces.xs};
margin: 0 auto;
max-width: 900px;
`

const SigTab = () => {
const SigTab = ({ iMessageContent }: { iMessageContent: IMessageContent }) => {
const { t } = useTranslation('signatures')
const [activeEventKey, setActiveEventKey] = useState(0)
const TabItems = [t('tab.message.tab'), t('tab.file.tab'), t('tab.hash.tab')]
Expand All @@ -28,7 +30,7 @@ const SigTab = () => {
{!useMediaQuery('(min-width: 768px)') && (
<Accordion>
<AccordionContent eventKey={0} title={t('tab.message.tab')}>
<MessageContent />
<MessageContent iMessageContent={iMessageContent}/>
</AccordionContent>
<AccordionContent eventKey={1} title={t('tab.file.tab')}>
<FileContent />
Expand All @@ -45,7 +47,7 @@ const SigTab = () => {
onToggle={setActiveEventKey}
>
<TabPanel eventKey={0}>
<MessageContent />
<MessageContent iMessageContent={iMessageContent}/>
</TabPanel>
<TabPanel eventKey={1}>
<FileContent />
Expand Down
1 change: 1 addition & 0 deletions i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ module.exports = {
'rgx:/mobile': ['walletMobile'],
'rgx:/verusid-lookup': ['verusid'],
'/signatures': ['signatures'],
'/signatures/[data]': ['signatures'],
},
}
7 changes: 6 additions & 1 deletion pages/signatures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ const Signatures = () => {
>
<DefaultHeader align="center">{t('heading')}</DefaultHeader>
</Section>
<SigTab />
<SigTab iMessageContent={{
message: '',
verusId: '',
signature: '',
filled: false
}} />
</MainLayout>
</>
)
Expand Down
35 changes: 35 additions & 0 deletions pages/signatures/[data].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { NextSeo } from 'next-seo'
import useTranslation from 'next-translate/useTranslation'
import { MainLayout, Section } from '@/components/layouts'
import { DefaultHeader } from '@/components/elements'
import { SigTab } from '@/components/sections/Signatures'
import { useRouter } from 'next/router'

const SignaturesExt = () => {
const { t } = useTranslation('signatures')
const title = t('seo:page.signatures.title')
const description = t('seo:page.signatures.description')
const {query} = useRouter()
let messageData = { message: '', verusId: '', signature: '', filled: false }
if (query) {
if (typeof query.data === 'string') {
messageData = JSON.parse(Buffer.from(query.data, 'base64').toString())
}
}
return (
<>
<NextSeo title={title} description={description} />
<MainLayout>
<Section
width={900}
styles="margin-bottom: 75px !important; margin-top:75px;"
>
<DefaultHeader align="center">{t('heading')}</DefaultHeader>
</Section>
<SigTab iMessageContent={messageData} />
</MainLayout>
</>
)
}

export default SignaturesExt