diff --git a/background/main.ts b/background/main.ts index ba35977197..658fe9e983 100644 --- a/background/main.ts +++ b/background/main.ts @@ -1224,12 +1224,14 @@ export default class Main extends BaseService { "denyOrRevokePermission", async (permission) => { await Promise.all( - [ETHEREUM, POLYGON, OPTIMISM, GOERLI].map(async (network) => { - await this.providerBridgeService.denyOrRevokePermission({ - ...permission, - chainID: network.chainID, - }) - }) + [ETHEREUM, POLYGON, OPTIMISM, GOERLI, ARBITRUM_ONE].map( + async (network) => { + await this.providerBridgeService.denyOrRevokePermission({ + ...permission, + chainID: network.chainID, + }) + } + ) ) } ) diff --git a/background/redux-slices/selectors/accountsSelectors.ts b/background/redux-slices/selectors/accountsSelectors.ts index a52189db13..7d7038eb3a 100644 --- a/background/redux-slices/selectors/accountsSelectors.ts +++ b/background/redux-slices/selectors/accountsSelectors.ts @@ -1,7 +1,7 @@ import { createSelector } from "@reduxjs/toolkit" import { selectHideDust } from "../ui" import { RootState } from ".." -import { AccountType, CompleteAssetAmount } from "../accounts" +import { AccountState, AccountType, CompleteAssetAmount } from "../accounts" import { AssetsState, selectAssetPricePoint } from "../assets" import { enrichAssetAmountWithDecimalValues, @@ -333,7 +333,70 @@ const getTotalBalance = ( .reduce((total, assetBalance) => total + assetBalance, 0) } -export const selectCurrentNetworkAccountTotalsByCategory = createSelector( +function getNetworkAccountTotalsByCategory( + accounts: AccountState, + assets: AssetsState, + accountSignersByAddress: ReturnType, + keyringsByAddresses: ReturnType, + sourcesByAddress: ReturnType, + mainCurrencySymbol: ReturnType, + network: EVMNetwork +): CategorizedAccountTotals { + return Object.entries(accounts.accountsData.evm[network.chainID] ?? {}) + .filter(([, accountData]) => typeof accountData !== "undefined") + .map(([address, accountData]): AccountTotal => { + const shortenedAddress = truncateAddress(address) + + const accountSigner = + accountSignersByAddress[address] ?? ReadOnlyAccountSigner + const keyringId = keyringsByAddresses[address]?.id + + const accountType = getAccountType( + address, + accountSigner, + sourcesByAddress + ) + + if (accountData === "loading") { + return { + address, + network, + shortenedAddress, + accountType, + keyringId, + accountSigner, + } + } + + return { + address, + network, + shortenedAddress, + accountType, + keyringId, + accountSigner, + name: accountData.ens.name ?? accountData.defaultName, + avatarURL: accountData.ens.avatarURL ?? accountData.defaultAvatar, + localizedTotalMainCurrencyAmount: formatCurrencyAmount( + mainCurrencySymbol, + getTotalBalance(accountData.balances, assets, mainCurrencySymbol), + desiredDecimals + ), + } + }) + .reduce( + (seenTotalsByType, accountTotal) => ({ + ...seenTotalsByType, + [accountTotal.accountType]: [ + ...(seenTotalsByType[accountTotal.accountType] ?? []), + accountTotal, + ], + }), + {} + ) +} + +const selectNetworkAccountTotalsByCategoryResolver = createSelector( getAccountState, getAssetsState, selectAccountSignersByAddress, @@ -347,63 +410,30 @@ export const selectCurrentNetworkAccountTotalsByCategory = createSelector( accountSignersByAddress, keyringsByAddresses, sourcesByAddress, - mainCurrencySymbol, + mainCurrencySymbol + ): ((network: EVMNetwork) => CategorizedAccountTotals) => { + return (network: EVMNetwork) => { + return getNetworkAccountTotalsByCategory( + accounts, + assets, + accountSignersByAddress, + keyringsByAddresses, + sourcesByAddress, + mainCurrencySymbol, + network + ) + } + } +) + +export const selectCurrentNetworkAccountTotalsByCategory = createSelector( + selectNetworkAccountTotalsByCategoryResolver, + selectCurrentNetwork, + ( + selectNetworkAccountTotalsByCategory, currentNetwork ): CategorizedAccountTotals => { - return Object.entries( - accounts.accountsData.evm[currentNetwork.chainID] ?? {} - ) - .filter(([, accountData]) => typeof accountData !== "undefined") - .map(([address, accountData]): AccountTotal => { - const shortenedAddress = truncateAddress(address) - - const accountSigner = - accountSignersByAddress[address] ?? ReadOnlyAccountSigner - const keyringId = keyringsByAddresses[address]?.id - - const accountType = getAccountType( - address, - accountSigner, - sourcesByAddress - ) - - if (accountData === "loading") { - return { - address, - network: currentNetwork, - shortenedAddress, - accountType, - keyringId, - accountSigner, - } - } - - return { - address, - network: currentNetwork, - shortenedAddress, - accountType, - keyringId, - accountSigner, - name: accountData.ens.name ?? accountData.defaultName, - avatarURL: accountData.ens.avatarURL ?? accountData.defaultAvatar, - localizedTotalMainCurrencyAmount: formatCurrencyAmount( - mainCurrencySymbol, - getTotalBalance(accountData.balances, assets, mainCurrencySymbol), - desiredDecimals - ), - } - }) - .reduce( - (seenTotalsByType, accountTotal) => ({ - ...seenTotalsByType, - [accountTotal.accountType]: [ - ...(seenTotalsByType[accountTotal.accountType] ?? []), - accountTotal, - ], - }), - {} - ) + return selectNetworkAccountTotalsByCategory(currentNetwork) } ) @@ -471,7 +501,9 @@ export const getAccountTotal = ( accountAddressOnNetwork: AddressOnNetwork ): AccountTotal | undefined => findAccountTotal( - selectCurrentNetworkAccountTotalsByCategory(state), + selectNetworkAccountTotalsByCategoryResolver(state)( + accountAddressOnNetwork.network + ), accountAddressOnNetwork ) diff --git a/provider-bridge/index.ts b/provider-bridge/index.ts index 6d148e202c..8997d10714 100644 --- a/provider-bridge/index.ts +++ b/provider-bridge/index.ts @@ -67,6 +67,8 @@ export function connectProviderBridge(): void { } export function injectTallyWindowProvider(): void { + if (document.contentType !== "text/html") return + try { const container = document.head || document.documentElement const scriptTag = document.createElement("script") diff --git a/ui/components/SignTransaction/SignTransactionNetworkAccountInfoTopBar.tsx b/ui/components/SignTransaction/SignTransactionNetworkAccountInfoTopBar.tsx index ea9d0d4a4b..72594dc9f4 100644 --- a/ui/components/SignTransaction/SignTransactionNetworkAccountInfoTopBar.tsx +++ b/ui/components/SignTransaction/SignTransactionNetworkAccountInfoTopBar.tsx @@ -1,13 +1,7 @@ import React, { ReactElement } from "react" import { AccountTotal } from "@tallyho/tally-background/redux-slices/selectors" -import { selectTransactionData } from "@tallyho/tally-background/redux-slices/selectors/transactionConstructionSelectors" -import { - selectSigningData, - selectTypedData, -} from "@tallyho/tally-background/redux-slices/signing" import { useTranslation } from "react-i18next" import SharedCurrentAccountInformation from "../Shared/SharedCurrentAccountInformation" -import { useBackgroundSelector } from "../../hooks" type Props = { accountTotal: AccountTotal @@ -17,15 +11,12 @@ export default function SignTransactionNetworkAccountInfoTopBar({ accountTotal, }: Props): ReactElement { const { t } = useTranslation() - const transactionData = useBackgroundSelector(selectTransactionData) - const signingData = useBackgroundSelector(selectSigningData) - const typedData = useBackgroundSelector(selectTypedData) - const { shortenedAddress, name, avatarURL } = accountTotal - - const networkName = - transactionData?.network.name ?? - signingData?.account.network.name ?? - typedData?.account.network.name + const { + network: { name: networkName }, + shortenedAddress, + name, + avatarURL, + } = accountTotal return (
diff --git a/ui/pages/PersonalSign.tsx b/ui/pages/PersonalSign.tsx index e33c4cc61e..51c0a2a1f8 100644 --- a/ui/pages/PersonalSign.tsx +++ b/ui/pages/PersonalSign.tsx @@ -2,7 +2,6 @@ import React, { ReactElement, useState } from "react" import { getAccountTotal, selectCurrentAccountSigner, - selectCurrentNetwork, } from "@tallyho/tally-background/redux-slices/selectors" import { rejectDataSignature, @@ -31,17 +30,13 @@ const TITLE: Record = { export default function PersonalSignData(): ReactElement { const { t } = useTranslation() const dispatch = useBackgroundDispatch() - const currentNetwork = useBackgroundSelector(selectCurrentNetwork) const signingDataRequest = useBackgroundSelector(selectSigningData) const history = useHistory() const signerAccountTotal = useBackgroundSelector((state) => { if (typeof signingDataRequest !== "undefined") { - return getAccountTotal(state, { - address: signingDataRequest.account.address, - network: currentNetwork, - }) + return getAccountTotal(state, signingDataRequest.account) } return undefined }) diff --git a/ui/pages/SignData.tsx b/ui/pages/SignData.tsx index 78889dbaee..7788320f4e 100644 --- a/ui/pages/SignData.tsx +++ b/ui/pages/SignData.tsx @@ -2,7 +2,6 @@ import { USE_UPDATED_SIGNING_UI } from "@tallyho/tally-background/features" import { getAccountTotal, selectCurrentAccountSigner, - selectCurrentNetwork, } from "@tallyho/tally-background/redux-slices/selectors" import { rejectDataSignature, @@ -32,16 +31,12 @@ export default function SignData(): ReactElement { }) const dispatch = useBackgroundDispatch() const typedDataRequest = useBackgroundSelector(selectTypedData) - const currentNetwork = useBackgroundSelector(selectCurrentNetwork) const history = useHistory() const signerAccountTotal = useBackgroundSelector((state) => { if (typeof typedDataRequest !== "undefined") { - return getAccountTotal(state, { - address: typedDataRequest.account.address, - network: currentNetwork, - }) + return getAccountTotal(state, typedDataRequest.account) } return undefined }) diff --git a/ui/pages/SignTransaction.tsx b/ui/pages/SignTransaction.tsx index 309237b69a..5e0e320d22 100644 --- a/ui/pages/SignTransaction.tsx +++ b/ui/pages/SignTransaction.tsx @@ -7,10 +7,7 @@ import { selectIsTransactionLoaded, selectTransactionData, } from "@tallyho/tally-background/redux-slices/selectors/transactionConstructionSelectors" -import { - getAccountTotal, - selectCurrentNetwork, -} from "@tallyho/tally-background/redux-slices/selectors" +import { getAccountTotal } from "@tallyho/tally-background/redux-slices/selectors" import { USE_UPDATED_SIGNING_UI } from "@tallyho/tally-background/features" import { ReadOnlyAccountSigner } from "@tallyho/tally-background/services/signing" import { @@ -28,7 +25,6 @@ import SignTransactionLoader from "../components/SignTransaction/SignTransaction export default function SignTransaction(): ReactElement { const dispatch = useBackgroundDispatch() const transactionDetails = useBackgroundSelector(selectTransactionData) - const currentNetwork = useBackgroundSelector(selectCurrentNetwork) const isTransactionDataReady = useBackgroundSelector( selectIsTransactionLoaded @@ -38,7 +34,7 @@ export default function SignTransaction(): ReactElement { if (typeof transactionDetails !== "undefined") { return getAccountTotal(state, { address: transactionDetails.from, - network: currentNetwork, + network: transactionDetails.network, }) } return undefined