@ -121,12 +121,12 @@ export function createNewVaultAndGetSeedPhrase(password) {
try {
try {
await createNewVault ( password )
await createNewVault ( password )
const seedWords = await verifySeedPhrase ( )
const seedWords = await verifySeedPhrase ( )
dispatch ( hideLoadingIndication ( ) )
return seedWords
return seedWords
} catch ( error ) {
} catch ( error ) {
dispatch ( hideLoadingIndication ( ) )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
throw new Error ( error . message )
throw new Error ( error . message )
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
}
}
}
}
@ -139,12 +139,12 @@ export function unlockAndGetSeedPhrase(password) {
await submitPassword ( password )
await submitPassword ( password )
const seedWords = await verifySeedPhrase ( )
const seedWords = await verifySeedPhrase ( )
await forceUpdateMetamaskState ( dispatch )
await forceUpdateMetamaskState ( dispatch )
dispatch ( hideLoadingIndication ( ) )
return seedWords
return seedWords
} catch ( error ) {
} catch ( error ) {
dispatch ( hideLoadingIndication ( ) )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
throw new Error ( error . message )
throw new Error ( error . message )
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
}
}
}
}
@ -209,12 +209,12 @@ export function requestRevealSeedWords(password) {
try {
try {
await verifyPassword ( password )
await verifyPassword ( password )
const seedWords = await verifySeedPhrase ( )
const seedWords = await verifySeedPhrase ( )
dispatch ( hideLoadingIndication ( ) )
return seedWords
return seedWords
} catch ( error ) {
} catch ( error ) {
dispatch ( hideLoadingIndication ( ) )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
throw new Error ( error . message )
throw new Error ( error . message )
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
}
}
}
}
@ -306,11 +306,12 @@ export function importNewAccount(strategy, args) {
log . debug ( ` background.getState ` )
log . debug ( ` background.getState ` )
newState = await promisifiedBackground . getState ( )
newState = await promisifiedBackground . getState ( )
} catch ( err ) {
} catch ( err ) {
dispatch ( hideLoadingIndication ( ) )
dispatch ( displayWarning ( err . message ) )
dispatch ( displayWarning ( err . message ) )
throw err
throw err
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( hideLoadingIndication ( ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( updateMetamaskState ( newState ) )
if ( newState . selectedAddress ) {
if ( newState . selectedAddress ) {
dispatch ( {
dispatch ( {
@ -335,11 +336,13 @@ export function addNewAccount() {
} catch ( error ) {
} catch ( error ) {
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
throw error
throw error
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
const newAccountAddress = Object . keys ( newIdentities ) . find (
const newAccountAddress = Object . keys ( newIdentities ) . find (
( address ) => ! oldIdentities [ address ] ,
( address ) => ! oldIdentities [ address ] ,
)
)
dispatch ( hideLoadingIndication ( ) )
await forceUpdateMetamaskState ( dispatch )
await forceUpdateMetamaskState ( dispatch )
return newAccountAddress
return newAccountAddress
}
}
@ -360,9 +363,10 @@ export function checkHardwareStatus(deviceName, hdPath) {
log . error ( error )
log . error ( error )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
throw error
throw error
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( hideLoadingIndication ( ) )
await forceUpdateMetamaskState ( dispatch )
await forceUpdateMetamaskState ( dispatch )
return unlocked
return unlocked
}
}
@ -378,9 +382,10 @@ export function forgetDevice(deviceName) {
log . error ( error )
log . error ( error )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
throw error
throw error
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( hideLoadingIndication ( ) )
await forceUpdateMetamaskState ( dispatch )
await forceUpdateMetamaskState ( dispatch )
}
}
}
}
@ -403,10 +408,11 @@ export function connectHardware(deviceName, page, hdPath) {
log . error ( error )
log . error ( error )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
throw error
throw error
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( hideLoadingIndication ( ) )
await forceUpdateMetamaskState ( dispatch )
await forceUpdateMetamaskState ( dispatch )
return accounts
return accounts
}
}
}
}
@ -421,6 +427,7 @@ export function unlockHardwareWalletAccount(index, deviceName, hdPath) {
deviceName ,
deviceName ,
hdPath ,
hdPath ,
( err ) => {
( err ) => {
dispatch ( hideLoadingIndication ( ) )
if ( err ) {
if ( err ) {
log . error ( err )
log . error ( err )
dispatch ( displayWarning ( err . message ) )
dispatch ( displayWarning ( err . message ) )
@ -428,7 +435,6 @@ export function unlockHardwareWalletAccount(index, deviceName, hdPath) {
return
return
}
}
dispatch ( hideLoadingIndication ( ) )
resolve ( )
resolve ( )
} ,
} ,
)
)
@ -454,12 +460,13 @@ export function setCurrentCurrency(currencyCode) {
try {
try {
data = await promisifiedBackground . setCurrentCurrency ( currencyCode )
data = await promisifiedBackground . setCurrentCurrency ( currencyCode )
} catch ( error ) {
} catch ( error ) {
dispatch ( hideLoadingIndication ( ) )
log . error ( error . stack )
log . error ( error . stack )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
return
return
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( hideLoadingIndication ( ) )
dispatch ( {
dispatch ( {
type : actionConstants . SET _CURRENT _FIAT ,
type : actionConstants . SET _CURRENT _FIAT ,
value : {
value : {
@ -480,12 +487,13 @@ export function signMsg(msgData) {
try {
try {
newState = await promisifiedBackground . signMessage ( msgData )
newState = await promisifiedBackground . signMessage ( msgData )
} catch ( error ) {
} catch ( error ) {
dispatch ( hideLoadingIndication ( ) )
log . error ( error )
log . error ( error )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
throw error
throw error
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( hideLoadingIndication ( ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( completedTx ( msgData . metamaskId ) )
dispatch ( completedTx ( msgData . metamaskId ) )
dispatch ( closeCurrentNotificationWindow ( ) )
dispatch ( closeCurrentNotificationWindow ( ) )
@ -503,12 +511,13 @@ export function signPersonalMsg(msgData) {
try {
try {
newState = await promisifiedBackground . signPersonalMessage ( msgData )
newState = await promisifiedBackground . signPersonalMessage ( msgData )
} catch ( error ) {
} catch ( error ) {
dispatch ( hideLoadingIndication ( ) )
log . error ( error )
log . error ( error )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
throw error
throw error
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( hideLoadingIndication ( ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( completedTx ( msgData . metamaskId ) )
dispatch ( completedTx ( msgData . metamaskId ) )
dispatch ( closeCurrentNotificationWindow ( ) )
dispatch ( closeCurrentNotificationWindow ( ) )
@ -547,12 +556,13 @@ export function decryptMsg(decryptedMsgData) {
try {
try {
newState = await promisifiedBackground . decryptMessage ( decryptedMsgData )
newState = await promisifiedBackground . decryptMessage ( decryptedMsgData )
} catch ( error ) {
} catch ( error ) {
dispatch ( hideLoadingIndication ( ) )
log . error ( error )
log . error ( error )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
throw error
throw error
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( hideLoadingIndication ( ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( completedTx ( decryptedMsgData . metamaskId ) )
dispatch ( completedTx ( decryptedMsgData . metamaskId ) )
dispatch ( closeCurrentNotificationWindow ( ) )
dispatch ( closeCurrentNotificationWindow ( ) )
@ -570,12 +580,13 @@ export function encryptionPublicKeyMsg(msgData) {
try {
try {
newState = await promisifiedBackground . encryptionPublicKey ( msgData )
newState = await promisifiedBackground . encryptionPublicKey ( msgData )
} catch ( error ) {
} catch ( error ) {
dispatch ( hideLoadingIndication ( ) )
log . error ( error )
log . error ( error )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
throw error
throw error
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( hideLoadingIndication ( ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( completedTx ( msgData . metamaskId ) )
dispatch ( completedTx ( msgData . metamaskId ) )
dispatch ( closeCurrentNotificationWindow ( ) )
dispatch ( closeCurrentNotificationWindow ( ) )
@ -593,12 +604,13 @@ export function signTypedMsg(msgData) {
try {
try {
newState = await promisifiedBackground . signTypedMessage ( msgData )
newState = await promisifiedBackground . signTypedMessage ( msgData )
} catch ( error ) {
} catch ( error ) {
dispatch ( hideLoadingIndication ( ) )
log . error ( error )
log . error ( error )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
throw error
throw error
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( hideLoadingIndication ( ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( completedTx ( msgData . metamaskId ) )
dispatch ( completedTx ( msgData . metamaskId ) )
dispatch ( closeCurrentNotificationWindow ( ) )
dispatch ( closeCurrentNotificationWindow ( ) )
@ -788,14 +800,19 @@ export function updateSendEnsResolutionError(errorMessage) {
}
}
export function signTokenTx ( tokenAddress , toAddress , amount , txData ) {
export function signTokenTx ( tokenAddress , toAddress , amount , txData ) {
return ( dispatch ) => {
return async ( dispatch ) => {
dispatch ( showLoadingIndication ( ) )
dispatch ( showLoadingIndication ( ) )
const token = global . eth . contract ( abi ) . at ( tokenAddress )
token . transfer ( toAddress , addHexPrefix ( amount ) , txData ) . catch ( ( err ) => {
try {
const token = global . eth . contract ( abi ) . at ( tokenAddress )
const txPromise = token . transfer ( toAddress , addHexPrefix ( amount ) , txData )
dispatch ( showConfTxPage ( ) )
dispatch ( hideLoadingIndication ( ) )
dispatch ( hideLoadingIndication ( ) )
dispatch ( displayWarning ( err . message ) )
await txPromise
} )
} catch ( error ) {
dispatch ( showConfTxPage ( ) )
dispatch ( hideLoadingIndication ( ) )
dispatch ( displayWarning ( error . message ) )
}
}
}
}
}
@ -815,30 +832,29 @@ const updateMetamaskStateFromBackground = () => {
}
}
export function updateTransaction ( txData , dontShowLoadingIndicator ) {
export function updateTransaction ( txData , dontShowLoadingIndicator ) {
return ( dispatch ) => {
return async ( dispatch ) => {
! dontShowLoadingIndicator && dispatch ( showLoadingIndication ( ) )
! dontShowLoadingIndicator && dispatch ( showLoadingIndication ( ) )
return new Promise ( ( resolve , reject ) => {
try {
b ackground. updateTransaction ( txData , ( err ) => {
await promisifiedB ackground. updateTransaction ( txData )
dispatch ( updateTransactionParams ( txData . id , txData . txParams ) )
} catch ( error ) {
if ( err ) {
dispatch ( updateTransactionParams ( txData . id , txData . txParams ) )
dispatch ( txError ( err ) )
dispatch ( hideLoadingIndication ( ) )
dispatch ( goHome ( ) )
dispatch ( txError ( error ) )
log . error ( err . message )
dispatch ( goHome ( ) )
reject ( err )
log . error ( error . message )
return
throw error
}
}
resolve ( txData )
try {
} )
dispatch ( updateTransactionParams ( txData . id , txData . txParams ) )
} )
const newState = await updateMetamaskStateFromBackground ( )
. then ( ( ) => updateMetamaskStateFromBackground ( ) )
dispatch ( updateMetamaskState ( newState ) )
. then ( ( newState ) => dispatch ( updateMetamaskState ( newState ) ) )
dispatch ( showConfTxPage ( { id : txData . id } ) )
. then ( ( ) => {
return txData
dispatch ( showConfTxPage ( { id : txData . id } ) )
} finally {
dispatch ( hideLoadingIndication ( ) )
dispatch ( hideLoadingIndication ( ) )
return txData
}
} )
}
}
}
}
@ -950,6 +966,7 @@ export function cancelMsg(msgData) {
} finally {
} finally {
dispatch ( hideLoadingIndication ( ) )
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( updateMetamaskState ( newState ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( completedTx ( msgData . id ) )
dispatch ( completedTx ( msgData . id ) )
dispatch ( closeCurrentNotificationWindow ( ) )
dispatch ( closeCurrentNotificationWindow ( ) )
@ -967,6 +984,7 @@ export function cancelPersonalMsg(msgData) {
} finally {
} finally {
dispatch ( hideLoadingIndication ( ) )
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( updateMetamaskState ( newState ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( completedTx ( msgData . id ) )
dispatch ( completedTx ( msgData . id ) )
dispatch ( closeCurrentNotificationWindow ( ) )
dispatch ( closeCurrentNotificationWindow ( ) )
@ -984,6 +1002,7 @@ export function cancelDecryptMsg(msgData) {
} finally {
} finally {
dispatch ( hideLoadingIndication ( ) )
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( updateMetamaskState ( newState ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( completedTx ( msgData . id ) )
dispatch ( completedTx ( msgData . id ) )
dispatch ( closeCurrentNotificationWindow ( ) )
dispatch ( closeCurrentNotificationWindow ( ) )
@ -1003,6 +1022,7 @@ export function cancelEncryptionPublicKeyMsg(msgData) {
} finally {
} finally {
dispatch ( hideLoadingIndication ( ) )
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( updateMetamaskState ( newState ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( completedTx ( msgData . id ) )
dispatch ( completedTx ( msgData . id ) )
dispatch ( closeCurrentNotificationWindow ( ) )
dispatch ( closeCurrentNotificationWindow ( ) )
@ -1020,6 +1040,7 @@ export function cancelTypedMsg(msgData) {
} finally {
} finally {
dispatch ( hideLoadingIndication ( ) )
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( updateMetamaskState ( newState ) )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( completedTx ( msgData . id ) )
dispatch ( completedTx ( msgData . id ) )
dispatch ( closeCurrentNotificationWindow ( ) )
dispatch ( closeCurrentNotificationWindow ( ) )
@ -1031,9 +1052,9 @@ export function cancelTx(txData) {
return ( dispatch ) => {
return ( dispatch ) => {
dispatch ( showLoadingIndication ( ) )
dispatch ( showLoadingIndication ( ) )
return new Promise ( ( resolve , reject ) => {
return new Promise ( ( resolve , reject ) => {
background . cancelTransaction ( txData . id , ( err ) => {
background . cancelTransaction ( txData . id , ( error ) => {
if ( err ) {
if ( error ) {
reject ( err )
reject ( error )
return
return
}
}
@ -1050,6 +1071,10 @@ export function cancelTx(txData) {
return txData
return txData
} )
} )
. catch ( ( error ) => {
dispatch ( hideLoadingIndication ( ) )
throw error
} )
}
}
}
}
@ -1061,34 +1086,38 @@ export function cancelTx(txData) {
export function cancelTxs ( txDataList ) {
export function cancelTxs ( txDataList ) {
return async ( dispatch ) => {
return async ( dispatch ) => {
dispatch ( showLoadingIndication ( ) )
dispatch ( showLoadingIndication ( ) )
const txIds = txDataList . map ( ( { id } ) => id )
const cancellations = txIds . map (
( id ) =>
new Promise ( ( resolve , reject ) => {
background . cancelTransaction ( id , ( err ) => {
if ( err ) {
reject ( err )
return
}
resolve ( )
} )
} ) ,
)
await Promise . all ( cancellations )
try {
const newState = await updateMetamaskStateFromBackground ( )
const txIds = txDataList . map ( ( { id } ) => id )
dispatch ( updateMetamaskState ( newState ) )
const cancellations = txIds . map (
dispatch ( clearSend ( ) )
( id ) =>
new Promise ( ( resolve , reject ) => {
background . cancelTransaction ( id , ( err ) => {
if ( err ) {
reject ( err )
return
}
resolve ( )
} )
} ) ,
)
txIds . forEach ( ( id ) => {
await Promise . all ( cancellations )
dispatch ( completedTx ( id ) )
} )
dispatch ( hideLoadingIndication ( ) )
const newState = await updateMetamaskStateFromBackground ( )
dispatch ( updateMetamaskState ( newState ) )
dispatch ( clearSend ( ) )
if ( getEnvironmentType ( ) === ENVIRONMENT _TYPE _NOTIFICATION ) {
txIds . forEach ( ( id ) => {
global . platform . closeCurrentWindow ( )
dispatch ( completedTx ( id ) )
} )
} finally {
if ( getEnvironmentType ( ) === ENVIRONMENT _TYPE _NOTIFICATION ) {
global . platform . closeCurrentWindow ( )
} else {
dispatch ( hideLoadingIndication ( ) )
}
}
}
}
}
}
}
@ -1235,11 +1264,11 @@ export function setSelectedAddress(address) {
try {
try {
await _setSelectedAddress ( dispatch , address )
await _setSelectedAddress ( dispatch , address )
} catch ( error ) {
} catch ( error ) {
dispatch ( hideLoadingIndication ( ) )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
return
return
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( hideLoadingIndication ( ) )
}
}
}
}
@ -1270,11 +1299,12 @@ export function showAccountDetail(address) {
try {
try {
await _setSelectedAddress ( dispatch , address )
await _setSelectedAddress ( dispatch , address )
} catch ( error ) {
} catch ( error ) {
dispatch ( hideLoadingIndication ( ) )
dispatch ( displayWarning ( error . message ) )
dispatch ( displayWarning ( error . message ) )
return
return
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( hideLoadingIndication ( ) )
dispatch ( {
dispatch ( {
type : actionConstants . SHOW _ACCOUNT _DETAIL ,
type : actionConstants . SHOW _ACCOUNT _DETAIL ,
value : address ,
value : address ,
@ -2024,13 +2054,13 @@ export function setCompletedOnboarding() {
try {
try {
await promisifiedBackground . completeOnboarding ( )
await promisifiedBackground . completeOnboarding ( )
dispatch ( completeOnboarding ( ) )
} catch ( err ) {
} catch ( err ) {
dispatch ( displayWarning ( err . message ) )
dispatch ( displayWarning ( err . message ) )
throw err
throw err
} finally {
dispatch ( hideLoadingIndication ( ) )
}
}
dispatch ( completeOnboarding ( ) )
dispatch ( hideLoadingIndication ( ) )
}
}
}
}
@ -2179,20 +2209,19 @@ export function setIpfsGateway(val) {
export function updateCurrentLocale ( key ) {
export function updateCurrentLocale ( key ) {
return async ( dispatch ) => {
return async ( dispatch ) => {
dispatch ( showLoadingIndication ( ) )
dispatch ( showLoadingIndication ( ) )
await loadRelativeTimeFormatLocaleData ( key )
return fetchLocale ( key ) . then ( ( localeMessages ) => {
try {
log . debug ( ` background.setCurrentLocale ` )
await loadRelativeTimeFormatLocaleData ( key )
background . setCurrentLocale ( key , ( err , textDirection ) => {
const localeMessages = await fetchLocale ( key )
if ( err ) {
const textDirection = await promisifiedBackground . setCurrentLocale ( key )
dispatch ( hideLoadingIndication ( ) )
await switchDirection ( textDirection )
dispatch ( displayWarning ( err . message ) )
dispatch ( setCurrentLocale ( key , localeMessages ) )
return
} catch ( error ) {
}
dispatch ( displayWarning ( error . message ) )
switchDirection ( textDirection )
return
dispatch ( setCurrentLocale ( key , localeMessages ) )
} finally {
dispatch ( hideLoadingIndication ( ) )
dispatch ( hideLoadingIndication ( ) )
} )
}
} )
}
}
}
}