Skip to content

Commit

Permalink
Remove support for Eth AUDIO send from client (#10803)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickyrombo authored Dec 19, 2024
1 parent 821ae14 commit 0722c33
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const usePurchaseContentErrorMessage = (
case PurchaseErrorCode.NoQuote:
return messages.noQuote
case BuyUSDCErrorCode.OnrampError:
case BuyUSDCErrorCode.CountryNotSupported:
case PurchaseErrorCode.Canceled:
case PurchaseErrorCode.InsufficientBalance:
case PurchaseErrorCode.Unknown:
Expand Down
13 changes: 0 additions & 13 deletions packages/common/src/services/audius-backend/AudiusBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1194,18 +1194,6 @@ export const audiusBackend = ({
}
}

/**
* Make a request to send
*/
async function sendTokens(address: string, amount: BNWei) {
await waitForLibsInit()
const receipt = await audiusLibs.Account.permitAndSendTokens(
address,
amount
)
return receipt
}

/** Gets associated token account info for the passed account. It will
* first check if `address` ia a token account. If not, it will assume
* it is a root account and attempt to derive an associated token account from it.
Expand Down Expand Up @@ -1608,7 +1596,6 @@ export const audiusBackend = ({
identityServiceUrl,
recordTrackListen,
registerDeviceToken,
sendTokens,
sendWAudioTokens,
sendWelcomeEmail,
setup,
Expand Down
19 changes: 1 addition & 18 deletions packages/common/src/services/wallet-client/WalletClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import BN from 'bn.js'

import { userWalletsFromSDK } from '~/adapters'
import { ID, Id } from '~/models/Identifiers'
import {
BNWei,
SolanaWalletAddress,
StringWei,
WalletAddress
} from '~/models/Wallet'
import { BNWei, SolanaWalletAddress, StringWei } from '~/models/Wallet'
import { isNullOrUndefined } from '~/utils/typeUtils'
import { stringWeiToBN } from '~/utils/wallet'

Expand Down Expand Up @@ -240,18 +235,6 @@ export class WalletClient {
}
}

async sendTokens(address: WalletAddress, amount: BNWei): Promise<void> {
if (amount.lt(MIN_TRANSFERRABLE_WEI)) {
throw new Error('Insufficient Audio to transfer')
}
try {
await this.audiusBackendInstance.sendTokens(address, amount)
} catch (err) {
console.error(err)
throw err
}
}

async sendWAudioTokens({
address,
amount,
Expand Down
7 changes: 3 additions & 4 deletions packages/common/src/store/pages/token-dashboard/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Chain } from '../../../models/Chain'
import { BNWei } from '../../../models/Wallet'
import { Nullable } from '../../../utils/typeUtils'
import { stringWeiToBN } from '../../../utils/wallet'
import { CommonState } from '../../commonStore'

export const getSendData = (
state: CommonState
): Nullable<{ recipientWallet: string; amount: BNWei; chain: Chain }> => {
): Nullable<{ recipientWallet: string; amount: BNWei }> => {
const modalState = state.pages.tokenDashboard.modalState
if (
!(
Expand All @@ -17,8 +16,8 @@ export const getSendData = (
)
)
return null
const { recipientWallet, amount, chain } = modalState.flowState
return { recipientWallet, amount: stringWeiToBN(amount), chain }
const { recipientWallet, amount } = modalState.flowState
return { recipientWallet, amount: stringWeiToBN(amount) }
}

export const getModalState = (state: CommonState) =>
Expand Down
9 changes: 3 additions & 6 deletions packages/common/src/store/pages/token-dashboard/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,14 @@ const slice = createSlice({
},
inputSendData: (
state,
{ payload: { amount, wallet, chain } }: InputSendDataAction
{ payload: { amount, wallet } }: InputSendDataAction
) => {
const newState: TokenDashboardPageModalState = {
stage: 'SEND' as const,
flowState: {
stage: 'AWAITING_CONFIRMATION',
amount,
recipientWallet: wallet,
chain,
canRecipientReceiveWAudio: 'loading'
}
}
Expand Down Expand Up @@ -106,8 +105,7 @@ const slice = createSlice({
state.modalState.flowState = {
stage: 'AWAITING_CONVERTING_ETH_AUDIO_TO_SOL',
recipientWallet: state.modalState.flowState.recipientWallet,
amount: state.modalState.flowState.amount,
chain: state.modalState.flowState.chain
amount: state.modalState.flowState.amount
}
},
confirmSend: (state) => {
Expand All @@ -122,8 +120,7 @@ const slice = createSlice({
state.modalState.flowState = {
stage: 'SENDING',
recipientWallet: state.modalState.flowState.recipientWallet,
amount: state.modalState.flowState.amount,
chain: state.modalState.flowState.chain
amount: state.modalState.flowState.amount
}
},
pressReceive: (state) => {
Expand Down
5 changes: 0 additions & 5 deletions packages/common/src/store/pages/token-dashboard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,22 @@ type SendingState =
stage: 'AWAITING_CONFIRMATION'
amount: StringWei
recipientWallet: string
chain: Chain
canRecipientReceiveWAudio: CanReceiveWAudio
}
| {
stage: 'AWAITING_CONVERTING_ETH_AUDIO_TO_SOL'
amount: StringWei
recipientWallet: string
chain: Chain
}
| {
stage: 'SENDING'
amount: StringWei
recipientWallet: WalletAddress
chain: Chain
}
| {
stage: 'CONFIRMED_SEND'
amount: StringWei
recipientWallet: WalletAddress
chain: Chain
}
| { stage: 'ERROR'; error: string }

Expand Down Expand Up @@ -67,7 +63,6 @@ export type ConfirmRemoveWalletAction = PayloadAction<{
export type InputSendDataAction = PayloadAction<{
amount: StringWei
wallet: WalletAddress
chain: Chain
}>

export type AssociatedWalletsState = {
Expand Down
2 changes: 0 additions & 2 deletions packages/common/src/store/wallet/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import BN from 'bn.js'

import { isNullOrUndefined, Nullable } from '~/utils/typeUtils'

import { Chain } from '../../models/Chain'
import { StringUSDC, StringWei } from '../../models/Wallet'

type WalletState = {
Expand Down Expand Up @@ -118,7 +117,6 @@ const slice = createSlice({
_action: PayloadAction<{
recipientWallet: string
amount: StringWei
chain: Chain
}>
) => {},
sendSucceeded: () => {},
Expand Down
66 changes: 24 additions & 42 deletions packages/web/src/common/store/wallet/sagas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Name,
Chain,
ErrorLevel,
BNWei,
SolanaWalletAddress
Expand Down Expand Up @@ -74,7 +73,7 @@ function* getIsBalanceFrozen() {
* @param action.playload.chain 'eth' or 'sol'
*/
function* sendAsync({
payload: { recipientWallet, amount: weiAudioAmount, chain }
payload: { recipientWallet, amount: weiAudioAmount }
}: ReturnType<typeof send>) {
// WalletClient relies on audiusBackendInstance. Use waitForWrite to ensure it's initialized
yield* waitForWrite()
Expand All @@ -101,17 +100,9 @@ function* sendAsync({
return
}

if (
chain === Chain.Eth &&
(!weiBNBalance || !weiBNBalance.gte(weiBNAmount))
) {
if (weiBNAmount.gt(weiBNBalance)) {
yield* put(sendFailed({ error: 'Not enough $AUDIO' }))
return
} else if (chain === Chain.Sol) {
if (weiBNAmount.gt(weiBNBalance)) {
yield* put(sendFailed({ error: 'Not enough $AUDIO' }))
return
}
}

try {
Expand Down Expand Up @@ -140,45 +131,36 @@ function* sendAsync({

// If transferring spl wrapped audio and there are insufficent funds with only the
// user bank balance, transfer all eth AUDIO to spl wrapped audio
if (chain === Chain.Sol && weiBNAmount.gt(waudioWeiAmount)) {
if (weiBNAmount.gt(waudioWeiAmount)) {
yield* put(transferEthAudioToSolWAudio())
yield* call([walletClient, walletClient.transferTokensFromEthToSol], {
sdk,
ethAddress: currentUser
})
}

if (chain === Chain.Eth) {
yield* call(
[walletClient, walletClient.sendTokens],
recipientWallet,
weiBNAmount
)
} else {
try {
yield* call([walletClient, walletClient.sendWAudioTokens], {
address: recipientWallet as SolanaWalletAddress,
amount: weiBNAmount,
ethAddress: currentUser
})
} catch (e) {
const errorMessage = getErrorMessage(e)
if (errorMessage === 'Missing social proof') {
yield* put(sendFailed({ error: 'Missing social proof' }))
return
}
if (
errorMessage ===
'Recipient has no $AUDIO token account. Please install Phantom-Wallet to create one.'
) {
yield* put(sendFailed({ error: errorMessage }))
return
}
yield* put(
sendFailed({ error: 'Something has gone wrong, please try again.' })
)
try {
yield* call([walletClient, walletClient.sendWAudioTokens], {
address: recipientWallet as SolanaWalletAddress,
amount: weiBNAmount,
ethAddress: currentUser
})
} catch (e) {
const errorMessage = getErrorMessage(e)
if (errorMessage === 'Missing social proof') {
yield* put(sendFailed({ error: 'Missing social proof' }))
return
}
if (
errorMessage ===
'Recipient has no $AUDIO token account. Please install Phantom-Wallet to create one.'
) {
yield* put(sendFailed({ error: errorMessage }))
return
}
yield* put(
sendFailed({ error: 'Something has gone wrong, please try again.' })
)
return
}

// Only decrease store balance if we haven't already changed
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/pages/audio-rewards-page/WalletModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ const WalletModal = () => {
chain: Chain
) => {
const stringWei = weiToString(amount)
dispatch(inputSendData({ amount: stringWei, wallet, chain }))
dispatch(inputSendData({ amount: stringWei, wallet }))
}

const onConfirmSend = () => {
Expand Down
9 changes: 3 additions & 6 deletions packages/web/src/store/token-dashboard/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ function* confirmSendAsync() {
// Send the txn, update local balance
const sendData = yield* select(getSendData)
if (!sendData) return
const { recipientWallet, amount, chain } = sendData
yield* put(
walletSend({ recipientWallet, amount: weiToString(amount), chain })
)
const { recipientWallet, amount } = sendData
yield* put(walletSend({ recipientWallet, amount: weiToString(amount) }))

const { error } = yield* race({
success: take(sendSucceeded),
Expand Down Expand Up @@ -80,8 +78,7 @@ function* confirmSendAsync() {
flowState: {
stage: 'CONFIRMED_SEND',
amount: weiToString(amount),
recipientWallet,
chain
recipientWallet
}
}
yield* put(setModalState({ modalState: sentState }))
Expand Down

0 comments on commit 0722c33

Please sign in to comment.