Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PAY-2394][PAY-2391][PAY-2393] Address misc coinflow withdrawal ux #7312

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions packages/common/src/api/user.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { full } from '@audius/sdk'
import { full } from '@audius/sdk'

import { createApi } from 'audius-query'
import { ID, Kind, StringUSDC } from 'models'
Expand All @@ -7,6 +7,7 @@ import {
USDCTransactionMethod,
USDCTransactionType
} from 'models/USDCTransactions'
import { getRootSolanaAccount } from 'services/audius-backend/solana'
import { Nullable } from 'utils/typeUtils'

import { Id } from './utils'
Expand All @@ -21,18 +22,24 @@ type GetUSDCTransactionListArgs = {
method?: full.GetUSDCTransactionsMethodEnum
}

const parseTransaction = (
transaction: full.TransactionDetails
): USDCTransactionDetails => {
const { change, balance, transactionType, method, ...rest } = transaction
return {
...rest,
transactionType: transactionType as USDCTransactionType,
method: method as USDCTransactionMethod,
change: change as StringUSDC,
balance: balance as StringUSDC
const makeParseTransaction =
(rootSolanaAccount: Nullable<string>) =>
(transaction: full.TransactionDetails): USDCTransactionDetails => {
const { change, balance, transactionType, method, metadata, ...rest } =
transaction
return {
...rest,
metadata: !rootSolanaAccount
? metadata
: rootSolanaAccount === metadata.toString()
? `Cash (${metadata})`
: metadata,
transactionType: transactionType as USDCTransactionType,
method: method as USDCTransactionMethod,
change: change as StringUSDC,
balance: balance as StringUSDC
}
}
}

const userApi = createApi({
reducerPath: 'userApi',
Expand Down Expand Up @@ -129,8 +136,19 @@ const userApi = createApi({
encodedDataMessage,
encodedDataSignature
})
// When fetching withdrawals, get the root account to display
// additional transaction context
if (
type === full.GetUSDCTransactionsTypeEnum.Transfer &&
method === full.GetUSDCTransactionCountMethodEnum.Send
) {
const rootSolanaAccount = (
await getRootSolanaAccount(context.audiusBackend)
).publicKey.toString()

return data.map(parseTransaction)
return data.map(makeParseTransaction(rootSolanaAccount))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love it, but I think it should probably be done at this layer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the worst. Could probably use a little more commentary to understand what's going on. Maybe as a jsdoc on the parsing function?

}
return data.map(makeParseTransaction(null))
},
options: { retry: true }
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ const messages = {

const MINIMUM_MANUAL_TRANSFER_AMOUNT_CENTS = 1

const DISABLE_MODAL_CLOSE_PAGES = new Set([
WithdrawUSDCModalPages.PREPARE_TRANSFER,
WithdrawUSDCModalPages.TRANSFER_IN_PROGRESS
])

const WithdrawUSDCFormSchema = (
userBalanceCents: number,
minWithdrawBalanceCents: number
Expand Down Expand Up @@ -228,9 +233,13 @@ export const WithdrawUSDCModal = () => {
isOpen={isOpen}
onClose={onClose}
onClosed={handleOnClosed}
dismissOnClickOutside={DISABLE_MODAL_CLOSE_PAGES.has(page)}
bodyClassName={styles.modal}
>
<ModalHeader onClose={onClose}>
<ModalHeader
onClose={onClose}
showDismissButton={DISABLE_MODAL_CLOSE_PAGES.has(page)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be inverted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

>
<Text
variant='label'
color='neutralLight2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const TransferSuccessful = ({
balanceStatus === Status.SUCCESS ? `$${balanceFormatted}` : undefined
}
/>
{methodValue !== WithdrawMethod.MANUAL_TRANSFER ? (
{methodValue !== WithdrawMethod.MANUAL_TRANSFER && signature ? (
<>
<Divider style={{ margin: 0 }} />
<div className={styles.destination}>
Expand Down