Skip to content

Commit

Permalink
[Release] Hotfix 2.21.0 => 2.21.1 (patch) (#9852)
Browse files Browse the repository at this point in the history
* chore: bump version 2.21.1

* fix: incorrect transaction record (#9853)

* fix: computed payment token (#9860)

* fix: sns adaptor context (#9858)

* chore: update lock file

* refactor: code style

* refactor: naming

* refactor: remove bridge

* refactor: remove logs

* refactor: send should be readonly

* fix: adjust chain id resolver (#9851)

* fix: debank cache time (#9863)

* fix: set debank cache time to short

* fix: add new duration type

* fix: remove deploy transaction after confirm transaction successfully (#9862)

---------

Co-authored-by: nuanyang233 <nuanyang233@gmail.com>
  • Loading branch information
guanbinrui and nuanyang233 committed Jun 18, 2023
1 parent 565a70f commit 99ad92d
Show file tree
Hide file tree
Showing 27 changed files with 162 additions and 267 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"yarn": ">=999.0.0",
"npm": ">=999.0.0"
},
"version": "2.21.0",
"version": "2.21.1",
"private": true,
"license": "AGPL-3.0-or-later",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Mask Network",
"version": "2.21.0",
"version": "2.21.1",
"manifest_version": 2,
"permissions": ["storage", "downloads", "webNavigation", "activeTab"],
"optional_permissions": ["<all_urls>", "notifications", "clipboardRead"],
Expand Down
4 changes: 2 additions & 2 deletions packages/mask/src/plugins/Savings/SNSAdaptor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useState } from 'react'
import { Trans } from 'react-i18next'
import type { Plugin } from '@masknet/plugin-infra'
import { ApplicationEntry } from '@masknet/shared'
import { Icons } from '@masknet/icons'
import { Trans } from 'react-i18next'
import { useState } from 'react'
import { base } from '../base.js'
import { SavingsDialog } from './SavingsDialog.js'

Expand Down
10 changes: 6 additions & 4 deletions packages/mask/src/plugins/Wallet/services/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isNil } from 'lodash-es'
import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers'
import { defer } from '@masknet/kit'
import { ECKeyIdentifier, type SignType } from '@masknet/shared-base'
import { SmartPayAccount, Web3 } from '@masknet/web3-providers'
import { SmartPayAccount, Web3Readonly } from '@masknet/web3-providers'
import {
ChainId,
createJsonRpcResponse,
Expand All @@ -15,8 +15,8 @@ import {
} from '@masknet/web3-shared-evm'
import { WalletRPC } from '../messages.js'
import { signWithWallet } from './wallet/index.js'
import { openPopupWindow, removePopupWindow } from '../../../../background/services/helper/index.js'
import { signWithPersona } from '../../../../background/services/identity/index.js'
import { openPopupWindow, removePopupWindow } from '../../../../background/services/helper/index.js'

/**
* Send to built-in RPC endpoints.
Expand Down Expand Up @@ -62,7 +62,9 @@ async function internalSend(
null,
createJsonRpcResponse(
pid,
await Web3.sendSignedTransaction(await signer.signTransaction(signableConfig), { chainId }),
await Web3Readonly.sendSignedTransaction(await signer.signTransaction(signableConfig), {
chainId,
}),
),
)
}
Expand Down Expand Up @@ -111,7 +113,7 @@ async function internalSend(
callback(new Error('Method not implemented.'))
break
default:
await Web3.getWeb3Provider({ chainId }).send(payload, callback)
await Web3Readonly.getWeb3Provider({ chainId }).send(payload, callback)
break
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-infra/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,13 @@ export namespace Plugin.Shared {

/** Send request to native API, for a risky request will be added into the waiting queue. */
send(payload: JsonRpcPayload, options?: TransactionOptions): Promise<JsonRpcResponse>

/** Confirm a request */
confirmRequest(
payload: JsonRpcPayload,
options?: { disableClose?: boolean; popupsWindow?: boolean },
): Promise<JsonRpcResponse | void>

/** Reject a request */
rejectRequest(payload: JsonRpcPayload): Promise<void>

Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/EVM/src/UI/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
Transaction,
TransactionParameter,
} from '@masknet/web3-shared-evm'
import { SharedUIPluginContext, Web3State } from '@masknet/web3-providers'
import { SharedPluginContext, Web3State } from '@masknet/web3-providers'
import { base } from '../../base.js'

const dashboard: Plugin.Dashboard.Definition<
Expand All @@ -20,7 +20,7 @@ const dashboard: Plugin.Dashboard.Definition<
> = {
...base,
async init(signal, context) {
SharedUIPluginContext.setup(context)
SharedPluginContext.setup(context)

const state = await Web3State.create(context)

Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/EVM/src/UI/SNSAdaptor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
Transaction,
TransactionParameter,
} from '@masknet/web3-shared-evm'
import { SharedUIPluginContext, Web3State } from '@masknet/web3-providers'
import { SharedPluginContext, Web3State } from '@masknet/web3-providers'
import { base } from '../../base.js'

const sns: Plugin.SNSAdaptor.Definition<
Expand All @@ -20,7 +20,7 @@ const sns: Plugin.SNSAdaptor.Definition<
> = {
...base,
async init(signal, context) {
SharedUIPluginContext.setup(context)
SharedPluginContext.setup(context)

const state = await Web3State.create(context)

Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/Flow/src/UI/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
Transaction,
TransactionParameter,
} from '@masknet/web3-shared-flow'
import { FlowWeb3State, SharedUIPluginContext } from '@masknet/web3-providers'
import { FlowWeb3State, SharedPluginContext } from '@masknet/web3-providers'
import { base } from '../../base.js'

const dashboard: Plugin.Dashboard.Definition<
Expand All @@ -20,7 +20,7 @@ const dashboard: Plugin.Dashboard.Definition<
> = {
...base,
async init(signal, context) {
SharedUIPluginContext.setup(context)
SharedPluginContext.setup(context)

const state = await FlowWeb3State.create(context)

Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/Flow/src/UI/SNSAdaptor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
Transaction,
TransactionParameter,
} from '@masknet/web3-shared-flow'
import { FlowWeb3State, SharedUIPluginContext } from '@masknet/web3-providers'
import { FlowWeb3State, SharedPluginContext } from '@masknet/web3-providers'
import { base } from '../../base.js'

const sns: Plugin.SNSAdaptor.Definition<
Expand All @@ -20,7 +20,7 @@ const sns: Plugin.SNSAdaptor.Definition<
> = {
...base,
async init(signal, context) {
SharedUIPluginContext.setup(context)
SharedPluginContext.setup(context)

const state = await FlowWeb3State.create(context)

Expand Down
6 changes: 4 additions & 2 deletions packages/plugins/SmartPay/src/hooks/useDeploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function useDeploy(
const snackbarKeyRef = useRef<SnackbarKey>()
const t = useI18N()

const { TransactionWatcher } = useWeb3State()
const { TransactionWatcher, Transaction } = useWeb3State()
const { signWithPersona, hasPaymentPassword, openPopupWindow } = useSNSAdaptorContext()
const lastRecognizedIdentity = useLastRecognizedIdentity()
const { chainId } = useChainContext<NetworkPluginID.PLUGIN_EVM>()
Expand Down Expand Up @@ -130,7 +130,8 @@ export function useDeploy(

const deployResult = await Web3.confirmTransaction(deployHash, options)
if (!deployResult?.status) return

await Transaction?.removeTransaction?.(chainId, '', hash)
await Transaction?.removeTransaction?.(chainId, '', deployHash)
onSuccess?.()

return deployResult.transactionHash
Expand Down Expand Up @@ -172,5 +173,6 @@ export function useDeploy(
nonce,
onSuccess,
TransactionWatcher,
Transaction,
])
}
4 changes: 2 additions & 2 deletions packages/plugins/Solana/src/UI/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
Transaction,
TransactionParameter,
} from '@masknet/web3-shared-solana'
import { SharedUIPluginContext, SolanaWeb3State } from '@masknet/web3-providers'
import { SharedPluginContext, SolanaWeb3State } from '@masknet/web3-providers'
import { base } from '../../base.js'

const dashboard: Plugin.Dashboard.Definition<
Expand All @@ -20,7 +20,7 @@ const dashboard: Plugin.Dashboard.Definition<
> = {
...base,
async init(signal, context) {
SharedUIPluginContext.setup(context)
SharedPluginContext.setup(context)

const state = await SolanaWeb3State.create(context)

Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/Solana/src/UI/SNSAdaptor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
Transaction,
TransactionParameter,
} from '@masknet/web3-shared-solana'
import { SharedUIPluginContext, SolanaWeb3State } from '@masknet/web3-providers'
import { SharedPluginContext, SolanaWeb3State } from '@masknet/web3-providers'
import { base } from '../../base.js'

const sns: Plugin.SNSAdaptor.Definition<
Expand All @@ -20,7 +20,7 @@ const sns: Plugin.SNSAdaptor.Definition<
> = {
...base,
async init(signal, context) {
SharedUIPluginContext.setup(context)
SharedPluginContext.setup(context)

const state = await SolanaWeb3State.create(context)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class DeBankFungibleTokenAPI implements FungibleTokenAPI.Provider<ChainId
{
enableSquash: true,
enableCache: true,
cacheDuration: Duration.LONG,
cacheDuration: Duration.MINIMAL,
},
)

Expand Down
13 changes: 13 additions & 0 deletions packages/web3-providers/src/PluginContext/apis/SharedContextAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Plugin } from '@masknet/plugin-infra'
import { ValueRefWithReady } from '@masknet/shared-base'
import { BaseContextAPI } from './BaseAPI.js'

type Context = Pick<Plugin.Shared.SharedUIContext, 'signWithPersona' | 'send'>

export const SharedContextRef = new ValueRefWithReady<Context>()

export class SharedContextAPI extends BaseContextAPI<Context> {
constructor() {
super(SharedContextRef)
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion packages/web3-providers/src/PluginContext/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './apis/SharedUIContextAPI.js'
export * from './apis/SharedContextAPI.js'
export * from './apis/SNSAdaptorContextAPI.js'
4 changes: 2 additions & 2 deletions packages/web3-providers/src/Storage/apis/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NextIDStorage } from '../storages/NextID.js'
import { RSS3Storage } from '../storages/RSS3.js'
import { FireflyStorage } from '../storages/Firefly.js'
import type { StorageAPI } from '../../entry-types.js'
import { SharedUIContextRef } from '../../PluginContext/index.js'
import { SharedContextRef } from '../../PluginContext/index.js'

export class Web3StorageAPI implements StorageAPI.Provider {
createKVStorage(namespace: string) {
Expand All @@ -21,6 +21,6 @@ export class Web3StorageAPI implements StorageAPI.Provider {

createNextIDStorage(proofIdentity: string, platform: NextIDPlatform, signerOrPublicKey: string | ECKeyIdentifier) {
if (!platform || !signerOrPublicKey) throw new Error('Instantiation parameter error.')
return new NextIDStorage(proofIdentity, platform, signerOrPublicKey, SharedUIContextRef.value.signWithPersona)
return new NextIDStorage(proofIdentity, platform, signerOrPublicKey, SharedContextRef.value.signWithPersona)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { RequestArguments } from 'web3-core'
import { ProviderType, ChainId } from '@masknet/web3-shared-evm'
import { type BaseContractWalletProvider, Providers } from '@masknet/web3-providers'
import { SharedUIContextRef } from '../../../PluginContext/index.js'
import { Web3StateRef } from '../apis/Web3StateAPI.js'
import { ConnectionContext } from '../libs/ConnectionContext.js'
import type { ConnectionOptions } from '../types/index.js'
Expand Down Expand Up @@ -29,9 +28,5 @@ const initializer = {
}

export function createContext(requestArguments: RequestArguments, options?: ConnectionOptions) {
return new ConnectionContext(requestArguments, options, {
...initializer,
mask_send: SharedUIContextRef.value.send,
mask_signWithPersona: SharedUIContextRef.value.signWithPersona,
})
return new ConnectionContext(requestArguments, options, initializer)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ContractReadonlyAPI } from '../apis/ContractReadonlyAPI.js'
import type { ConnectionContext } from '../libs/ConnectionContext.js'
import { Providers } from '../providers/index.js'
import type { BaseContractWalletProvider } from '../providers/BaseContractWallet.js'
import { SharedContextRef } from '../../../PluginContext/index.js'
import type { BundlerAPI, AbstractAccountAPI, FunderAPI } from '../../../entry-types.js'

export class ContractWallet implements Middleware<ConnectionContext> {
Expand All @@ -39,8 +40,7 @@ export class ContractWallet implements Middleware<ConnectionContext> {
return new Signer(
context.identifier,
async <T>(type: SignType, message: T, identifier?: ECKeyIdentifier) => {
if (!context.bridge.signWithPersona) return ''
return context.bridge.signWithPersona(type, message, identifier, true)
return SharedContextRef.value.signWithPersona(type, message, identifier, true)
},
)
if (context.owner)
Expand Down
16 changes: 12 additions & 4 deletions packages/web3-providers/src/Web3/EVM/interceptors/Popups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
ProviderType,
} from '@masknet/web3-shared-evm'
import { ExtensionSite, getSiteType, isEnhanceableSiteType } from '@masknet/shared-base'
import { isGreaterThan, toFixed } from '@masknet/web3-shared-base'
import { isGreaterThan, isZero, toFixed } from '@masknet/web3-shared-base'
import { SharedContextRef } from '../../../PluginContext/index.js'
import { SmartPayBundlerAPI } from '../../../SmartPay/index.js'
import { ConnectionReadonlyAPI } from '../apis/ConnectionReadonlyAPI.js'
import { ContractReadonlyAPI } from '../apis/ContractReadonlyAPI.js'
Expand All @@ -30,6 +31,7 @@ export class Popups implements Middleware<ConnectionContext> {
private Bundler = new SmartPayBundlerAPI()

private async getPaymentToken(context: ConnectionContext) {
const maskAddress = getMaskTokenAddress(context.chainId)
try {
const smartPayChainId = await this.Bundler.getSupportedChainId()
if (context.chainId !== smartPayChainId || !context.owner) return DEFAULT_PAYMENT_TOKEN_STATE
Expand All @@ -46,8 +48,6 @@ export class Popups implements Middleware<ConnectionContext> {

if (!signableConfig?.maxFeePerGas) return DEFAULT_PAYMENT_TOKEN_STATE

const maskAddress = getMaskTokenAddress(context.chainId)

const gas = await this.Web3.estimateTransaction?.(signableConfig, undefined, {
chainId: context.chainId,
account: context.account,
Expand Down Expand Up @@ -82,6 +82,14 @@ export class Popups implements Middleware<ConnectionContext> {
paymentToken: context.paymentToken ?? !availableBalanceTooLow ? maskAddress : undefined,
}
} catch (error) {
const nativeBalance = await this.Web3.getNativeTokenBalance({
account: context.account,
chainId: context.chainId,
})

if (isZero(nativeBalance))
return { allowMaskAsGas: true, paymentToken: context.paymentToken ?? maskAddress }

return {
allowMaskAsGas: false,
paymentToken: undefined,
Expand All @@ -107,7 +115,7 @@ export class Popups implements Middleware<ConnectionContext> {
isUndefined,
)

const response = await context.bridge.send?.(context.request, options)
const response = await SharedContextRef.value.send(context.request, options)
const editor = ErrorEditor.from(null, response)

if (editor.presence) {
Expand Down

0 comments on commit 99ad92d

Please sign in to comment.