/
githubmirror
/
client
Обзор
Документация
Войти
/
githubmirror
/
client
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
shared/provision/error.tsx
317 строк
11 KB
chrisnojima
refactor(styles): theme via hooks, no android remount (#29515)
08 авг 2026, 02:24
Не верифицирован
08 авг 2026, 02:24
a41d38e
Код
Авторство
О чём код?
import * as C from '@/constants' import * as Kb from '@/common-adapters' import type * as React from 'react' import {SignupScreen} from '@/signup/common' import {openURL} from '@/util/misc' import * as T from '@/constants/types' import type {ProvisionRouteError} from '@/constants/provision' import {startAccountReset} from '@/login/reset/account-reset' const Wrapper = (p: {onBack: () => void; children: React.ReactNode}) => { const styles = useStyles() return ( <SignupScreen onBack={p.onBack} buttons={isMobile ? [{label: 'Close', onClick: p.onBack}] : undefined} > <Kb.ScrollView contentContainerStyle={styles.scrollContent}> <Kb.ImageIcon type="icon-illustration-zen-240-180" style={styles.icon} /> <Kb.Text type="Header" style={styles.header}> Oops, something went wrong. </Kb.Text> <Kb.Box2 direction="vertical" gap="small" gapStart={true} gapEnd={true} style={styles.container}> {p.children} </Kb.Box2> </Kb.ScrollView> </SignupScreen> ) } const rewriteErrorDesc = (s: string) => { switch (s) { case 'Provisioner is a different user than we wanted.': return 'Is the other device using the username you expect? It seems to be different.' default: return s } } type Props = { route: { params: { error?: ProvisionRouteError username?: string } } } const RenderError = ({route}: Props) => { const styles = useStyles() const error = route.params.error const username = route.params.username ?? '' const onBack = C.Router2.navigateUp const onKBHome = () => void openURL('https://keybase.io/') const onPasswordReset = () => void openURL('https://keybase.io/#password-reset') const onAccountReset = () => startAccountReset(false, username) if (!error) { return ( <Wrapper onBack={onBack}> <Kb.Text center={true} type="Body"> Unknown error: Please report this to us. </Kb.Text> </Wrapper> ) } const f = error.fields const fields = f?.reduce<{[key: string]: string}>((acc, f) => { const k = typeof f.key === 'string' ? f.key : '' acc[k] = f.value || '' return acc }, {}) ?? {} switch (error.code) { case T.RPCGen.StatusCode.scdeviceprovisionoffline: case T.RPCGen.StatusCode.scapinetworkerror: return ( <Wrapper onBack={onBack}> <Kb.Text center={true} type="Body"> The device authorization failed because this device went offline. </Kb.Text> <Kb.Text center={true} type="Body"> Please check your network connection and try again. </Kb.Text> </Wrapper> ) case T.RPCGen.StatusCode.scdevicenoprovision: return ( <Wrapper onBack={onBack}> <Kb.Text center={true} type="Body"> {"You can't authorize by password, since you have established device or paper keys."} </Kb.Text> <Kb.Text center={true} type="Body"> You can go back and pick a device or paper key, or{' '} <Kb.Text type="BodyPrimaryLink" onClick={onAccountReset}> reset your account entirely </Kb.Text> . </Kb.Text> </Wrapper> ) case T.RPCGen.StatusCode.scdeviceprevprovisioned: return ( <Wrapper onBack={onBack}> <Kb.Text center={true} type="Body"> You have already authorized this device.{' '} </Kb.Text> <Kb.Text center={true} type="Body"> {"Please use 'keybase login [username]' to log in. "} </Kb.Text> </Wrapper> ) case T.RPCGen.StatusCode.sckeynomatchinggpg: if (fields['has_active_device']) { return ( <Wrapper onBack={onBack}> <Kb.Text center={true} type="Body"> {"You can't authorize using solely a password, since you have active device keys."} </Kb.Text> <Kb.Text center={true} type="BodySemibold"> You have options: </Kb.Text> <Kb.Box2 direction="vertical" style={styles.list}> <Kb.Text center={true} type="Body"> {' - Go back and select a device or paper key'} </Kb.Text> <Kb.Text center={true} type="Body"> {' - Install Keybase on a machine that has your PGP private key in it'} </Kb.Text> <Kb.Text center={true} type="Body"> {' - Login to the website and host an encrypted copy of your PGP private key'} </Kb.Text> <Kb.Text center={true} type="Body"> {' - or, '} <Kb.Text type="BodyPrimaryLink" onClick={onAccountReset}> reset your account entirely </Kb.Text> {'.'} </Kb.Text> </Kb.Box2> </Wrapper> ) } else { return ( <Wrapper onBack={onBack}> <Kb.Text center={true} type="Body"> {"You can't authorize using a password, since you've established a PGP key."} </Kb.Text> <Kb.Text center={true} type="BodySemibold" style={{textAlign: 'left'}}> You have options: </Kb.Text> <Kb.Box2 direction="vertical" style={styles.list}> <Kb.Text center={true} type="Body"> {' - Use '} <Kb.Text type="TerminalInline">keybase login</Kb.Text> on the command line to log in </Kb.Text> {!isMobile && ( <Kb.Text center={true} type="Body"> {' - Install GPG on this machine and import your PGP private key into it'} </Kb.Text> )} <Kb.Text center={true} type="Body"> {' - Install Keybase on a different machine that has your PGP key'} </Kb.Text> <Kb.Text center={true} type="Body"> {' - Login to the website and host an encrypted copy of your PGP private key'} </Kb.Text> <Kb.Text center={true} type="Body"> {' - Or, '} <Kb.Text type="BodyPrimaryLink" onClick={onAccountReset}> reset your account entirely </Kb.Text> . </Kb.Text> </Kb.Box2> </Wrapper> ) } case T.RPCGen.StatusCode.sckeynotfound: return error.desc ? ( <Wrapper onBack={onBack}> <Kb.Markdown>{error.desc}</Kb.Markdown> </Wrapper> ) : ( <Wrapper onBack={onBack}> <Kb.Text center={true} type="Body"> { "Your PGP keychain has multiple keys installed, and we're not sure which one to use to authorize your account." } </Kb.Text> <Kb.Text center={true} type="Body"> Please run <Kb.Text type="TerminalInline">keybase login</Kb.Text> on the command line to continue. </Kb.Text> </Wrapper> ) case T.RPCGen.StatusCode.scbadloginpassword: return ( <Wrapper onBack={onBack}> <Kb.Text center={true} type="Body"> {"Looks like that's a bad password."} </Kb.Text> <Kb.Text center={true} type="BodyPrimaryLink" onClick={onPasswordReset}> Reset your password? </Kb.Text> </Wrapper> ) case T.RPCGen.StatusCode.sckeysyncedpgpnotfound: case T.RPCGen.StatusCode.scgpgunavailable: case T.RPCGen.StatusCode.sckeynosecret: return ( <Wrapper onBack={onBack}> <Kb.Text center={true} type="Body"> { "Sorry, your account is already established with a PGP public key, but we can't access the corresponding private key." } </Kb.Text> <Kb.Text center={true} type="BodySemibold"> You have options: </Kb.Text> <Kb.Box2 direction="vertical" style={styles.list}> <Kb.Text center={true} type="Body"> {' - Run '} <Kb.Text type="TerminalInline">keybase login</Kb.Text> on the device with the corresponding PGP private key </Kb.Text> {!isMobile && ( <Kb.Text center={true} type="Body"> {' - Install GPG, put your PGP private key on this machine and try again'} </Kb.Text> )} <Kb.Text center={true} type="Body"> {' - Go back and authorize with another device or paper key'} </Kb.Text> <Kb.Text center={true} type="Body"> {' - Or, if none of the above are possible, '} <Kb.Text type="BodyPrimaryLink" onClick={onAccountReset}> reset your account and start fresh </Kb.Text> </Kb.Text> </Kb.Box2> </Wrapper> ) case T.RPCGen.StatusCode.scinputcanceled: return ( <Wrapper onBack={onBack}> <Kb.Text center={true} type="Body"> Login cancelled. </Kb.Text> </Wrapper> ) case T.RPCGen.StatusCode.sckeycorrupted: return ( <Wrapper onBack={onBack}> <Kb.Text center={true} type="Body"> {error.message} </Kb.Text> <Kb.Text center={true} type="Body"> We were able to generate a PGP signature but it was rejected by the server. </Kb.Text> <Kb.Text type="Body">This often means that this PGP key is expired or unusable.</Kb.Text> <Kb.Text center={true} type="Body"> You can update your key on{' '} <Kb.Text type="BodyPrimaryLink" onClick={onKBHome}> keybase.io </Kb.Text> . </Kb.Text> </Wrapper> ) case T.RPCGen.StatusCode.scdeleted: return ( <Wrapper onBack={onBack}> <Kb.Text center={true} type="Body"> This user has been deleted. </Kb.Text> </Wrapper> ) default: return ( <Wrapper onBack={onBack}> <Kb.Box2 direction="vertical"> <Kb.Text center={true} type="Body" selectable={true}> {rewriteErrorDesc(error.desc)} </Kb.Text> <Kb.Text center={true} type="BodySmall" selectable={true}> {' ' + error.details} </Kb.Text> </Kb.Box2> </Wrapper> ) } } const useStyles = Kb.Styles.createStyleHook( () => ({ container: {maxWidth: 550}, header: { alignSelf: 'center', marginBottom: 20, marginTop: 46, }, icon: { alignSelf: 'center', height: 180, width: 240, }, list: { marginBottom: 10, marginLeft: Kb.Styles.globalMargins.tiny, maxWidth: 460, }, scrollContent: {alignItems: 'center'}, }) as const ) export default RenderError