Skip to content

Commit

Permalink
Underbridge: Drop updated dApp connections feature flag, further Taho…
Browse files Browse the repository at this point in the history
… renames (#3595)

This PR does two things:
- Drops the `ENABLE_UPDATED_DAPP_CONNECTIONS` feature flag completely,
as well as all related code paths.
- Updates all remaining references to `tally` in the window provider to
say `taho` instead, except if they were part of a publicly-visible API.
In the latter case, adds a `taho` equivalent, so that we can phase
`tally` out at an unspecified later date.

Latest build:
[extension-builds-3595](https://github.com/tahowallet/extension/suites/15119822565/artifacts/863994512)
(as of Tue, 15 Aug 2023 20:01:43 GMT).
  • Loading branch information
Shadowfiend authored Aug 15, 2023
2 parents 4685cb3 + 268c076 commit 169c8ed
Show file tree
Hide file tree
Showing 24 changed files with 134 additions and 633 deletions.
1 change: 0 additions & 1 deletion .env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ SUPPORT_SWAP_QUOTE_REFRESH=false
SUPPORT_ACHIEVEMENTS_BANNER=false
SUPPORT_NFT_SEND=false
USE_MAINNET_FORK=false
ENABLE_UPDATED_DAPP_CONNECTIONS=true
2 changes: 0 additions & 2 deletions background/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export const RuntimeFlag = {
SUPPORT_SWAP_QUOTE_REFRESH: process.env.SUPPORT_SWAP_QUOTE_REFRESH === "true",
SUPPORT_CUSTOM_NETWORKS: process.env.SUPPORT_CUSTOM_NETWORKS === "true",
SUPPORT_CUSTOM_RPCS: process.env.SUPPORT_CUSTOM_RPCS === "true",
ENABLE_UPDATED_DAPP_CONNECTIONS:
process.env.ENABLE_UPDATED_DAPP_CONNECTIONS === "true",
} as const

type BuildTimeFlagType = keyof typeof BuildTimeFlag
Expand Down
6 changes: 3 additions & 3 deletions background/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ import {
REDUX_STATE_VERSION,
} from "./redux-slices/migrations"
import { PermissionMap } from "./services/provider-bridge/utils"
import { TALLY_INTERNAL_ORIGIN } from "./services/internal-ethereum-provider/constants"
import { TAHO_INTERNAL_ORIGIN } from "./services/internal-ethereum-provider/constants"
import {
ActivityDetail,
addActivity,
Expand Down Expand Up @@ -750,7 +750,7 @@ export default class Main extends BaseService<never> {
address: accounts[0].address,
network:
await this.internalEthereumProviderService.getCurrentOrDefaultNetworkForOrigin(
TALLY_INTERNAL_ORIGIN
TAHO_INTERNAL_ORIGIN
),
})
)
Expand Down Expand Up @@ -1410,7 +1410,7 @@ export default class Main extends BaseService<never> {
this.internalEthereumProviderService.routeSafeRPCRequest(
"wallet_switchEthereumChain",
[{ chainId: network.chainID }],
TALLY_INTERNAL_ORIGIN
TAHO_INTERNAL_ORIGIN
)
this.chainService.pollBlockPricesForNetwork(network.chainID)
this.store.dispatch(clearCustomGas())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// eslint-disable-next-line import/prefer-default-export
export const TALLY_INTERNAL_ORIGIN = "@tally-internal"
export const TAHO_INTERNAL_ORIGIN = "@tally-internal"
4 changes: 2 additions & 2 deletions background/services/internal-ethereum-provider/db.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Dexie from "dexie"
import { ETHEREUM } from "../../constants"
import { EVMNetwork } from "../../networks"
import { TALLY_INTERNAL_ORIGIN } from "./constants"
import { TAHO_INTERNAL_ORIGIN } from "./constants"

type NetworkForOrigin = {
origin: string
Expand Down Expand Up @@ -42,7 +42,7 @@ export class InternalEthereumProviderDatabase extends Dexie {
this.on("populate", (tx) =>
tx.db
.table("currentNetwork")
.add({ origin: TALLY_INTERNAL_ORIGIN, network: ETHEREUM })
.add({ origin: TAHO_INTERNAL_ORIGIN, network: ETHEREUM })
)
}

Expand Down
8 changes: 4 additions & 4 deletions background/services/internal-ethereum-provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
parseSigningData,
} from "../../utils/signing"
import { getOrCreateDB, InternalEthereumProviderDatabase } from "./db"
import { TALLY_INTERNAL_ORIGIN } from "./constants"
import { TAHO_INTERNAL_ORIGIN } from "./constants"
import { ROOTSTOCK } from "../../constants"
import {
EnrichedEVMTransactionRequest,
Expand Down Expand Up @@ -145,7 +145,7 @@ export default class InternalEthereumProviderService extends BaseService<Events>
result: await this.routeSafeRPCRequest(
event.request.method,
event.request.params,
TALLY_INTERNAL_ORIGIN
TAHO_INTERNAL_ORIGIN
),
}
logger.debug("internal response:", response)
Expand Down Expand Up @@ -372,7 +372,7 @@ export default class InternalEthereumProviderService extends BaseService<Events>

private async getCurrentInternalNetwork(): Promise<EVMNetwork> {
return this.db.getCurrentNetworkForOrigin(
TALLY_INTERNAL_ORIGIN
TAHO_INTERNAL_ORIGIN
) as Promise<EVMNetwork>
}

Expand All @@ -398,7 +398,7 @@ export default class InternalEthereumProviderService extends BaseService<Events>
origin: string
): Promise<SignedTransaction> {
const annotation =
origin === TALLY_INTERNAL_ORIGIN &&
origin === TAHO_INTERNAL_ORIGIN &&
"annotation" in transactionRequest &&
transactionRequest.annotation !== undefined
? // We use `as` here as we know it's from a trusted source.
Expand Down
8 changes: 4 additions & 4 deletions background/services/provider-bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
EIP1193Error,
RPCRequest,
EIP1193_ERROR_CODES,
isTallyConfigPayload,
isTahoConfigPayload,
} from "@tallyho/provider-bridge-shared"
import { TransactionRequest as EthersTransactionRequest } from "@ethersproject/abstract-provider"
import BaseService from "../base"
Expand All @@ -35,7 +35,7 @@ import {
parseRPCRequestParams,
} from "./utils"
import { toHexChainID } from "../../networks"
import { TALLY_INTERNAL_ORIGIN } from "../internal-ethereum-provider/constants"
import { TAHO_INTERNAL_ORIGIN } from "../internal-ethereum-provider/constants"

type Events = ServiceLifecycleEvents & {
requestPermission: PermissionRequest
Expand Down Expand Up @@ -159,13 +159,13 @@ export default class ProviderBridgeService extends BaseService<Events> {
)

const originPermission = await this.checkPermission(origin, network.chainID)
if (origin === TALLY_INTERNAL_ORIGIN) {
if (origin === TAHO_INTERNAL_ORIGIN) {
// Explicitly disallow anyone who has managed to pretend to be the
// internal provider.
response.result = new EIP1193Error(
EIP1193_ERROR_CODES.unauthorized
).toJSON()
} else if (isTallyConfigPayload(event.request)) {
} else if (isTahoConfigPayload(event.request)) {
// let's start with the internal communication
response.id = "tallyHo"
response.result = {
Expand Down
10 changes: 9 additions & 1 deletion env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,29 @@ type WalletProvider = BaseWalletProvider & {

type TahoProvider = BaseWalletProvider & {
isTally: true
isTaho: true
tahoSetAsDefault: boolean
send: (method: string, params: unknown[]) => void | Promise<unknown>
}

type WindowEthereum = WalletProvider & {
isMetaMask?: boolean
tallySetAsDefault?: boolean
tahoSetAsDefault?: boolean
isTally?: boolean
isTaho?: boolean
autoRefreshOnNetworkChange?: boolean
}
interface Window {
walletRouter?: {
currentProvider: WalletProvider
providers: WalletProvider[]
shouldSetTallyForCurrentProvider: (
shouldSetTally: boolean,
shouldSetTaho: boolean,
shouldReload?: boolean
) => void
shouldSetTahoForCurrentProvider: (
shouldSetTaho: boolean,
shouldReload?: boolean
) => void
routeToNewNonTahoDefault: (request: unknown) => Promise<unknown>
Expand All @@ -68,6 +75,7 @@ interface Window {
addProvider: (newProvider: WalletProvider) => void
}
tally?: TahoProvider
taho?: TahoProvider
ethereum?: WindowEthereum
oldEthereum?: WindowEthereum
}
Expand Down
16 changes: 7 additions & 9 deletions provider-bridge-shared/runtime-typechecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
RPCRequest,
WindowResponseEvent,
PortResponseEvent,
TallyConfigPayload,
TallyInternalCommunication,
TallyAccountPayload,
TahoConfigPayload,
TahoInternalCommunication,
TahoAccountPayload,
} from "./types"

export function getType(arg: unknown): string {
Expand Down Expand Up @@ -80,19 +80,17 @@ export function isAllowedQueryParamPage(
return Object.values<unknown>(AllowedQueryParamPage).includes(url)
}

export function isTallyInternalCommunication(
export function isTahoInternalCommunication(
arg: unknown
): arg is TallyInternalCommunication {
): arg is TahoInternalCommunication {
return isObject(arg) && arg.id === "tallyHo"
}

export function isTallyConfigPayload(arg: unknown): arg is TallyConfigPayload {
export function isTahoConfigPayload(arg: unknown): arg is TahoConfigPayload {
return isObject(arg) && arg.method === "tally_getConfig"
}

export function isTallyAccountPayload(
arg: unknown
): arg is TallyAccountPayload {
export function isTahoAccountPayload(arg: unknown): arg is TahoAccountPayload {
return (
isObject(arg) &&
arg.method === "tally_accountChanged" &&
Expand Down
8 changes: 4 additions & 4 deletions provider-bridge-shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ export type PortTransport = {

export type EthersSendCallback = (error: unknown, response: unknown) => void

export type TallyInternalCommunication = {
export type TahoInternalCommunication = {
id: "tallyHo"
result: TallyConfigPayload | TallyAccountPayload
result: TahoConfigPayload | TahoAccountPayload
}

export type TallyConfigPayload = {
export type TahoConfigPayload = {
method: "tally_getConfig"
defaultWallet: boolean
chainId?: string
shouldReload?: boolean
[prop: string]: unknown
}

export type TallyAccountPayload = {
export type TahoAccountPayload = {
method: "tally_accountChanged"
address: Array<string>
}
30 changes: 21 additions & 9 deletions src/window-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ Object.defineProperty(window, "tally", {
writable: false,
configurable: false,
})
Object.defineProperty(window, "taho", {
value: tahoWindowProvider,
writable: false,
configurable: false,
})

if (!window.walletRouter) {
const existingProviders =
Expand All @@ -202,21 +207,28 @@ if (!window.walletRouter) {

Object.defineProperty(window, "walletRouter", {
value: {
currentProvider: window.tally,
currentProvider: window.taho,
lastInjectedProvider: wrappedLastInjectedProvider,
tallyProvider: window.tally,
tallyProvider: window.taho,
tahoProvider: window.taho,
providers: dedupedProviders,
shouldSetTallyForCurrentProvider(
shouldSetTally: boolean,
shouldReload = false
) {
if (shouldSetTally && this.currentProvider !== this.tallyProvider) {
this.currentProvider = this.tallyProvider
this.shouldSetTahoForCurrentProvider(shouldSetTally, shouldReload)
},
shouldSetTahoForCurrentProvider(
shouldSetTaho: boolean,
shouldReload = false
) {
if (shouldSetTaho && this.currentProvider !== this.tahoProvider) {
this.currentProvider = this.tahoProvider
} else if (
!shouldSetTally &&
this.currentProvider === this.tallyProvider
!shouldSetTaho &&
this.currentProvider === this.tahoProvider
) {
this.currentProvider = this.lastInjectedProvider ?? this.tallyProvider
this.currentProvider = this.lastInjectedProvider ?? this.tahoProvider
}

// Make the new "current provider" first in the provider list. This
Expand Down Expand Up @@ -249,7 +261,7 @@ if (!window.walletRouter) {
// where Taho is default, then default is turned off, but no other
// provider is installed, so that we don't try to reroute back to Taho
// as the only other provider.
if (this.currentProvider === this.tallyProvider) {
if (this.currentProvider === this.tahoProvider) {
return Promise.reject(
new Error("Only the Taho provider is installed.")
)
Expand All @@ -267,7 +279,7 @@ if (!window.walletRouter) {
},
reemitTahoEvent(event: string | symbol, ...args: unknown[]): boolean {
if (
this.currentProvider !== this.tallyProvider ||
this.currentProvider !== this.tahoProvider ||
this.lastInjectedProvider === undefined ||
this.currentProvider === this.lastInjectedProvider
) {
Expand Down
15 changes: 0 additions & 15 deletions ui/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -797,15 +797,6 @@
},
"reviewSwap": "Review swap"
},
"switchWallet": {
"title": "Want to use another wallet instead?",
"tooltip": "You are seeing this because Taho is set as default wallet, you can change this option in the main menu.",
"confirmSwitchWallet": "Yes, switch wallet",
"notDefaultWalletMessage": "Taho not Default",
"disableWalletExplainer": "We disabled Taho as the default wallet for you. You can always re-enable it from Menu ☰ at any time.",
"useTahoAsDefaultPrompt": "Use Taho as default wallet",
"closeButton": "Close window"
},
"toggle": {
"collapse": "Collapse",
"viewAll": "View all"
Expand Down Expand Up @@ -921,12 +912,6 @@
}
},
"dAppConnect": {
"switchWallet": {
"title": "Taho not Default",
"descFirstPart": "We disabled Taho as default wallet for you. You can always enable it back from Settings",
"descSecondPart": "at any time.",
"toggleTitle": "Use Taho as default wallet"
},
"defaultConnectionPopover": {
"title": "Connecting with Taho",
"activeWallet": "Your active wallet is Taho.",
Expand Down
Loading

0 comments on commit 169c8ed

Please sign in to comment.