Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
[C-963] Migrate wallet sagas (#1857)
Browse files Browse the repository at this point in the history
* Migrate wallet sagas

* Fix types
  • Loading branch information
sliptype committed Sep 2, 2022
1 parent 238d729 commit 436cd27
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/mobile/src/store/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import confirmerSagas from 'common/store/confirmer/sagas'
import signOnSagas from 'common/store/pages/signon/sagas'
import signOutSagas from 'common/store/sign-out/sagas'
import tippingSagas from 'common/store/tipping/sagas'
import walletSagas from 'common/store/wallet/sagas'
import { all, fork } from 'typed-redux-saga'

import initKeyboardEvents from './keyboard/sagas'
Expand Down Expand Up @@ -37,6 +38,8 @@ export default function* rootSaga() {
// Tipping
...tippingSagas(),

...walletSagas(),

initKeyboardEvents,
...remoteConfig(),
...oauthSagas()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { all, call, put, take, takeEvery, select } from 'typed-redux-saga'

import { make } from 'common/store/analytics/actions'
import { SETUP_BACKEND_SUCCEEDED } from 'common/store/backend/actions'
import { getAssociatedTokenRentExemptionMinimum } from 'services/audius-backend/BuyAudio'

const ATA_SIZE = 165 // Size allocated for an associated token account

const {
getBalance,
Expand Down Expand Up @@ -233,15 +234,25 @@ function* fetchBalanceAsync() {
*/
function* checkAssociatedTokenAccountOrSol(action: InputSendDataAction) {
const walletClient = yield* getContext('walletClient')
const { audiusLibs } = yield* getContext('audiusBackendInstance')
const address = action.payload.wallet

const connection = audiusLibs.solanaWeb3Manager!.connection

const associatedTokenAccount = yield* call(() =>
walletClient.getAssociatedTokenAccountInfo(address)
)
if (!associatedTokenAccount) {
const balance: BNWei = yield* call(() =>
walletClient.getWalletSolBalance(address)
)
const minRentForATA = yield* call(getAssociatedTokenRentExemptionMinimum)

// TODO: this can become a call to getAssociatedTokenRentExemptionMinimum
// when the BuyAudio service has been migrated
const minRentForATA = yield* connection.getMinimumBalanceForRentExemption(
ATA_SIZE,
'processed'
)
const minRentBN = new BN(minRentForATA)
if (balance.lt(minRentBN)) {
yield* put(
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/store/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import notificationUsersPageSagas from 'common/store/user-list/notifications/sag
import repostPageSagas from 'common/store/user-list/reposts/sagas'
import supportingPageSagas from 'common/store/user-list/supporting/sagas'
import topSupportersPageSagas from 'common/store/user-list/top-supporters/sagas'
import walletSagas from 'common/store/wallet/sagas'
import addToPlaylistSagas from 'components/add-to-playlist/store/sagas'
import changePasswordSagas from 'components/change-password/store/sagas'
import firstUploadModalSagas from 'components/first-upload-modal/store/sagas'
Expand Down Expand Up @@ -79,7 +80,6 @@ import playlistLibrarySagas from 'store/playlist-library/sagas'
import routingSagas from 'store/routing/sagas'
import solanaSagas from 'store/solana/sagas'
import tokenDashboardSagas from 'store/token-dashboard/sagas'
import walletSagas from 'store/wallet/sagas'

const NATIVE_MOBILE = process.env.REACT_APP_NATIVE_MOBILE

Expand Down

0 comments on commit 436cd27

Please sign in to comment.