Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/components/UI/Bridge/Views/BridgeView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import { useInitialDestToken } from '../../hooks/useInitialDestToken';
import { useGasFeeEstimates } from '../../../../Views/confirmations/hooks/gas/useGasFeeEstimates';
import { selectSelectedNetworkClientId } from '../../../../../selectors/networkController';
import { useMetrics, MetaMetricsEvents } from '../../../../hooks/useMetrics';
import { BridgeToken, BridgeViewMode } from '../../types';
import { BridgeToken, BridgeViewMode, CowSwapQuoteResponse } from '../../types';
import { useSwitchTokens } from '../../hooks/useSwitchTokens';
import { ScrollView } from 'react-native';
import useIsInsufficientBalance from '../../hooks/useInsufficientBalance';
Expand Down Expand Up @@ -343,7 +343,7 @@ const BridgeView = () => {
if (activeQuote) {
dispatch(setIsSubmittingTx(true));
await submitBridgeTx({
quoteResponse: activeQuote,
quoteResponse: activeQuote as CowSwapQuoteResponse & QuoteMetadata,
});
}
} catch (error) {
Expand Down
6 changes: 6 additions & 0 deletions app/components/UI/Bridge/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TxData, Quote, Intent } from '@metamask/bridge-controller';
import { Asset } from '@metamask/assets-controllers';
import { Hex, CaipChainId } from '@metamask/utils';

Expand All @@ -18,6 +19,11 @@ export interface BridgeToken {
currencyExchangeRate?: number; // A rate of the token in the user's currency, e.g. 100.12345
accountType?: Asset['accountType'];
}
export interface CowSwapQuoteResponse extends QuoteResponse {
aggregator: string;
walletAddress: string;
intent?: Intent;
}

export enum BridgeViewMode {
Swap = 'Swap',
Expand Down
164 changes: 106 additions & 58 deletions app/components/UI/TransactionElement/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { PureComponent } from 'react';
import React, { PureComponent, useCallback } from 'react';
import PropTypes from 'prop-types';
import {
TouchableOpacity,
Expand Down Expand Up @@ -162,6 +162,20 @@ const NEW_TRANSACTION_DETAILS_TYPES = [
TransactionType.predictWithdraw,
];

const INTENT_STATUS = {
SUBMITTED: 'SUBMITTED',
PENDING: 'PENDING',
COMPLETE: 'COMPLETE',
FAILED: 'FAILED',
UNKNOWN: 'UNKNOWN',
};

const TRANSACTION_STATUS = {
SUBMITTED: 'submitted',
PENDING: 'pending',
CONFIRMED: 'confirmed',
FAILED: 'failed',
};
/**
* View that renders a transaction item part of transactions list
*/
Expand Down Expand Up @@ -449,6 +463,24 @@ class TransactionElement extends PureComponent {
);
};

mapIntentStatusToTransactionStatus = (intentStatus) => {
if (intentStatus === INTENT_STATUS.PENDING) {
return TRANSACTION_STATUS.PENDING;
}
if (intentStatus === INTENT_STATUS.COMPLETE) {
return TRANSACTION_STATUS.CONFIRMED;
}
if (intentStatus === INTENT_STATUS.FAILED) {
return TRANSACTION_STATUS.FAILED;
}
if (intentStatus === INTENT_STATUS.SUBMITTED) {
return TRANSACTION_STATUS.SUBMITTED;
}

// if it is unknown status, default to failed
return TRANSACTION_STATUS.FAILED;
};

/**
* Renders an horizontal bar with basic tx information
*
Expand All @@ -468,14 +500,23 @@ class TransactionElement extends PureComponent {
const { colors, typography } = this.context || mockTheme;
const styles = createStyles(colors, typography);
const { value, fiatValue = false, actionKey } = transactionElement;
// transform the status from bridgeTxHistoryItem to the status of the transaction
let transactionStatus = status;
if (bridgeTxHistoryItem) {
transactionStatus = this.mapIntentStatusToTransactionStatus(
bridgeTxHistoryItem.status.status,
);
}

const renderNormalActions =
(status === 'submitted' ||
(status === 'approved' && !isQRHardwareAccount && !isLedgerAccount)) &&
(transactionStatus === 'submitted' ||
(transactionStatus === 'approved' &&
!isQRHardwareAccount &&
!isLedgerAccount)) &&
!isSmartTransaction &&
!isBridgeTransaction;
const renderUnsignedQRActions =
status === 'approved' && isQRHardwareAccount;
transactionStatus === 'approved' && isQRHardwareAccount;
const renderLedgerActions = status === 'approved' && isLedgerAccount;
const accountImportTime = selectedInternalAccount?.metadata.importTime;
let title = actionKey;
Expand All @@ -484,62 +525,69 @@ class TransactionElement extends PureComponent {
}

return (
<ListItem>
<ListItem.Date style={styles.listItemDate}>
{this.renderTxTime()}
</ListItem.Date>
<ListItem.Content style={styles.listItemContent}>
<ListItem.Icon>
{this.renderTxElementIcon(transactionElement, tx)}
</ListItem.Icon>
<ListItem.Body>
<ListItem.Title numberOfLines={1} style={styles.listItemTitle}>
{title}
</ListItem.Title>
{!FINAL_NON_CONFIRMED_STATUSES.includes(status) &&
isBridgeTransaction &&
!isBridgeComplete ? (
<BridgeActivityItemTxSegments
bridgeTxHistoryItem={bridgeTxHistoryItem}
transactionStatus={this.props.tx.status}
/>
) : (
<StatusText
testID={`transaction-status-${i}`}
status={status}
style={styles.listItemStatus}
/>
)}
</ListItem.Body>
{Boolean(value) && (
<ListItem.Amounts>
{!isTestNet(chainId) && (
<ListItem.FiatAmount style={styles.listItemFiatAmount}>
{fiatValue}
</ListItem.FiatAmount>
<>
{accountImportTime > time && this.renderImportTime()}
<ListItem>
<ListItem.Date style={styles.listItemDate}>
{this.renderTxTime()}
</ListItem.Date>
<ListItem.Content style={styles.listItemContent}>
<ListItem.Icon>
{this.renderTxElementIcon(
transactionElement,
transactionStatus,
chainId,
)}
</ListItem.Icon>
<ListItem.Body>
<ListItem.Title numberOfLines={1} style={styles.listItemTitle}>
{title}
</ListItem.Title>
{!FINAL_NON_CONFIRMED_STATUSES.includes(status) &&
isBridgeTransaction &&
!isBridgeComplete ? (
<BridgeActivityItemTxSegments
bridgeTxHistoryItem={bridgeTxHistoryItem}
transactionStatus={this.props.tx.status}
/>
) : (
<StatusText
testID={`transaction-status-${i}`}
status={transactionStatus}
style={styles.listItemStatus}
/>
)}
<ListItem.Amount style={styles.listItemAmount}>
{value}
</ListItem.Amount>
</ListItem.Amounts>
</ListItem.Body>
{Boolean(value) && (
<ListItem.Amounts>
{!isTestNet(chainId) && (
<ListItem.FiatAmount style={styles.listItemFiatAmount}>
{fiatValue}
</ListItem.FiatAmount>
)}
<ListItem.Amount style={styles.listItemAmount}>
{value}
</ListItem.Amount>
</ListItem.Amounts>
)}
</ListItem.Content>
{renderNormalActions && (
<ListItem.Actions>
{this.renderSpeedUpButton()}
{this.renderCancelButton()}
</ListItem.Actions>
)}
</ListItem.Content>
{renderNormalActions && (
<ListItem.Actions>
{this.renderSpeedUpButton()}
{this.renderCancelButton()}
</ListItem.Actions>
)}
{renderUnsignedQRActions && (
<ListItem.Actions>
{this.renderQRSignButton()}
{this.renderCancelUnsignedButton()}
</ListItem.Actions>
)}
{renderLedgerActions && (
<ListItem.Actions>{this.renderLedgerSignButton()}</ListItem.Actions>
)}
</ListItem>
{renderUnsignedQRActions && (
<ListItem.Actions>
{this.renderQRSignButton()}
{this.renderCancelUnsignedButton()}
</ListItem.Actions>
)}
{renderLedgerActions && (
<ListItem.Actions>{this.renderLedgerSignButton()}</ListItem.Actions>
)}
</ListItem>
</>
);
};

Expand Down
15 changes: 7 additions & 8 deletions app/constants/bridge.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { SolScope, BtcScope, TrxScope } from '@metamask/keyring-api';
import { CHAIN_IDS } from '@metamask/transaction-controller';
import { CaipChainId, Hex } from '@metamask/utils';
import {
BRIDGE_DEV_API_BASE_URL,
BRIDGE_PROD_API_BASE_URL,
} from '@metamask/bridge-controller';

/**
* Swaps testnet chain ID (1337 in decimal)
Expand Down Expand Up @@ -60,7 +56,10 @@ export const NETWORK_TO_SHORT_NETWORK_NAME_MAP: Record<
[TrxScope.Mainnet]: 'Tron',
};

export const BRIDGE_API_BASE_URL =
process.env.BRIDGE_USE_DEV_APIS === 'true'
? BRIDGE_DEV_API_BASE_URL
: BRIDGE_PROD_API_BASE_URL;
// export const BRIDGE_API_BASE_URL =
// process.env.BRIDGE_USE_DEV_APIS === 'true'
// ? BRIDGE_DEV_API_BASE_URL
// : BRIDGE_PROD_API_BASE_URL;

//TODO link to dev bridge API. Update to prod bridge API when ready.
export const BRIDGE_API_BASE_URL = 'http://localhost:3000';
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@ export function getTransactionControllerInitMessenger(
'SmartTransactionsController:smartTransaction',
'SmartTransactionsController:smartTransactionConfirmationDone',
],
allowedActions: [
'ApprovalController:addRequest',
'ApprovalController:endFlow',
'ApprovalController:startFlow',
'ApprovalController:updateRequestState',
'KeyringController:signTypedMessage',
'BridgeStatusController:submitTx',
'DelegationController:signDelegation',
'NetworkController:getEIP1559Compatibility',
'KeyringController:signEip7702Authorization',
'KeyringController:signTypedMessage',
],
messenger,
});

Expand Down
Loading
Loading