Skip to content

Commit

Permalink
Split TransactionListScene
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon-edge committed Jan 28, 2025
1 parent c62bcc0 commit ecb3d20
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 67 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## Unreleased (develop)

- added: Price chart to `TransactionListScene`
- added: Add Unizen DEX
- changed: `TransactionListScene` split into two scenes: `TransactionListScene` and `TransactionListScene2`

## 4.21.0 (2025-01-22)

Expand Down
16 changes: 16 additions & 0 deletions src/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import { SweepPrivateKeyProcessingScene as SweepPrivateKeyProcessingSceneCompone
import { SweepPrivateKeySelectCryptoScene as SweepPrivateKeySelectCryptoSceneComponent } from './scenes/SweepPrivateKeySelectCryptoScene'
import { TransactionDetailsScene as TransactionDetailsSceneComponent } from './scenes/TransactionDetailsScene'
import { TransactionList as TransactionListComponent } from './scenes/TransactionListScene'
import { TransactionList2 as TransactionList2Component } from './scenes/TransactionListScene2'
import { TransactionsExportScene as TransactionsExportSceneComponent } from './scenes/TransactionsExportScene'
import { UpgradeUsernameScene as UpgradeUsernameSceneComponent } from './scenes/UpgradeUsernameScreen'
import { WalletListScene as WalletListSceneComponent } from './scenes/WalletListScene'
Expand Down Expand Up @@ -218,6 +219,7 @@ const SwapSettingsScene = ifLoggedIn(SwapSettingsSceneComponent)
const SwapSuccessScene = ifLoggedIn(SwapSuccessSceneComponent)
const TransactionDetailsScene = ifLoggedIn(TransactionDetailsSceneComponent)
const TransactionList = ifLoggedIn(TransactionListComponent)
const TransactionList2 = ifLoggedIn(TransactionList2Component)
const TransactionsExportScene = ifLoggedIn(TransactionsExportSceneComponent)
const WalletListScene = ifLoggedIn(WalletListSceneComponent)
const WalletRestoreScene = ifLoggedIn(WalletRestoreSceneComponent)
Expand Down Expand Up @@ -276,6 +278,13 @@ const EdgeWalletsTabScreen = () => {
headerTitle: () => <ParamHeaderTitle<'transactionList'> fromParams={params => params.walletName} />
}}
/>
<WalletsStack.Screen
name="transactionList2"
component={TransactionList2}
options={{
headerTitle: () => <ParamHeaderTitle<'transactionList2'> fromParams={params => params.walletName} />
}}
/>
</WalletsStack.Navigator>
)
}
Expand Down Expand Up @@ -781,6 +790,13 @@ const EdgeAppStack = () => {
headerTitle: () => <TransactionDetailsTitle />
}}
/>
<WalletsStack.Screen
name="transactionList2"
component={TransactionList2}
options={{
headerTitle: () => <ParamHeaderTitle<'transactionList2'> fromParams={params => params.walletName} />
}}
/>
<AppStack.Screen
name="transactionsExport"
component={TransactionsExportScene}
Expand Down
90 changes: 30 additions & 60 deletions src/components/scenes/TransactionListScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import { useSceneScrollHandler } from '../../state/SceneScrollState'
import { useDispatch, useSelector } from '../../types/reactRedux'
import { NavigationBase, WalletsTabSceneProps } from '../../types/routerTypes'
import { coinrankListData, infoServerData } from '../../util/network'
import { calculateSpamThreshold, convertNativeToDenomination, darkenHexColor, unixToLocaleDateTime, zeroString } from '../../util/utils'
import { calculateSpamThreshold, convertNativeToDenomination, darkenHexColor, zeroString } from '../../util/utils'
import { EdgeCard } from '../cards/EdgeCard'
import { InfoCardCarousel } from '../cards/InfoCardCarousel'
import { SwipeChart } from '../charts/SwipeChart'
import { AccentColors } from '../common/DotsBackground'
import { EdgeAnim, fadeInDown10, MAX_LIST_ITEMS_ANIM } from '../common/EdgeAnim'
import { fadeInDown10 } from '../common/EdgeAnim'
import { SceneWrapper } from '../common/SceneWrapper'
import { SectionHeader as SectionHeaderUi4 } from '../common/SectionHeader'
import { withWallet } from '../hoc/withWallet'
Expand All @@ -35,7 +35,7 @@ import { BuyCrypto } from '../themed/BuyCrypto'
import { EdgeText, Paragraph } from '../themed/EdgeText'
import { ExplorerCard } from '../themed/ExplorerCard'
import { SearchFooter } from '../themed/SearchFooter'
import { EmptyLoader, SectionHeader, SectionHeaderCentered } from '../themed/TransactionListComponents'
import { EmptyLoader, SectionHeaderCentered } from '../themed/TransactionListComponents'
import { TransactionListRow } from '../themed/TransactionListRow'
import { TransactionListTop } from '../themed/TransactionListTop'

