Skip to content

Commit

Permalink
[chore] CR update
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed May 3, 2022
1 parent 92da558 commit 5e21ef5
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/TxHistory/TxHistoryNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const TxHistoryNavigator = () => {
name="history-details"
component={TxDetails}
options={({route}) => ({
title: formatDateToSeconds(transactionInfos[route.params.id].submittedAt),
title: formatDateToSeconds(transactionInfos[route.params.id]?.submittedAt),
})}
/>

Expand Down
19 changes: 16 additions & 3 deletions src/appStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ describe('migrateWalletMetas()', () => {
await storage.write(`/wallet/${meta.id}`, meta)
await storage.write(`/wallet/${meta.id}/data`, mockedWalletData)
const walletMetas = [meta]
const expected = [{...mockedWalletMeta, networkId: NETWORK_REGISTRY.JORMUNGANDR}]
const expected = [
{
...mockedWalletMeta,
networkId: NETWORK_REGISTRY.JORMUNGANDR,
walletImplementationId: WALLETS.JORMUNGANDR_ITN.WALLET_IMPLEMENTATION_ID,
},
]

const result = await migrateWalletMetas(walletMetas)

Expand All @@ -64,7 +70,14 @@ describe('migrateWalletMetas()', () => {
await storage.write(`/wallet/${meta.id}`, meta)
await storage.write(`/wallet/${meta.id}/data`, mockedWalletData)
const walletMetas = [meta]
const expected = [{...mockedWalletMeta, isShelley: false, networkId: NETWORK_REGISTRY.HASKELL_SHELLEY}]
const expected = [
{
...mockedWalletMeta,
isShelley: false,
networkId: NETWORK_REGISTRY.HASKELL_SHELLEY,
walletImplementationId: WALLETS.HASKELL_BYRON.WALLET_IMPLEMENTATION_ID,
},
]

const result = await migrateWalletMetas(walletMetas)

Expand Down Expand Up @@ -198,7 +211,7 @@ describe('migrateWalletMetas()', () => {
})
it('should set checksum with empty data when there is no addressGenerator in the wallet/data ', async () => {
const meta = {...mockedWalletMeta}
const data = {...mockedWalletData, externalChain: null}
const data = {...mockedWalletData, externalChain: {}}
delete meta.checksum
await storage.write(`/wallet/${meta.id}`, meta)
await storage.write(`/wallet/${meta.id}/data`, data)
Expand Down
10 changes: 5 additions & 5 deletions src/appStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function toShelleyWalletMeta(currentWalletMeta: Partial<WalletMeta>): Prom

// migrate checksum
if (!currentWalletMeta?.checksum) {
if (walletData != null && walletData.externalChain?.addressGenerator != null) {
if (walletData != null && walletData?.externalChain?.addressGenerator != null) {
const {accountPubKeyHex} = walletData.externalChain.addressGenerator
switch (walletImplementationId) {
case WALLETS.HASKELL_BYRON.WALLET_IMPLEMENTATION_ID:
Expand All @@ -59,8 +59,8 @@ async function toShelleyWalletMeta(currentWalletMeta: Partial<WalletMeta>): Prom
await migrateAttribute('checksum', walletMetaUpdate)
}

// missing implementation id
if (!currentWalletMeta?.walletImplementationId && walletImplementationId) {
// resolving to a different implementation id
if (currentWalletMeta?.walletImplementationId !== walletImplementationId) {
walletMetaUpdate.walletImplementationId = walletImplementationId
await migrateAttribute('walletImplementationId', walletMetaUpdate)
}
Expand Down Expand Up @@ -100,7 +100,7 @@ function migrateAttribute(attr: keyof WalletMeta, walletMetaUpdated: Partial<Wal
return storage.write(`/wallet/${id}`, walletMetaUpdated)
}

function isWalletMeta(walletMeta?: WalletMeta | object | undefined): walletMeta is WalletMeta {
function isWalletMeta(walletMeta: WalletMeta | object | undefined): walletMeta is WalletMeta {
return (
// prettier-ignore
!!walletMeta &&
Expand All @@ -121,7 +121,7 @@ function isWalletMeta(walletMeta?: WalletMeta | object | undefined): walletMeta
|| !('provider' in walletMeta)) &&
'walletImplementationId' in walletMeta
&& typeof walletMeta.walletImplementationId === 'string'
&& Object.values(WALLET_IMPLEMENTATION_REGISTRY).indexOf(walletMeta.walletImplementationId) > -1 &&
&& Object.values(WALLET_IMPLEMENTATION_REGISTRY).includes(walletMeta?.walletImplementationId) &&
('isShelley' in walletMeta
&& typeof walletMeta.isShelley === 'boolean'
|| !('isShelley' in walletMeta))
Expand Down
85 changes: 71 additions & 14 deletions src/components/ErrorBoundary/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import React, {Component, ErrorInfo, ReactNode} from 'react'
import {Text, View} from 'react-native'
import {BackHandler, Image, Platform, ScrollView, StyleSheet, Text, View} from 'react-native'
import {Divider} from 'react-native-paper'

import image from '../../../legacy/assets/img/error.png'
import {Button, CopyButton} from '../../../legacy/components/UiKit'
import {Logger} from '../../../legacy/utils/logging'

import {ExpandableItem} from '../../WalletInit/WalletInit/ExpandableItem'
import {Spacer} from '../Spacer'
interface Props {
children: ReactNode
}
Expand Down Expand Up @@ -36,21 +40,74 @@ export class ErrorBoundary extends Component<Props, State> {
render() {
if (this.state.hasError) {
return (
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 12,
paddingTop: 80,
}}
>
<Text>Oops!!! Something went wrong..</Text>
<Text>Error: {this.state.error}</Text>
<Text>Error Info: {this.state.errorInfo}</Text>
<View style={styles.root}>
<ScrollView>
<View style={styles.headerView}>
<Text style={styles.title}>Oops!!! Something went wrong.</Text>
<Spacer height={24} />
<Image source={image} />
</View>
<Divider />

<Spacer height={16} />

<Text style={styles.paragraph}>
Please consider sending this error to Yoroi mobile support. Unfortunately, we can not recover from this
error. You need to relaunch the app.
</Text>

<Spacer height={16} />

<View style={styles.errorSection}>
<View style={styles.errorSectionHeader}>
<Text style={styles.paragraph}>{this.state.error}</Text>
<CopyButton value={`${this.state.error}:${this.state.errorInfo}`} />
</View>

<Spacer height={16} />
</View>
<ExpandableItem label="Show error" content={this.state.errorInfo} />
</ScrollView>

{Platform.OS === 'android' && (
<Actions style={{padding: 16}}>
<Button onPress={() => BackHandler.exitApp()} title="OK" style={{width: '100%'}} />
</Actions>
)}
</View>
)
}
return this.props.children
}
}

const Actions = (props) => {
return <View {...props} />
}

const styles = StyleSheet.create({
root: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 16,
paddingTop: 70,
},
title: {
fontFamily: 'Rubik-Medium',
},
headerView: {
alignItems: 'center',
},
paragraph: {
fontSize: 14,
lineHeight: 18,
},
errorSection: {
paddingVertical: 16,
},
errorSectionHeader: {
flexDirection: 'row',
justifyContent: 'space-between',
},
})

0 comments on commit 5e21ef5

Please sign in to comment.