diff --git a/src/containers/transferContainer.js b/src/containers/transferContainer.js index e4562c6b0..149f3fc54 100644 --- a/src/containers/transferContainer.js +++ b/src/containers/transferContainer.js @@ -107,7 +107,7 @@ class TransferContainer extends Component { return validUsers; }; - _transferToAccount = (from, destination, amount, memo) => { + _transferToAccount = async (from, destination, amount, memo) => { const { pinCode, navigation, dispatch, intl } = this.props; let { currentAccount } = this.props; const { selectedAccount } = this.state; @@ -160,7 +160,7 @@ class TransferContainer extends Component { break; } if (!currentAccount.local) { - const realmData = getUserDataWithUsername(currentAccount.name); + const realmData = await getUserDataWithUsername(currentAccount.name); currentAccount.local = realmData[0]; } diff --git a/src/providers/steem/auth.js b/src/providers/steem/auth.js index 4b2c5676e..594ac64c6 100644 --- a/src/providers/steem/auth.js +++ b/src/providers/steem/auth.js @@ -32,7 +32,7 @@ export const login = async (username, password, isPinCodeOpen) => { if (!account) { return Promise.reject(new Error('auth.invalid_username')); } - if (isLoggedInUser(username)) { + if (await isLoggedInUser(username)) { return Promise.reject(new Error('auth.already_logged')); } // Public keys of user @@ -144,7 +144,7 @@ export const loginWithSC2 = async (code, isPinCodeOpen) => { account.local.avatar = avatar; } - if (isLoggedInUser(account.name)) { + if (await isLoggedInUser(account.name)) { reject(new Error('auth.already_logged')); } @@ -167,7 +167,7 @@ export const loginWithSC2 = async (code, isPinCodeOpen) => { export const setUserDataWithPinCode = async data => { try { - const result = getUserDataWithUsername(data.username); + const result = await getUserDataWithUsername(data.username); const userData = result[0]; if (!data.password) { @@ -234,7 +234,7 @@ export const updatePinCode = data => export const verifyPinCode = async data => { const pinHash = await getPinCode(); - const result = getUserDataWithUsername(data.username); + const result = await getUserDataWithUsername(data.username); const userData = result[0]; // This is migration for new pin structure, it will remove v2.2 @@ -338,8 +338,8 @@ export const getUpdatedUserData = (userData, data) => { }; }; -const isLoggedInUser = username => { - const result = getUserDataWithUsername(username); +const isLoggedInUser = async username => { + const result = await getUserDataWithUsername(username); if (result.length > 0) { return true; } diff --git a/src/screens/application/container/applicationContainer.js b/src/screens/application/container/applicationContainer.js index 066a44b4f..b85416700 100644 --- a/src/screens/application/container/applicationContainer.js +++ b/src/screens/application/container/applicationContainer.js @@ -637,7 +637,7 @@ class ApplicationContainer extends Component { const accountData = await switchAccount(targetAccountUsername); - const realmData = getUserDataWithUsername(targetAccountUsername); + const realmData = await getUserDataWithUsername(targetAccountUsername); const _currentAccount = accountData; _currentAccount.username = accountData.name; [_currentAccount.local] = realmData; diff --git a/src/screens/pinCode/container/pinCodeContainer.js b/src/screens/pinCode/container/pinCodeContainer.js index 4548cec71..689c733e5 100644 --- a/src/screens/pinCode/container/pinCodeContainer.js +++ b/src/screens/pinCode/container/pinCodeContainer.js @@ -207,21 +207,22 @@ class PinCodeContainer extends Component { verifyPinCode(pinData) .then(() => { this._savePinCode(pin); - const realmData = getUserDataWithUsername(currentAccount.name); - const _currentAccount = currentAccount; - _currentAccount.username = _currentAccount.name; - [_currentAccount.local] = realmData; - dispatch(updateCurrentAccount({ ..._currentAccount })); - dispatch(closePinCodeModal()); - if (callback) callback(pin, oldPinCode); - if (navigateTo) { - const navigateAction = NavigationActions.navigate({ - routeName: navigateTo, - params: navigateParams, - action: NavigationActions.navigate({ routeName: navigateTo }), - }); - dispatch(navigateAction); - } + getUserDataWithUsername(currentAccount.name).then(realmData => { + const _currentAccount = currentAccount; + _currentAccount.username = _currentAccount.name; + [_currentAccount.local] = realmData; + dispatch(updateCurrentAccount({ ..._currentAccount })); + dispatch(closePinCodeModal()); + if (callback) callback(pin, oldPinCode); + if (navigateTo) { + const navigateAction = NavigationActions.navigate({ + routeName: navigateTo, + params: navigateParams, + action: NavigationActions.navigate({ routeName: navigateTo }), + }); + dispatch(navigateAction); + } + }); }) .catch(err => { Alert.alert( @@ -246,7 +247,7 @@ class PinCodeContainer extends Component { const { intl, currentAccount, applicationPinCode } = this.props; const { isExistUser, pinCode } = this.state; - const realmData = getUserDataWithUsername(currentAccount.name); + const realmData = await getUserDataWithUsername(currentAccount.name); const userData = realmData[0]; // For exist users