Expand Down Expand Up @@ -101,11 +101,7 @@ function TransactionListComponent(props: Props) {
}, [exchangeDenom, exchangeRate, spamFilterOn])

// Transaction list state machine:
const {
transactions,
atEnd,
requestMore: handleScrollEnd
} = useTransactionList(wallet, tokenId, {
const { transactions, requestMore: handleScrollEnd } = useTransactionList(wallet, tokenId, {
searchString: isSearching ? searchText : undefined,
spamThreshold
})
Expand All @@ -116,36 +112,10 @@ function TransactionListComponent(props: Props) {
const listItems = React.useMemo(() => {
if (isTransactionListUnsupported) return []

let lastSection = ''
const out: ListItem[] = []
for (const tx of transactions) {
// Create a new section header if we need one:
const { date } = unixToLocaleDateTime(tx.date)
if (date !== lastSection) {
out.push(date)
lastSection = date
}

// Add the transaction to the list:
out.push(tx)
}

// If we are still loading, add a spinner at the end:
if (!atEnd) out.push(null)

return out
}, [atEnd, isTransactionListUnsupported, transactions])

// TODO: Comment out sticky header indices until we figure out how to
// give the headers a background only when they're sticking.
// Figure out where the section headers are located:
// const stickyHeaderIndices = React.useMemo<number[]>(() => {
// const out: number[] = []
// for (let i = 0; i < listItems.length; ++i) {
// if (typeof listItems[i] === 'string') out.push(i)
// }
// return out
// }, [listItems])
// Take only the 5 most recent transactions
const recentTransactions = transactions.slice(0, 5)
return recentTransactions.length > 0 ? recentTransactions : []
}, [isTransactionListUnsupported, transactions])

// ---------------------------------------------------------------------------
// Side-Effects
Expand Down Expand Up @@ -202,6 +172,10 @@ function TransactionListComponent(props: Props) {
navigation.navigate('coinRankingDetails', { assetId, fiatCurrencyCode })
})

const handlePressSeeAll = useHandler(() => {
navigation.navigate('transactionList2', route.params)
})

//
// Renderers
//
Expand Down Expand Up @@ -254,13 +228,20 @@ function TransactionListComponent(props: Props) {
)}
<SectionHeaderUi4
leftTitle={lstrings.transaction_list_recent_transactions}
rightNode={lstrings.coin_rank_see_more}
onRightPress={handlePressCoinRanking}
rightNode={listItems.length === 0 ? null : lstrings.see_all}
onRightPress={handlePressSeeAll}
/>
<EdgeCard sections>
{listItems.map((tx: EdgeTransaction) => (
<View key={tx.txid} style={styles.txRow}>
<TransactionListRow navigation={navigation as NavigationBase} transaction={tx} wallet={wallet} noCard />
</View>
))}
</EdgeCard>
</>
)
}, [
listItems.length,
listItems,
navigation,
isSearching,
tokenId,
Expand All @@ -274,7 +255,9 @@ function TransactionListComponent(props: Props) {
handlePressCoinRanking,
fiatRateFormat,
currencyCode,
fiatCurrencyCode
fiatCurrencyCode,
handlePressSeeAll,
styles.txRow
])

const emptyComponent = React.useMemo(() => {
Expand All @@ -292,19 +275,7 @@ function TransactionListComponent(props: Props) {
return <EmptyLoader />
}

const disableAnimation = index >= MAX_LIST_ITEMS_ANIM
if (typeof item === 'string') {
return (
<EdgeAnim disableAnimation={disableAnimation} enter={{ type: 'fadeInDown', distance: 30 * (index + 1) }}>
<SectionHeader title={item} />
</EdgeAnim>
)
}
return (
<EdgeAnim disableAnimation={disableAnimation} enter={{ type: 'fadeInDown', distance: 30 * (index + 1) }}>
<TransactionListRow navigation={navigation as NavigationBase} transaction={item} wallet={wallet} />
</EdgeAnim>
)
return null // We're not using the FlatList rendering anymore
})

const keyExtractor = useHandler((item: ListItem) => {
Expand Down Expand Up @@ -376,9 +347,6 @@ function TransactionListComponent(props: Props) {
ListHeaderComponent={topArea}
onEndReachedThreshold={0.5}
renderItem={renderItem}
// TODO: Comment out sticky header indices until we figure out how to
// give the headers a background only when they're sticking.
// stickyHeaderIndices={stickyHeaderIndices}
onEndReached={handleScrollEnd}
onScroll={handleScroll}
scrollIndicatorInsets={SCROLL_INDICATOR_INSET_FIX}
Expand Down Expand Up @@ -406,7 +374,9 @@ export const TransactionList = withWallet(TransactionListComponent)

const getStyles = cacheStyles(() => ({
flatList: {
overflow: 'visible',
flexShrink: 0
flex: 1
},
txRow: {
paddingVertical: 0
}
}))
Loading

0 comments on commit ecb3d20

Please sign in to comment.