Skip to content

Commit

Permalink
Update Add Funds copy and loading state (#8266)
Browse files Browse the repository at this point in the history
Co-authored-by: Saliou Diallo <saliou@audius.co>
  • Loading branch information
sddioulde and Saliou Diallo committed Apr 30, 2024
1 parent 4503cc7 commit 62b5a08
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 29 deletions.
6 changes: 3 additions & 3 deletions packages/common/src/store/buy-crypto/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ function* doBuyCryptoViaSol({
amount: (lamportsToPurchase / LAMPORTS_PER_SOL).toString(),
destinationCurrency: 'sol',
destinationWallet: wallet.publicKey.toBase58(),
onrampCanceled,
onrampFailed,
onrampSucceeded
onrampCanceled: onrampCanceled(),
onrampFailed: onrampFailed({}),
onrampSucceeded: onrampSucceeded()
})
)
yield* put(setVisibility({ modal: 'StripeOnRamp', visible: true }))
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/store/buy-crypto/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const slice = createSlice({
*/
onrampFailed: (
_state,
_action: PayloadAction<{ error: StripeSessionCreationError }>
_action: PayloadAction<{ error?: StripeSessionCreationError }>
) => {
// handled by saga
},
Expand Down
11 changes: 4 additions & 7 deletions packages/common/src/store/buy-usdc/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ import {
purchaseStarted,
onrampSucceeded,
startRecoveryIfNecessary,
recoveryStatusChanged,
transferStarted
recoveryStatusChanged
} from './slice'
import { BuyUSDCError, BuyUSDCErrorCode } from './types'
import { getBuyUSDCRemoteConfig, getUSDCUserBank } from './utils'
Expand Down Expand Up @@ -178,8 +177,6 @@ function* transferStep({
const feePayerOverride = new PublicKey(feePayer)
const recentBlockhash = yield* call(getRecentBlockhash, audiusBackendInstance)

yield* put(transferStarted())

yield* call(
retry,
async () => {
Expand Down Expand Up @@ -264,9 +261,9 @@ function* doBuyUSDC({
amount: (desiredAmount / 100).toString(),
destinationCurrency: 'usdc',
destinationWallet: rootAccount.publicKey.toString(),
onrampCanceled,
onrampFailed,
onrampSucceeded
onrampCanceled: onrampCanceled(),
onrampFailed: onrampFailed({}),
onrampSucceeded: onrampSucceeded()
})
)

Expand Down
6 changes: 1 addition & 5 deletions packages/common/src/store/buy-usdc/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@ const slice = createSlice({
onrampSucceeded: (state) => {
state.stage = BuyUSDCStage.CONFIRMING_PURCHASE
},
transferStarted: (state) => {
state.stage = BuyUSDCStage.TRANSFERRING
},
onrampFailed: (
_state,
_action: PayloadAction<{ error: StripeSessionCreationError }>
_action: PayloadAction<{ error?: StripeSessionCreationError }>
) => {
// handled by saga
},
Expand Down Expand Up @@ -104,7 +101,6 @@ export const {
onrampSucceeded,
onrampCanceled,
onrampFailed,
transferStarted,
stripeSessionStatusChanged,
startRecoveryIfNecessary,
recoveryStatusChanged,
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/store/buy-usdc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export enum BuyUSDCStage {
START = 'START',
PURCHASING = 'PURCHASING',
CONFIRMING_PURCHASE = 'CONFIRMING_PURCHASE',
TRANSFERRING = 'TRANSFERRING',
CANCELED = 'CANCELED',
FINISH = 'FINISH'
}
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/store/ui/stripe-modal/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function* handleStripeSessionChanged({
}

if (onrampSucceeded) {
yield* put(onrampSucceeded)
yield* put({ ...onrampSucceeded })
}
yield* put(setVisibility({ modal: 'StripeOnRamp', visible: 'closing' }))
}
Expand All @@ -139,7 +139,7 @@ function* handleCancelStripeOnramp() {
yield* put(setVisibility({ modal: 'StripeOnRamp', visible: 'closing' }))

if (onrampCanceled) {
yield* put(onrampCanceled)
yield* put({ ...onrampCanceled })
}
}

Expand Down
7 changes: 5 additions & 2 deletions packages/web/src/components/add-funds-modal/AddFundsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export const AddFundsModal = () => {
const { isOpen, onClose } = useAddFundsModal()
const dispatch = useDispatch()
const buyUSDCStage = useSelector(getBuyUSDCFlowStage)
const isTransferring = buyUSDCStage === BuyUSDCStage.TRANSFERRING
const inProgress = [
BuyUSDCStage.PURCHASING,
BuyUSDCStage.CONFIRMING_PURCHASE
].includes(buyUSDCStage)
const isMobile = useIsMobile()

const [page, setPage] = useState<Page>('add-funds')
Expand Down Expand Up @@ -82,7 +85,7 @@ export const AddFundsModal = () => {
onClosed={handleClosed}
bodyClassName={styles.modal}
useGradientTitle={false}
dismissOnClickOutside={!isTransferring}
dismissOnClickOutside={!inProgress}
isFullscreen={false}
>
<ModalHeader
Expand Down
13 changes: 8 additions & 5 deletions packages/web/src/components/add-funds/AddFunds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const { getBuyUSDCFlowStage } = buyUSDCSelectors

const messages = {
usdcBalance: 'USDC Balance',
transferring: 'Transferring funds to your wallet...',
purchasing: 'Purchasing',
continue: 'Continue'
}

Expand Down Expand Up @@ -48,7 +48,10 @@ export const AddFunds = ({
const balance = USDC(balanceBN ?? new BN(0)).value

const buyUSDCStage = useSelector(getBuyUSDCFlowStage)
const isTransferring = buyUSDCStage === BuyUSDCStage.TRANSFERRING
const inProgress = [
BuyUSDCStage.PURCHASING,
BuyUSDCStage.CONFIRMING_PURCHASE
].includes(buyUSDCStage)

return (
<div className={styles.root}>
Expand Down Expand Up @@ -90,10 +93,10 @@ export const AddFunds = ({
onClick={() =>
onContinue(selectedPurchaseMethod, selectedPurchaseVendor)
}
isLoading={isTransferring}
disabled={isTransferring}
isLoading={inProgress}
disabled={inProgress}
>
{isTransferring ? messages.transferring : messages.continue}
{inProgress ? messages.purchasing : messages.continue}
</Button>
</Flex>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export const StripeBuyAudioButton = () => {
dispatch(
initializeStripeModal({
amount,
onrampSucceeded,
onrampCanceled,
onrampFailed: onrampCanceled,
onrampSucceeded: onrampSucceeded(),
onrampCanceled: onrampCanceled(),
onrampFailed: onrampCanceled(),
destinationCurrency: 'sol',
destinationWallet
})
Expand Down

0 comments on commit 62b5a08

Please sign in to comment.