Skip to content

Commit

Permalink
mobile: history op screen improvements (#709)
Browse files Browse the repository at this point in the history
* mobile: make History Op usernames clickable

* stop disabling tab swipe on history op
  • Loading branch information
nalinbhardwaj committed Feb 13, 2024
1 parent 1f091fe commit 3386faf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
25 changes: 18 additions & 7 deletions apps/daimo-mobile/src/view/screen/HistoryOpScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import {
OpStatus,
PaymentLinkOpEvent,
amountToDollars,
canSendTo,
getAccountName,
timeString,
} from "@daimo/common";
import { ChainConfig, daimoChainFromId } from "@daimo/contract";
import React, { createContext, useCallback, useContext } from "react";
import { Linking, StyleSheet, View } from "react-native";
import { TouchableHighlight } from "react-native-gesture-handler";

import { NoteDisplay } from "./link/NoteScreen";
import { getCachedEAccount } from "../../logic/addr";
Expand All @@ -28,8 +30,8 @@ import { ContactBubble } from "../shared/ContactBubble";
import { PendingDot } from "../shared/PendingDot";
import { ScreenHeader } from "../shared/ScreenHeader";
import Spacer from "../shared/Spacer";
import { useDisableTabSwipe, useNav } from "../shared/nav";
import { color, ss } from "../shared/style";
import { navToAccountPage, useNav } from "../shared/nav";
import { color, ss, touchHighlightUnderlay } from "../shared/style";
import {
TextBody,
TextBodyCaps,
Expand All @@ -51,8 +53,6 @@ export function HistoryOpScreen(props: Props) {

function HistoryOpScreenInner({ account, op }: Props) {
const toggleBottomSheet = useContext(ToggleBottomSheetContext);
const nav = useNav();
useDisableTabSwipe(nav);

// Load the latest version of this op. If the user opens the detail screen
// while the op is pending, and it confirms, the screen should update.
Expand Down Expand Up @@ -171,7 +171,7 @@ function TransferBody({
const chainName = chainConfig.chainL2.name.toUpperCase();

return (
<View style={ss.container.padH16}>
<View>
<TextCenter>
<TextH3 color={color.grayDark}>{verb}</TextH3>
</TextCenter>
Expand Down Expand Up @@ -201,9 +201,20 @@ function OpRow({ op, otherAcc }: { op: OpEvent; otherAcc: EAccount }) {

const date = timeString(op.timestamp);

const nav = useNav();

const viewAccount = useCallback(() => {
navToAccountPage(otherAcc, nav);
}, [nav, otherAcc]);

return (
<View style={styles.transferBorder}>
<View style={styles.transferRowWrap}>
<TouchableHighlight
onPress={viewAccount}
disabled={!canSendTo(otherAcc)}
{...touchHighlightUnderlay.subtle}
style={styles.transferRowWrap}
>
<View style={styles.transferRow}>
<View style={styles.transferOtherAccount}>
<ContactBubble
Expand All @@ -216,7 +227,7 @@ function OpRow({ op, otherAcc }: { op: OpEvent; otherAcc: EAccount }) {
</View>
<TextPara color={textLight}>{date}</TextPara>
</View>
</View>
</TouchableHighlight>
</View>
);
}
Expand Down
8 changes: 2 additions & 6 deletions apps/daimo-mobile/src/view/shared/HistoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { getAmountText } from "./Amount";
import { ContactBubble } from "./ContactBubble";
import { PendingDot } from "./PendingDot";
import Spacer from "./Spacer";
import { useNav } from "./nav";
import { navToAccountPage, useNav } from "./nav";
import { color, ss, touchHighlightUnderlay } from "./style";
import { DaimoText, TextBody, TextCenter, TextLight } from "./text";
import { getCachedEAccount } from "../../logic/addr";
Expand Down Expand Up @@ -207,15 +207,11 @@ function DisplayOpRow({
const nav = useNav();
const viewOp = useCallback(
(isLinkToOp: boolean) => {
// Workaround: react-navigation typescript types are broken.
// currentTab is eg "SendNav", is NOT in fact a ParamListTab:
const currentTab = nav.getState().routes[0].name;
const newTab = currentTab.startsWith("Send") ? "SendTab" : "HomeTab";
if (isLinkToOp || !canSendTo(otherAcc)) {
toggleBottomSheet(true);
onSelectHistoryOp(displayOp);
} else {
nav.navigate(newTab, { screen: "Account", params: { eAcc: otherAcc } });
navToAccountPage(otherAcc, nav);
}
},
[nav, displayOp, linkTo, otherAcc]
Expand Down
9 changes: 9 additions & 0 deletions apps/daimo-mobile/src/view/shared/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,12 @@ export function useFocusOnScreenTransitionEnd(
return unsubscribe;
}, [isFocused, autoFocus]);
}

// Open account page within the same tab.
export function navToAccountPage(account: EAccount, nav: MainNav) {
// Workaround: react-navigation typescript types are broken.
// currentTab is eg "SendNav", is NOT in fact a ParamListTab:
const currentTab = nav.getState().routes[0].name;
const newTab = currentTab.startsWith("Send") ? "SendTab" : "HomeTab";
nav.navigate(newTab, { screen: "Account", params: { eAcc: account } });
}

0 comments on commit 3386faf

Please sign in to comment.