diff --git a/app/models/authcore-store/authcore-store.ts b/app/models/authcore-store/authcore-store.ts index 13bbb6433..3a4dc7ade 100644 --- a/app/models/authcore-store/authcore-store.ts +++ b/app/models/authcore-store/authcore-store.ts @@ -25,6 +25,7 @@ export const AuthCoreStoreModel = types accessToken: "", idToken: "", hasSignedIn: false, + pendingInit: null, })) .extend(withEnvironment) .views(self => ({ @@ -43,6 +44,7 @@ export const AuthCoreStoreModel = types self.hasSignedIn = value }, fetchCurrentUser: flow(function * () { + if (self.pendingInit) yield self.pendingInit const currentUser: any = yield self.env.authCoreAPI.getCurrentUser(self.accessToken) self.profile = AuthCoreUserModel.create(currentUser) }), @@ -73,6 +75,7 @@ export const AuthCoreStoreModel = types } = yield self.env.authCoreAPI.setupModules(refreshToken, accessToken) self.accessToken = newAccessToken self.cosmosAddresses.replace(addresses) + self.pendingInit = null }), signOut: flow(function * () { self.setHasSignedIn(false) @@ -104,17 +107,22 @@ export const AuthCoreStoreModel = types ]) }), resume: flow(function * () { - const [ - { password: refreshToken }, - { password: accessToken }, - { password: idToken }, - ]: any = yield Promise.all([ + const promises = Promise.all([ Keychain.load(self.getCredentialKeyFor("refresh_token")), Keychain.load(self.getCredentialKeyFor("access_token")), Keychain.load(self.getCredentialKeyFor("id_token")), - ]) - yield self.init(refreshToken, accessToken, idToken) - self.setHasSignedIn(true) + ]).then((res) => { + const [ + { password: refreshToken }, + { password: accessToken }, + { password: idToken }, + ] = res + return self.init(refreshToken, accessToken, idToken) + }).then(() => { + self.setHasSignedIn(true) + }) + self.pendingInit = promises + yield promises }), })) diff --git a/app/models/root-store/setup-root-store.ts b/app/models/root-store/setup-root-store.ts index dd3b0dc9d..057958416 100644 --- a/app/models/root-store/setup-root-store.ts +++ b/app/models/root-store/setup-root-store.ts @@ -92,9 +92,10 @@ export async function setupRootStore() { // Setup Authcore env.setupAuthCore() if (rootStore.userStore.currentUser) { - await rootStore.userStore.authCore.resume() - const address = rootStore.userStore.authCore.primaryCosmosAddress - rootStore.chainStore.setupWallet(address) + rootStore.userStore.authCore.resume().then(() => { + const address = rootStore.userStore.authCore.primaryCosmosAddress + rootStore.chainStore.setupWallet(address) + }) } } catch (e) { // if there's any problems loading, then let's at least fallback to an empty state diff --git a/app/screens/auth-loading-screen/auth-loading-screen.tsx b/app/screens/auth-loading-screen/auth-loading-screen.tsx index 1170e80f3..3f3150441 100644 --- a/app/screens/auth-loading-screen/auth-loading-screen.tsx +++ b/app/screens/auth-loading-screen/auth-loading-screen.tsx @@ -25,13 +25,14 @@ export class AuthLoadingScreen extends React.Component