forked from CityOfZion/neon-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced authentication actions/reducers with new actions architecture (
CityOfZion#586) * Add failed screen when data can't be fetched * Replaced module auth functions with actions * Fixed withData to account for data not being loaded yet * Added redirects when user logs in or out * Added error notifications to login actions * Fixed showing back to back error notifications * Added wallet reload when network changes
- Loading branch information
Showing
61 changed files
with
710 additions
and
671 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import Logout from '../../app/containers/App/Header/Logout' | ||
import Logout from '../../app/containers/App/Header/Logout/Logout' | ||
|
||
describe('Logout', () => { | ||
const logout = jest.fn() | ||
|
||
test('should render without crashing', () => { | ||
const wrapper = shallow(<Logout onClick={logout} />) | ||
const wrapper = shallow(<Logout logout={logout} />) | ||
expect(wrapper).toMatchSnapshot() | ||
}) | ||
|
||
test('should dispatch logout action when clicked', () => { | ||
const wrapper = shallow(<Logout onClick={logout} />) | ||
const wrapper = shallow(<Logout logout={logout} />) | ||
expect(logout.mock.calls.length).toEqual(0) | ||
wrapper.find('.logout').simulate('click') | ||
wrapper.find('#logout').simulate('click') | ||
expect(logout.mock.calls.length).toEqual(1) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
__tests__/components/__snapshots__/TransactionHistory.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// @flow | ||
import { wallet } from 'neon-js' | ||
import { noop } from 'lodash' | ||
|
||
import createRequestActions from '../util/api/createRequestActions' | ||
import { upgradeNEP6AddAddresses } from '../core/account' | ||
import { validatePassphraseLength } from '../core/wallet' | ||
|
||
type WifLoginProps = { | ||
wif: string | ||
} | ||
|
||
type LedgerLoginProps = { | ||
publicKey: string, | ||
signingFunction: Function | ||
} | ||
|
||
type Nep2LoginProps = { | ||
passphrase: string, | ||
encryptedWIF: string | ||
} | ||
|
||
type AccountType = ?{ | ||
address: string, | ||
wif?: string, | ||
publicKey?: string, | ||
signingFunction?: Function, | ||
isHardwareLogin: boolean | ||
} | ||
|
||
export const ID = 'ACCOUNT' | ||
|
||
export const wifLoginActions = createRequestActions(ID, ({ wif }: WifLoginProps) => (state: Object): AccountType => { | ||
const account = new wallet.Account(wif) | ||
|
||
return { wif, address: account.address, isHardwareLogin: false } | ||
}) | ||
|
||
export const nep2LoginActions = createRequestActions(ID, ({ passphrase, encryptedWIF }: Nep2LoginProps) => async (state: Object): Promise<AccountType> => { | ||
if (!validatePassphraseLength(passphrase)) { | ||
throw new Error('Passphrase too short') | ||
} | ||
|
||
if (!wallet.isNEP2(encryptedWIF)) { | ||
throw new Error('That is not a valid encrypted key') | ||
} | ||
|
||
const wif = wallet.decrypt(encryptedWIF, passphrase) | ||
const account = new wallet.Account(wif) | ||
|
||
await upgradeNEP6AddAddresses(encryptedWIF, wif) | ||
|
||
return { wif, address: account.address, isHardwareLogin: false } | ||
}) | ||
|
||
export const ledgerLoginActions = createRequestActions(ID, ({ publicKey, signingFunction }: LedgerLoginProps) => (state: Object): AccountType => { | ||
const publicKeyEncoded = wallet.getPublicKeyEncoded(publicKey) | ||
const account = new wallet.Account(publicKeyEncoded) | ||
|
||
return { address: account.address, publicKey, signingFunction, isHardwareLogin: true } | ||
}) | ||
|
||
export const logoutActions = createRequestActions(ID, () => (state: Object): AccountType => { | ||
return null | ||
}) | ||
|
||
// TODO: Better way to expose action data than to make a faux function? One idea is to change | ||
// `withData` to accept the `ID` exported from this file instead of a generated action. | ||
export default createRequestActions(ID, () => (state: Object) => noop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// @flow | ||
import createRequestActions from '../util/api/createRequestActions' | ||
import { getStorage, setStorage } from '../core/storage' | ||
import { DEFAULT_WALLET } from '../core/constants' | ||
|
||
type Props = { | ||
networkId: string | ||
} | ||
|
||
const STORAGE_KEY = 'userWallet' | ||
|
||
const getWallet = async (): Promise<Object> => { | ||
return await getStorage(STORAGE_KEY) || DEFAULT_WALLET | ||
} | ||
|
||
export const ID = 'ACCOUNTS' | ||
|
||
export const updateAccountsActions = createRequestActions(ID, (accounts) => async (state: Object): Promise<Object> => { | ||
const userWallet = await getWallet() | ||
const newWallet = { ...userWallet, accounts } | ||
await setStorage(STORAGE_KEY, newWallet) | ||
|
||
return newWallet | ||
}) | ||
|
||
export default createRequestActions(ID, ({ networkId }: Props = {}) => async (state: Object): Promise<Object> => { | ||
const userWallet = await getWallet() | ||
return userWallet.accounts | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.