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

feat: deposit pending and success screens #1481

Merged
merged 5 commits into from
Jan 30, 2025
Merged

Conversation

tinaszheng
Copy link
Contributor

This PR adds:

  • global tracking for transfer success states. it also stores it in persisted state so that if the user closes the tab and comes back, we'll still be able to query for updated statuses. this will be more relevant for notifications later on
  • pending / success screens!

Up next (not in this PR):

  • calculate account free collateral diffs based on deposit amounts
  • Wait for the account free collateral value to update before showing the success screen. this ensures we also wait for the sweep action to complete, and that users will see success at the same time their account value changes.

@tinaszheng tinaszheng requested a review from a team as a code owner January 29, 2025 21:33
Copy link

vercel bot commented Jan 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
v4-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 30, 2025 6:16pm
v4-testnet ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 30, 2025 6:16pm

Base automatically changed from tina/retry-error-states to main January 29, 2025 22:50
@tinaszheng tinaszheng force-pushed the tina/pending-screens branch from 4f3f74d to c50ca43 Compare January 29, 2025 22:58
@@ -38,14 +36,15 @@ export const LoadingSpinner: React.FC<LoadingSpinnerProps> = ({
cx="19"
cy="19"
r="16"
stroke={stroke}
stroke="var(--color-accent)"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this updates for all loading spinners but this is the new design ANYWAY


// TODO(deposit2.0): localization for this whole component
export const DepositStatus = ({ txHash, chainId, onClose }: DepositStatusProps) => {
const deposit = useAppSelector((store) => getDeposit(store, txHash, chainId));
Copy link
Contributor

Choose a reason for hiding this comment

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

getDeposit isn't a selector so it's running every time anything in the state updates and doing the .find and .flat which could get slow in theory. Should probably be a parameterized selector.

/**
* @returns saved chartConfig for TradingView
*/
export const getPendingDeposits = (state: RootState, dydxAddress?: DydxAddress): Deposit[] => {
Copy link
Contributor

Choose a reason for hiding this comment

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

probably should also be a real selector

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updateddd

type Transfer = Deposit | Withdraw;

export interface TransferState {
accountToTransfers: { [account: DydxAddress]: Transfer[] };
Copy link
Contributor

Choose a reason for hiding this comment

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

kinda mildly prefer transfersByTargetAddress

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh i like. transfersByDydxAddress perhaps. because target address can be your evm address for withdrawals but we'd want to group by dydx account


return {
...state,
transfers: {},
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is necessary since there's some logic jared or you added somewhere that will make a thing initialState if it's undefined when the app starts up / after migrations maybe possibly probably

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we've seen it in the past for whatever reason, better to be safe/explicit i guess /shrug

}, [dydxAddress, pendingDeposits, skipClient, dispatch]);
}

function handleResponseStatus(status: StatusState) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is typescript inferring the return type correctly? Could use LoadableStatus

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup its correct

useEffect(() => {
if (!dydxAddress || !pendingDeposits.length) return;

for (let i = 0; i < pendingDeposits.length; i += 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could this be a .map or .forEach instead ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dont be scared of for loops tyler!


return transfersByAddress[dydxAddress].filter(
(transfer) => transfer.type === 'deposit' && transfer.status === 'pending'
) as Deposit[];
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a way to do this without the cast? Not sure if we could utilize a transfer is Deposit filter function :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that works for individual transfer items but not for the filtered array itself :/ i like the idea of adding some explicit type guard functions tho

);

const selectAllTransfers = createAppSelector(
[(state: RootState) => state.transfers.transfersByDydxAddress],
Copy link
Contributor

Choose a reason for hiding this comment

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

can replace with getTransfersByAddress?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

omg true

</div>
<Button
onClick={onClose}
type={ButtonType.Submit}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think Submit is necessary

@tinaszheng tinaszheng merged commit 8d63546 into main Jan 30, 2025
9 checks passed
@tinaszheng tinaszheng deleted the tina/pending-screens branch January 30, 2025 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants