Skip to content

Commit

Permalink
Merge branch 'main' into release-0.17.2
Browse files Browse the repository at this point in the history
  • Loading branch information
SJQuality authored Oct 17, 2022
2 parents 0876ba8 + bcabb8f commit 8118a7e
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 97 deletions.
14 changes: 8 additions & 6 deletions background/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1224,12 +1224,14 @@ export default class Main extends BaseService<never> {
"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,
})
}
)
)
}
)
Expand Down
148 changes: 90 additions & 58 deletions background/redux-slices/selectors/accountsSelectors.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -333,7 +333,70 @@ const getTotalBalance = (
.reduce((total, assetBalance) => total + assetBalance, 0)
}

export const selectCurrentNetworkAccountTotalsByCategory = createSelector(
function getNetworkAccountTotalsByCategory(
accounts: AccountState,
assets: AssetsState,
accountSignersByAddress: ReturnType<typeof selectAccountSignersByAddress>,
keyringsByAddresses: ReturnType<typeof selectKeyringsByAddresses>,
sourcesByAddress: ReturnType<typeof selectSourcesByAddress>,
mainCurrencySymbol: ReturnType<typeof selectMainCurrencySymbol>,
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<CategorizedAccountTotals>(
(seenTotalsByType, accountTotal) => ({
...seenTotalsByType,
[accountTotal.accountType]: [
...(seenTotalsByType[accountTotal.accountType] ?? []),
accountTotal,
],
}),
{}
)
}

const selectNetworkAccountTotalsByCategoryResolver = createSelector(
getAccountState,
getAssetsState,
selectAccountSignersByAddress,
Expand All @@ -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<CategorizedAccountTotals>(
(seenTotalsByType, accountTotal) => ({
...seenTotalsByType,
[accountTotal.accountType]: [
...(seenTotalsByType[accountTotal.accountType] ?? []),
accountTotal,
],
}),
{}
)
return selectNetworkAccountTotalsByCategory(currentNetwork)
}
)

Expand Down Expand Up @@ -471,7 +501,9 @@ export const getAccountTotal = (
accountAddressOnNetwork: AddressOnNetwork
): AccountTotal | undefined =>
findAccountTotal(
selectCurrentNetworkAccountTotalsByCategory(state),
selectNetworkAccountTotalsByCategoryResolver(state)(
accountAddressOnNetwork.network
),
accountAddressOnNetwork
)

Expand Down
2 changes: 2 additions & 0 deletions provider-bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 (
<div className="top_bar_wrap standard_width">
Expand Down
7 changes: 1 addition & 6 deletions ui/pages/PersonalSign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { ReactElement, useState } from "react"
import {
getAccountTotal,
selectCurrentAccountSigner,
selectCurrentNetwork,
} from "@tallyho/tally-background/redux-slices/selectors"
import {
rejectDataSignature,
Expand Down Expand Up @@ -31,17 +30,13 @@ const TITLE: Record<SigningDataType, string> = {
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
})
Expand Down
7 changes: 1 addition & 6 deletions ui/pages/SignData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
})
Expand Down
8 changes: 2 additions & 6 deletions ui/pages/SignTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 8118a7e

Please sign in to comment.