Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace incoming with external transactions #10908

Closed
Closed
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
15 changes: 9 additions & 6 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,9 @@
"externalExtension": {
"message": "External Extension"
},
"externalSend": {
"message": "External Send"
},
"extraApprovalGas": {
"message": "+$1 approval gas",
"description": "Expresses an additional gas amount the user will have to pay, on top of some other displayed amount. $1 is a decimal amount of gas"
Expand Down Expand Up @@ -1587,6 +1590,12 @@
"showAdvancedGasInlineDescription": {
"message": "Select this to show gas price and limit controls directly on the send and confirm screens."
},
"showExternalTransactions": {
"message": "Show External Transactions"
},
"showExternalTransactionsDescription": {
"message": "Select this to use Etherscan to show external transactions (incoming and originated from external wallets) in the transactions list"
},
"showFiatConversionInTestnets": {
"message": "Show Conversion on Testnets"
},
Expand All @@ -1599,12 +1608,6 @@
"showHexDataDescription": {
"message": "Select this to show the hex data field on the send screen"
},
"showIncomingTransactions": {
"message": "Show Incoming Transactions"
},
"showIncomingTransactionsDescription": {
"message": "Select this to use Etherscan to show incoming transactions in the transactions list"
},
"showPermissions": {
"message": "Show permissions"
},
Expand Down
6 changes: 0 additions & 6 deletions app/_locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1437,12 +1437,6 @@
"showHexDataDescription": {
"message": "Seleccionar esto para mostrar el campo de los datos en formato hex en la pantalla de mandar"
},
"showIncomingTransactions": {
"message": "Mostrar transacciones entrantes"
},
"showIncomingTransactionsDescription": {
"message": "Seleccione esto para usar Etherscan para mostrar las transacciones entrantes en la lista de transacciones"
},
"showPermissions": {
"message": "Mostrar permisos"
},
Expand Down
6 changes: 0 additions & 6 deletions app/_locales/es_419/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1437,12 +1437,6 @@
"showHexDataDescription": {
"message": "Selecciona esto para mostrar el campo de datos hexadecimales en la pantalla de envío"
},
"showIncomingTransactions": {
"message": "Mostrar transacciones entrantes"
},
"showIncomingTransactionsDescription": {
"message": "Seleccione esto para usar Etherscan para mostrar las transacciones entrantes en la lista de transacciones"
},
"showPermissions": {
"message": "Mostrar permisos"
},
Expand Down
6 changes: 0 additions & 6 deletions app/_locales/hi/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1428,12 +1428,6 @@
"showHexDataDescription": {
"message": "भेजने की स्क्रीन पर हेक्स डेटा फ़ील्ड दिखाने के लिए इसका चयन करें"
},
"showIncomingTransactions": {
"message": "आने वाले लेनदेन दिखाएँ"
},
"showIncomingTransactionsDescription": {
"message": "लेनदेन सूची में आने वाले लेनदेन को दिखाने के लिए Etherscan का उपयोग करने के लिए इसका चयन करें"
},
"showPermissions": {
"message": "अनुमतियाँ दिखाएँ"
},
Expand Down
6 changes: 0 additions & 6 deletions app/_locales/id/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1428,12 +1428,6 @@
"showHexDataDescription": {
"message": "Pilih ini untuk menampilkan bidang data hex di layar kirim"
},
"showIncomingTransactions": {
"message": "Menampilkan Transaksi yang Masuk"
},
"showIncomingTransactionsDescription": {
"message": "Pilih ini untuk menggunakan Etherscan untuk menampilkan transaksi yang masuk di daftar transaksi"
},
"showPermissions": {
"message": "Tampilkan Izin"
},
Expand Down
6 changes: 0 additions & 6 deletions app/_locales/it/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1443,12 +1443,6 @@
"showHexDataDescription": {
"message": "Seleziona per mostrare il campo dei dati hex nella schermata di invio"
},
"showIncomingTransactions": {
"message": "Mostra Transazioni in Ingresso"
},
"showIncomingTransactionsDescription": {
"message": "Usa Etherscan per visualizzare le transazioni in ingresso nella lista delle transazioni"
},
"showPermissions": {
"message": "Mostra permessi"
},
Expand Down
6 changes: 0 additions & 6 deletions app/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1437,12 +1437,6 @@
"showHexDataDescription": {
"message": "オンにすると、送金画面に16進データフィールドを表示します"
},
"showIncomingTransactions": {
"message": "着信したトランザクションの表示"
},
"showIncomingTransactionsDescription": {
"message": "オンにすると、Etherscanを使用して、着信トランザクションをトランザクションリストに表示します"
},
"showPermissions": {
"message": "権限の表示"
},
Expand Down
6 changes: 0 additions & 6 deletions app/_locales/ko/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1428,12 +1428,6 @@
"showHexDataDescription": {
"message": "이 항목을 선택하면 보내기 화면에 16진수 데이터 필드가 표시됩니다."
},
"showIncomingTransactions": {
"message": "수신 거래 표시"
},
"showIncomingTransactionsDescription": {
"message": "이 항목을 선택하면 Etherscan을 사용하여 거래 목록에 수신 거래를 표시합니다."
},
"showPermissions": {
"message": "권한 표시"
},
Expand Down
6 changes: 0 additions & 6 deletions app/_locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1428,12 +1428,6 @@
"showHexDataDescription": {
"message": "Выберите эту опцию, чтобы отобразить поле шестнадцатеричных данных на экране отправки"
},
"showIncomingTransactions": {
"message": "Показать входящие транзакции"
},
"showIncomingTransactionsDescription": {
"message": "Выберите это, чтобы использовать Etherscan для отображения входящих транзакций в списке транзакций"
},
"showPermissions": {
"message": "Показать разрешения"
},
Expand Down
6 changes: 0 additions & 6 deletions app/_locales/tl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1425,12 +1425,6 @@
"showHexDataDescription": {
"message": "Piliin ito para ipakita ang field ng hex data sa screen ng pagpapadala"
},
"showIncomingTransactions": {
"message": "Ipakita ang Mga Papasok na Transaksyon"
},
"showIncomingTransactionsDescription": {
"message": "Piliin ito para gamitin ang Etherscan sa pagpapakita ng mga papasok na transaksyon sa listahan ng mga transaksyon"
},
"showPermissions": {
"message": "Ipakita ang mga pahintulot"
},
Expand Down
6 changes: 0 additions & 6 deletions app/_locales/vi/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1428,12 +1428,6 @@
"showHexDataDescription": {
"message": "Chọn tùy chọn này để hiển thị trường dữ liệu thập lục phân trên màn hình gửi"
},
"showIncomingTransactions": {
"message": "Hiển thị các giao dịch đến"
},
"showIncomingTransactionsDescription": {
"message": "Chọn tùy chọn này nếu bạn muốn dùng Etherscan để hiển thị các giao dịch đến trong danh sách giao dịch"
},
"showPermissions": {
"message": "Hiển thị quyền"
},
Expand Down
6 changes: 0 additions & 6 deletions app/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1437,12 +1437,6 @@
"showHexDataDescription": {
"message": "请选择该选项,在发送页面显示十六进制数据字域"
},
"showIncomingTransactions": {
"message": "显示收到的交易"
},
"showIncomingTransactionsDescription": {
"message": "选择该选项可使用 Etherscan(以太坊浏览器)(以太坊浏览器)在交易列表中显示收到的交易。"
},
"showPermissions": {
"message": "显示权限"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ const fetchWithTimeout = getFetchWithTimeout(30000);
*/

/**
* This controller is responsible for retrieving incoming transactions. Etherscan is polled once every block to check
* for new incoming transactions for the current selected account on the current network
* This controller is responsible for retrieving external transactions. Etherscan is polled once every block to check
* for new external transactions for the current selected account on the current network
*
* Note that only the built-in Infura networks are supported (i.e. anything in `INFURA_PROVIDER_TYPES`). We will not
* attempt to retrieve incoming transactions on any custom RPC endpoints.
* attempt to retrieve external transactions on any custom RPC endpoints.
*/
const etherscanSupportedNetworks = [
GOERLI_CHAIN_ID,
Expand All @@ -58,7 +58,7 @@ const etherscanSupportedNetworks = [
ROPSTEN_CHAIN_ID,
];

export default class IncomingTransactionsController {
export default class ExternalTransactionsController {
constructor(opts = {}) {
const {
blockTracker,
Expand All @@ -77,8 +77,8 @@ export default class IncomingTransactionsController {
};

const initState = {
incomingTransactions: {},
incomingTxLastFetchedBlockByChainId: {
externalTransactions: {},
externalTxLastFetchedBlockByChainId: {
[GOERLI_CHAIN_ID]: null,
[KOVAN_CHAIN_ID]: null,
[MAINNET_CHAIN_ID]: null,
Expand All @@ -93,20 +93,20 @@ export default class IncomingTransactionsController {
previousValueComparator((prevState, currState) => {
const {
featureFlags: {
showIncomingTransactions: prevShowIncomingTransactions,
showExternalTransactions: prevShowExternalTransactions,
} = {},
} = prevState;
const {
featureFlags: {
showIncomingTransactions: currShowIncomingTransactions,
showExternalTransactions: currShowExternalTransactions,
} = {},
} = currState;

if (currShowIncomingTransactions === prevShowIncomingTransactions) {
if (currShowExternalTransactions === prevShowExternalTransactions) {
return;
}

if (prevShowIncomingTransactions && !currShowIncomingTransactions) {
if (prevShowExternalTransactions && !currShowExternalTransactions) {
this.stop();
return;
}
Expand Down Expand Up @@ -135,9 +135,9 @@ export default class IncomingTransactionsController {

start() {
const { featureFlags = {} } = this.preferencesController.store.getState();
const { showIncomingTransactions } = featureFlags;
const { showExternalTransactions } = featureFlags;

if (!showIncomingTransactions) {
if (!showExternalTransactions) {
return;
}

Expand Down Expand Up @@ -169,19 +169,19 @@ export default class IncomingTransactionsController {
const currentBlock = parseInt(this.blockTracker.getCurrentBlock(), 16);

const mostRecentlyFetchedBlock =
currentState.incomingTxLastFetchedBlockByChainId[chainId];
currentState.externalTxLastFetchedBlockByChainId[chainId];
const blockToFetchFrom =
mostRecentlyFetchedBlock ?? newBlockNumberDec ?? currentBlock;

const newIncomingTxs = await this._getNewIncomingTransactions(
const newExternalTxs = await this._getNewExternalTransactions(
address,
blockToFetchFrom,
chainId,
);

let newMostRecentlyFetchedBlock = blockToFetchFrom;

newIncomingTxs.forEach((tx) => {
newExternalTxs.forEach((tx) => {
if (
tx.blockNumber &&
parseInt(newMostRecentlyFetchedBlock, 10) <
Expand All @@ -192,17 +192,17 @@ export default class IncomingTransactionsController {
});

this.store.updateState({
incomingTxLastFetchedBlockByChainId: {
...currentState.incomingTxLastFetchedBlockByChainId,
externalTxLastFetchedBlockByChainId: {
...currentState.externalTxLastFetchedBlockByChainId,
[chainId]: newMostRecentlyFetchedBlock + 1,
},
incomingTransactions: newIncomingTxs.reduce(
externalTransactions: newExternalTxs.reduce(
(transactions, tx) => {
transactions[tx.hash] = tx;
return transactions;
},
{
...currentState.incomingTransactions,
...currentState.externalTransactions,
},
),
});
Expand All @@ -221,7 +221,7 @@ export default class IncomingTransactionsController {
* @param {string} [chainId] - The chainId for the current network
* @returns {TransactionMeta[]}
*/
async _getNewIncomingTransactions(address, fromBlock, chainId) {
async _getNewExternalTransactions(address, fromBlock, chainId) {
const etherscanSubdomain =
chainId === MAINNET_CHAIN_ID
? 'api'
Expand All @@ -235,32 +235,31 @@ export default class IncomingTransactionsController {
}
const response = await fetchWithTimeout(url);
const { status, result } = await response.json();
let newIncomingTxs = [];
const newExternalTxs = [];
if (status === '1' && Array.isArray(result) && result.length > 0) {
const remoteTxList = {};
const remoteTxs = [];
const externalTxList = {};
result.forEach((tx) => {
if (!remoteTxList[tx.hash]) {
remoteTxs.push(this._normalizeTxFromEtherscan(tx, chainId));
remoteTxList[tx.hash] = 1;
if (!externalTxList[tx.hash]) {
newExternalTxs.push(
this._normalizeTxFromEtherscan(tx, chainId, address),
);
externalTxList[tx.hash] = 1;
}
});

newIncomingTxs = remoteTxs.filter(
(tx) => tx.txParams?.to?.toLowerCase() === address.toLowerCase(),
);
newIncomingTxs.sort((a, b) => (a.time < b.time ? -1 : 1));
newExternalTxs.sort((a, b) => (a.time < b.time ? -1 : 1));
}
return newIncomingTxs;
return newExternalTxs;
}

/**
* Transmutes a EtherscanTransaction into a TransactionMeta
* @param {EtherscanTransaction} etherscanTransaction - the transaction to normalize
* @param {string} chainId - The chainId of the current network
* @param {string} address - Selected address
* @returns {TransactionMeta}
*/
_normalizeTxFromEtherscan(etherscanTransaction, chainId) {
_normalizeTxFromEtherscan(etherscanTransaction, chainId, address) {
const time = parseInt(etherscanTransaction.timeStamp, 10) * 1000;
const status =
etherscanTransaction.isError === '0'
Expand All @@ -282,7 +281,10 @@ export default class IncomingTransactionsController {
value: bnToHex(new BN(etherscanTransaction.value)),
},
hash: etherscanTransaction.hash,
type: TRANSACTION_TYPES.INCOMING,
type:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type parameter here will not be this simple, this could be any currently supported type of transaction not just sent or incoming. In the main transaction controller we use a method that determines what the transaction's type is.. we could potentially reuse some of that logic.

etherscanTransaction.from.toLowerCase() === address?.toLowerCase()
? TRANSACTION_TYPES.SENT
: TRANSACTION_TYPES.INCOMING,
};
}
}
Expand Down
Loading