@@ -1,6 +1,7 @@
11import React, { useCallback, useEffect, useMemo, useState } from 'react';
22
33import * as need from 'lib/need';
4+import * as ob from 'urbit-ob';
45import { useWallet } from 'store/wallet';
56import useRoller from 'lib/useRoller';
67import { useLocalRouter } from 'lib/LocalRouter';
@@ -25,7 +26,7 @@ interface GroupedTransactions {
2526}
2627
2728const TransactionHistory = () => {
28− const { pop }: any = useLocalRouter();
29+ const { pop, data }: any = useLocalRouter();
2930 const { api } = useRoller();
3031 const { wallet }: any = useWallet();
3132 const address = need.addressFromWallet(wallet);
@@ -34,6 +35,14 @@ const TransactionHistory = () => {
3435 const [dropdownOpen, setDropdownOpen] = useState<boolean>(false);
3536 const [selectedPatp, setSelectedPatp] = useState<string | null>(null);
3637
38+ // Pre-filter the results if navigating from Point view
39+ const filterByPoint = useMemo(() => {
40+ return data?.filterByPoint.matchWith({
41+ Nothing: () => null,
42+ Just: (p: number) => ob.patp(p.value).replace('~', ''),
43+ });
44+ }, [data]);
45+
3746 const shortAddress = useMemo(() => {
3847 return address.slice(0, 6);
3948 }, [address]);
@@ -41,8 +50,11 @@ const TransactionHistory = () => {
4150 const fetchTransactions = useCallback(async () => {
4251 const txns = await api.getHistory(address);
4352 setTransactions(txns);
53+ if (filterByPoint) {
54+ setSelectedPatp(filterByPoint);
55+ }
4456 setLoading(false);
45− }, [address, api]);
57+ }, [address, api, filterByPoint]);
4658
4759 const selectPatp = useCallback(patp => {
4860 setSelectedPatp(patp);
@@ -51,17 +63,20 @@ const TransactionHistory = () => {
5163
5264 const txnsByPatp = useMemo(() => {
5365 return transactions.reduce((memo, tx) => {
54− if (Object.keys(memo).includes(tx.ship)) {
55− memo[tx.ship].push(tx);
66+ const patp = tx.ship;
67+ if (Object.keys(memo).includes(patp)) {
68+ memo[patp].push(tx);
5669 } else {
57− memo[tx.ship] = [tx];
70+ memo[patp] = [tx];
5871 }
5972 return memo;
6073 }, {} as GroupedTransactions);
6174 }, [transactions]);
6275
6376 const txPatps = useMemo(() => {
64− return Object.keys(txnsByPatp).sort();
77+ return Object.keys(txnsByPatp).sort((a, b) => {
78+ return ob.patp2dec(`~${a}`) - ob.patp2dec(`~${b}`);
79+ });
6580 }, [txnsByPatp]);
6681
6782 const filteredPatps = useMemo(() => {
@@ -74,7 +89,9 @@ const TransactionHistory = () => {
7489
7590 useEffect(() => {
7691 fetchTransactions();
77− }, [fetchTransactions]);
92+ // Load the TX history only once
93+ // eslint-disable-next-line react-hooks/exhaustive-deps
94+ }, []);
7895
7996 return (
8097 <View