Skip to content
Permalink
Browse files

add checkForFlawedWallets feature for shelley

  • Loading branch information
v-almonacid committed Feb 14, 2020
1 parent 831c052 commit 325adbc93722d48e0832ab973b473f3228c179ae
Showing with 54 additions and 21 deletions.
  1. +26 −1 src/components/Delegation/DelegationSummary.js
  2. +28 −20 src/crypto/wallet.js
@@ -30,6 +30,7 @@ import {
isFetchingPoolInfoSelector,
totalDelegatedSelector,
lastAccountStateFetchErrorSelector,
isFlawedWalletSelector,
} from '../../selectors'
import DelegationNavigationButtons from './DelegationNavigationButtons'
import UtxoAutoRefresher from '../Send/UtxoAutoRefresher'
@@ -44,10 +45,12 @@ import {
import {fetchAccountState} from '../../actions/account'
import {fetchUTXOs} from '../../actions/utxo'
import {fetchPoolInfo} from '../../actions/pools'
import {SHELLEY_WALLET_ROUTES} from '../../RoutesList'
import {checkForFlawedWallets} from '../../actions'
import {SHELLEY_WALLET_ROUTES, WALLET_INIT_ROUTES} from '../../RoutesList'
import walletManager from '../../crypto/wallet'
import globalMessages from '../../i18n/global-messages'
import {formatAdaWithText, formatAdaInteger} from '../../utils/format'
import FlawedWalletModal from '../TxHistory/FlawedWalletModal'

import styles from './styles/DelegationSummary.style'

@@ -85,6 +88,8 @@ type Props = {
poolInfo: ?RemotePoolMetaSuccess,
totalDelegated: BigNumber,
lastAccountStateSyncError: any,
checkForFlawedWallets: () => any,
isFlawedWallet: boolean,
}

type State = {
@@ -108,6 +113,7 @@ class DelegationSummary extends React.Component<Props, State> {
1000,
)
this.props.fetchPoolInfo()
this.props.checkForFlawedWallets()
}

componentDidUpdate(prevProps) {
@@ -181,6 +187,8 @@ class DelegationSummary extends React.Component<Props, State> {
lastAccountStateSyncError,
isFetchingUtxos,
intl,
isFlawedWallet,
navigation,
} = this.props

const totalBalance =
@@ -214,6 +222,21 @@ class DelegationSummary extends React.Component<Props, State> {
return num.toString()
}

if (isFlawedWallet === true) {
return (
<FlawedWalletModal
visible
disableButtons={false}
onPress={() =>
navigation.navigate(WALLET_INIT_ROUTES.WALLET_SELECTION)
}
onRequestClose={() =>
navigation.navigate(WALLET_INIT_ROUTES.WALLET_SELECTION)
}
/>
)
}

return (
<SafeAreaView style={styles.scrollView}>
<StatusBar type="dark" />
@@ -339,11 +362,13 @@ export default injectIntl(
totalDelegated: totalDelegatedSelector(state),
isOnline: isOnlineSelector(state),
walletName: walletNameSelector(state),
isFlawedWallet: isFlawedWalletSelector(state),
}),
{
fetchPoolInfo,
fetchAccountState,
fetchUTXOs,
checkForFlawedWallets,
},
),
withNavigation,
@@ -1173,30 +1173,38 @@ class WalletManager {
return await api.getPoolInfo(pool, config)
}

async checkForFlawedWallets() {
async checkForFlawedWallets(): Promise<boolean> {
const mnemonics = [CONFIG.DEBUG.MNEMONIC1, CONFIG.DEBUG.MNEMONIC2]
let affected = false

for (const mnemonic of mnemonics) {
Logger.debug('WalletManager::checkForFlawedWallets mnemonic:', mnemonic)
const flawedAddresses = await util.getAddressesFromMnemonics(
mnemonic,
'External',
[0, 1, 2, 3, 4],
CARDANO_CONFIG.MAINNET,
)
for (let i = 0; i < flawedAddresses.length; i++) {
if (this._wallet == null) throw new WalletClosed()
if (this._wallet._externalChain.isMyAddress(flawedAddresses[i])) {
Logger.debug('WalletManager::checkForFlawedWallets: address match')
affected = true
if (i !== 0) {
throw new Error(
'WalletManager::checkForFlawedWallets: address match found for index > 0',
)
}
return affected
}
let flawedAddresses
if (this.isShelley) {
const flawedAddressesBech32 = await shelleyUtil.getGroupAddressesFromMnemonics(
mnemonic,
'External',
[0],
)
flawedAddresses = await Promise.all(
flawedAddressesBech32.map(async (addr) => {
return Buffer.from(
await (await Address.from_string(addr)).as_bytes(),
).toString('hex')
}),
)
} else {
flawedAddresses = await util.getAddressesFromMnemonics(
mnemonic,
'External',
[0],
CARDANO_CONFIG.MAINNET,
)
}
if (this._wallet == null) throw new WalletClosed()
if (this._wallet._externalChain.isMyAddress(flawedAddresses[0])) {
Logger.debug('WalletManager::checkForFlawedWallets: address match')
affected = true
return affected
}
}
Logger.debug('WalletManager::checkForFlawedWallets:: no match')

0 comments on commit 325adbc

Please sign in to comment.
You can’t perform that action at this time.