Skip to content

Commit

Permalink
Fix order of ops for account fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson committed Jan 16, 2025
1 parent 11c13e6 commit 717dc92
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions packages/common/src/store/account/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,12 @@ export function* fetchAccountAsync() {
const localStorage = yield* getContext('localStorage')
const sdk = yield* getSDK()
const accountStatus = yield* select(getAccountStatus)
// Don't revert successful local account fetch
if (accountStatus !== Status.SUCCESS) {
yield* put(fetchAccountRequested())
}

const { accountWalletAddress: wallet, web3WalletAddress } = yield* call([
authService,
authService.getWalletAddresses
])
console.log({ wallet, accountStatus })
if (!wallet) {
yield* put(
fetchAccountFailed({
Expand All @@ -182,6 +179,12 @@ export function* fetchAccountAsync() {
)
return
}

// Don't revert successful local account fetch
if (accountStatus !== Status.SUCCESS) {
yield* put(fetchAccountRequested())
}

const accountData: AccountUserMetadata | undefined = yield* call(
userApiFetchSaga.getUserAccount,
{
Expand Down Expand Up @@ -276,6 +279,7 @@ export function* fetchAccountAsync() {

function* fetchLocalAccountAsync() {
const localStorage = yield* getContext('localStorage')
const authService = yield* getContext('authService')

yield* put(fetchAccountRequested())

Expand All @@ -287,8 +291,17 @@ function* fetchLocalAccountAsync() {
localStorage,
localStorage.getAudiusAccountUser
])
const { accountWalletAddress: wallet } = yield* call([
authService,
authService.getWalletAddresses
])

if (cachedAccount && cachedAccountUser && !cachedAccountUser.is_deactivated) {
if (
cachedAccount &&
cachedAccountUser &&
wallet &&
!cachedAccountUser.is_deactivated
) {
yield* put(
cacheActions.add(Kind.USERS, [
{
Expand Down

0 comments on commit 717dc92

Please sign in to comment.