Skip to content

Commit

Permalink
feat(HW-697): add Tron support for transaction list (#2189)
Browse files Browse the repository at this point in the history
* feat(HW-697): add Tron support for transaction list

* fix(HW-932): Tron Transaction issues

* feat(HW-934): add fee check to transaction flow screens

* fix: transaction list
  • Loading branch information
iGroza authored Nov 6, 2024
1 parent 4b7be6f commit cf6a445
Show file tree
Hide file tree
Showing 19 changed files with 589 additions and 147 deletions.
2 changes: 1 addition & 1 deletion src/components/transaction-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const TransactionDetail = observer(
short
/>

{balance.isPositive() && (
{balance?.isPositive() && (
<DataContent
title={balance.toBalanceString(LONG_NUM_PRECISION)}
subtitleI18n={I18N.transactionDetailAmount}
Expand Down
49 changes: 36 additions & 13 deletions src/components/transaction-list/transaction-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {TransactionSectionHeader} from './transaction-section-header';
import {ItemData, SectionHeaderData, TransactionSection} from './types';

import {TransactionEmpty} from '../transaction-empty';
import {Spacer} from '../ui';
import {Loading, Spacer} from '../ui';

type OmitedSectionListProps = Omit<
SectionListProps<Transaction, TransactionSection>,
Expand Down Expand Up @@ -95,10 +95,15 @@ export const TransactionList = observer(

const sections = useMemo(
() =>
hideContent
hideContent || (!transactions?.length && isTransactionsLoading)
? []
: prepareDataForSectionList(transactions, txTimestampHeadersEnabled),
[transactions, hideContent, txTimestampHeadersEnabled],
[
transactions,
hideContent,
txTimestampHeadersEnabled,
isTransactionsLoading,
],
);

const listStyle = useMemo(
Expand All @@ -125,7 +130,7 @@ export const TransactionList = observer(
await Transaction.fetchNextTransactions(addresses);
}, [isTransactionsLoading]);
const keyExtractor = useCallback(
(item: Transaction) => `${item.id}:${item.hash}`,
(item: Transaction) => `${item.id}:${item.hash}:${item.msg.type}`,
[],
);

Expand Down Expand Up @@ -153,20 +158,38 @@ export const TransactionList = observer(
},
[addresses, onTransactionPress],
);
const renderListEmptyComponent = useCallback(
const renderListEmptyComponentDefault = useCallback(
() => <TransactionEmpty />,
[],
);

const renderListEmptyComponent = useMemo(() => {
if (sectionListProps.ListEmptyComponent) {
// if active tab is transactions and transactions are loading
if (!hideContent && isTransactionsLoading) {
return <Loading />;
}
return sectionListProps.ListEmptyComponent;
}
return renderListEmptyComponentDefault;
}, [hideContent, renderListEmptyComponentDefault, isTransactionsLoading]);

const renderListFooterComponent = useCallback(
() => (
<>
<ActivityIndicator
size="small"
color={
isTransactionsLoading ? getColor(Color.textBase2) : 'transparent'
}
/>
<Spacer height={12} />
{!hideContent && !!sections.length && (
<>
<ActivityIndicator
size="small"
color={
isTransactionsLoading
? getColor(Color.textBase2)
: 'transparent'
}
/>
<Spacer height={12} />
</>
)}
</>
),
[isTransactionsLoading],
Expand All @@ -178,11 +201,11 @@ export const TransactionList = observer(
overScrollMode="never"
bounces={false}
scrollEnabled={scrollEnabled}
ListEmptyComponent={renderListEmptyComponent}
ListFooterComponent={renderListFooterComponent}
contentContainerStyle={styles.grow}
{...sectionListProps}
/* CAN'NOT OVERRIDE */
ListEmptyComponent={renderListEmptyComponent}
sections={sections}
renderItem={renderItem}
keyExtractor={keyExtractor}
Expand Down
6 changes: 5 additions & 1 deletion src/event-actions/on-push-notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,16 @@ export async function onPushNotification(message: RemoteMessage<Data>) {
hash,
);
if (transaction) {
Transaction.create(transaction);
Transaction.create(
transaction,
Indexer.instance.getProvidersHeader(Wallet.addressList()),
);
navigator.navigate(HomeStackRoutes.TransactionDetail, {
// FIXME: For some reason navigator doesn't understand routing types correctly
// @ts-ignore
txId: transaction.id,
addresses: Wallet.addressList(),
txType: transaction.msg.type,
});
}
break;
Expand Down
16 changes: 16 additions & 0 deletions src/helpers/address-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ import {splitAddress} from '@app/utils';

export const HAQQ_VALIDATOR_PREFIX = 'haqqvaloper';
export class AddressUtils {
static bufferToTron(base64buffer: string): AddressTron {
if (!base64buffer) {
return '' as AddressTron;
}

if (AddressUtils.isTronAddress(base64buffer)) {
return base64buffer as AddressTron;
}

return AddressUtils.hexToTron(AddressUtils.fromBuffer(base64buffer));
}

static fromBuffer(base64buffer: string) {
return `0x${Buffer.from(base64buffer, 'base64').toString('hex')}`;
}

static hexToTron(address?: string): AddressTron {
if (!address) {
return '' as AddressTron;
Expand Down
Loading

0 comments on commit cf6a445

Please sign in to comment.