Skip to content

Commit

Permalink
Rely on state to determine ImportAccountsSelectionModal type, not props
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Feb 21, 2025
1 parent f054b74 commit 3c5229d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 15 deletions.
2 changes: 0 additions & 2 deletions src/app/pages/CreateWalletPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { ImportAccountsSelectionModal } from 'app/pages/OpenWalletPage/Features/
import { selectShowAccountsSelectionModal } from 'app/state/importaccounts/selectors'
import { createWalletActions } from './slice'
import { selectCheckbox, selectMnemonic } from './slice/selectors'
import { WalletType } from 'app/state/wallet/types'

export interface CreateWalletProps {}

Expand Down Expand Up @@ -95,7 +94,6 @@ export function CreateWalletPage(props: CreateWalletProps) {
abort={() => {
dispatch(importAccountsActions.clear())
}}
type={WalletType.Mnemonic}
/>
)}
<Grid gap="small" pad="small" columns={size === 'small' ? ['auto'] : ['2fr', '2fr']}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export function FromBleLedger() {
abort={() => {
dispatch(importAccountsActions.clear())
}}
type={WalletType.BleLedger}
/>
)}
</Box>
Expand Down
2 changes: 0 additions & 2 deletions src/app/pages/OpenWalletPage/Features/FromMnemonic/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { MnemonicValidation } from 'app/components/MnemonicValidation'
import { importAccountsActions } from 'app/state/importaccounts'
import { ImportAccountsSelectionModal } from 'app/pages/OpenWalletPage/Features/ImportAccountsSelectionModal'
import { selectShowAccountsSelectionModal } from 'app/state/importaccounts/selectors'
import { WalletType } from 'app/state/wallet/types'

export function FromMnemonic() {
const dispatch = useDispatch()
Expand All @@ -20,7 +19,6 @@ export function FromMnemonic() {
abort={() => {
dispatch(importAccountsActions.clear())
}}
type={WalletType.Mnemonic}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export function FromUsbLedger() {
abort={() => {
dispatch(importAccountsActions.clear())
}}
type={WalletType.UsbLedger}
/>
)}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const renderComponent = (store: any, abortFunction = () => {}) =>
render(
<Provider store={store}>
<ThemeProvider>
<ImportAccountsSelectionModal abort={abortFunction} type={WalletType.UsbLedger} />
<ImportAccountsSelectionModal abort={abortFunction} />
</ThemeProvider>
</Provider>,
)
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('<ImportAccountsSelectionModal />', () => {
pathDisplay: `m/44'/474'/0'`,
publicKey: '00',
selected: false,
type: WalletType.Mnemonic,
type: WalletType.UsbLedger,
},
]),
)
Expand All @@ -82,7 +82,7 @@ describe('<ImportAccountsSelectionModal />', () => {
pathDisplay: `m/44'/474'/0'`,
publicKey: '00',
selected: false,
type: WalletType.Mnemonic,
type: WalletType.UsbLedger,
},
{
address: 'oasis1qqv25adrld8jjquzxzg769689lgf9jxvwgjs8tha',
Expand All @@ -91,7 +91,7 @@ describe('<ImportAccountsSelectionModal />', () => {
pathDisplay: `m/44'/474'/1'`,
publicKey: '00',
selected: false,
type: WalletType.Mnemonic,
type: WalletType.UsbLedger,
},
]),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ResponsiveContext } from 'grommet/es6/contexts/ResponsiveContext'
import { Spinner } from 'grommet/es6/components/Spinner'
import { Text } from 'grommet/es6/components/Text'
import { numberOfAccountPages } from 'app/state/importaccounts/saga'
import { WalletType, LedgerWalletType } from 'app/state/wallet/types'
import { WalletType } from 'app/state/wallet/types'
import { ChoosePasswordFields } from 'app/components/Persist/ChoosePasswordFields'
import { FormValue as ChoosePasswordFieldsFormValue } from 'app/components/Persist/ChoosePasswordInputFields'
import { preventSavingInputsToUserData } from 'app/lib/preventSavingInputsToUserData'
Expand All @@ -47,7 +47,6 @@ function ImportAccountsSelector({ accounts }: ImportAccountsSelectorSelectorProp

interface ImportAccountsSelectionModalProps {
abort: () => void
type: WalletType.Mnemonic | LedgerWalletType
}

interface FormValue extends ChoosePasswordFieldsFormValue {}
Expand All @@ -61,10 +60,11 @@ export function ImportAccountsSelectionModal(props: ImportAccountsSelectionModal
const error = importAccounts.error
const selectedAccounts = useSelector(selectSelectedAccounts)
const dispatch = useDispatch()
const type = accounts.length > 0 ? accounts[0].type : undefined

const openAccounts = ({ value }: { value: FormValue }) => {
dispatch(
props.type === WalletType.UsbLedger
type === WalletType.UsbLedger
? walletActions.openWalletsFromLedger({ choosePassword: value.password2 })
: walletActions.openWalletFromMnemonic({ choosePassword: value.password2 }),
)
Expand All @@ -83,8 +83,8 @@ export function ImportAccountsSelectionModal(props: ImportAccountsSelectionModal

const onNext = () => {
dispatch(importAccountsActions.setPage(pageNum + 1))
if (props.type === WalletType.UsbLedger || props.type === WalletType.BleLedger) {
dispatch(importAccountsActions.enumerateMoreAccountsFromLedger(props.type))
if (type === WalletType.UsbLedger || type === WalletType.BleLedger) {
dispatch(importAccountsActions.enumerateMoreAccountsFromLedger(type))
}
}

Expand Down

0 comments on commit 3c5229d

Please sign in to comment.