This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C-974] Migrate account sagas (#1884)
* Migrate recordIP service * Migrate waudio service * Add sentry to storeContext * Move playlist-library sagas to web common * Split web logic into web saga * Fix bugs * Actually call action creator * Fix lint
- Loading branch information
Showing
24 changed files
with
415 additions
and
358 deletions.
There are no files selected for viewing
4 changes: 3 additions & 1 deletion
4
...b/src/services/audius-backend/RecordIP.ts → ...n/src/services/audius-backend/RecordIP.ts
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { AccountInfo } from '@solana/spl-token' | ||
import { PublicKey } from '@solana/web3.js' | ||
|
||
import { Nullable } from 'utils/typeUtils' | ||
|
||
import { AnalyticsEvent, Name } from '../../models' | ||
|
||
import { AudiusBackend } from './AudiusBackend' | ||
|
||
export const deriveUserBank = async (audiusBackendInstance: AudiusBackend) => { | ||
const audiusLibs = await audiusBackendInstance.getAudiusLibs() | ||
return (await audiusLibs.solanaWeb3Manager.deriveUserBank()) as PublicKey | ||
} | ||
|
||
export const doesUserBankExist = async ( | ||
audiusBackendInstance: AudiusBackend | ||
) => { | ||
const audiusLibs = await audiusBackendInstance.getAudiusLibs() | ||
const userBank: PublicKey = | ||
await audiusLibs.solanaWeb3Manager.deriveUserBank() | ||
const doesExist = await checkIsCreatedTokenAccount( | ||
userBank.toString(), | ||
audiusBackendInstance | ||
) | ||
return doesExist | ||
} | ||
|
||
export const checkIsCreatedTokenAccount = async ( | ||
addr: string, | ||
audiusBackendInstance: AudiusBackend | ||
) => { | ||
const audiusLibs = await audiusBackendInstance.getAudiusLibs() | ||
const tokenAccount: Nullable<AccountInfo> = | ||
await audiusLibs.solanaWeb3Manager.getTokenAccountInfo(addr) | ||
return tokenAccount != null | ||
} | ||
|
||
export const createUserBank = async ( | ||
feePayerOverride = null, | ||
audiusBackendInstance: AudiusBackend | ||
) => { | ||
const audiusLibs = await audiusBackendInstance.getAudiusLibs() | ||
return audiusLibs.solanaWeb3Manager.createUserBank(feePayerOverride) | ||
} | ||
|
||
export const createUserBankIfNeeded = async ( | ||
recordAnalytics: (event: AnalyticsEvent, callback?: () => void) => void, | ||
audiusBackendInstance: AudiusBackend, | ||
feePayerOverride = null | ||
) => { | ||
const audiusLibs = await audiusBackendInstance.getAudiusLibs() | ||
const userId = audiusLibs.Account.getCurrentUser().user_id | ||
try { | ||
const userbankExists = await doesUserBankExist(audiusBackendInstance) | ||
if (userbankExists) return | ||
console.warn(`Userbank doesn't exist, attempting to create...`) | ||
await recordAnalytics({ | ||
eventName: Name.CREATE_USER_BANK_REQUEST, | ||
properties: { userId } | ||
}) | ||
const { error, errorCode } = await createUserBank( | ||
feePayerOverride, | ||
audiusBackendInstance | ||
) | ||
if (error || errorCode) { | ||
console.error( | ||
`Failed to create userbank, with err: ${error}, ${errorCode}` | ||
) | ||
await recordAnalytics({ | ||
eventName: Name.CREATE_USER_BANK_FAILURE, | ||
properties: { | ||
userId, | ||
errorCode, | ||
error: (error as any).toString() | ||
} | ||
}) | ||
} else { | ||
console.log(`Successfully created userbank!`) | ||
await recordAnalytics({ | ||
eventName: Name.CREATE_USER_BANK_SUCCESS, | ||
properties: { userId } | ||
}) | ||
} | ||
} catch (err) { | ||
await recordAnalytics({ | ||
eventName: Name.CREATE_USER_BANK_FAILURE, | ||
properties: { | ||
userId, | ||
errorMessage: (err as any).toString() | ||
} | ||
}) | ||
console.error(`Failed to create userbank, with err: ${err}`) | ||
} | ||
} |
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,3 +1,3 @@ | ||
export { reducer as accountReducer, actions as accountActions } from './reducer' | ||
export { reducer as accountReducer, actions as accountActions } from './slice' | ||
export * as accountSelectors from './selectors' | ||
export * from './types' |
File renamed without changes.
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
Oops, something went wrong.