Skip to content

Commit 4f00593

Browse files
refactor: remove smartpay provider (#12280)
* refactor: remove smartpay provider * fix: linter * chore: remove type * fix: linter * fix: bugfix * chore: type check * fix: eslint * fix: linter --------- Co-authored-by: nuanyang233 <[email protected]> Co-authored-by: Jack-Works <[email protected]>
1 parent c9ad011 commit 4f00593

File tree

168 files changed

+383
-8356
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+383
-8356
lines changed

packages/icons/general/SmartPay.svg

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/icons/icon-generated-as-jsx.js

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/icons/icon-generated-as-url.js

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/mask/background/services/backup/restore.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { getBackupSummary, normalizeBackup, type BackupSummary } from '@masknet/backup-format'
22
import { restoreNormalizedBackup } from './internal_restore.js'
33
import { Result } from 'ts-results-es'
4-
import { SmartPayBundler, SmartPayOwner } from '@masknet/web3-providers'
5-
import { compact, sum } from 'lodash-es'
4+
import { sum } from 'lodash-es'
65
import { bytesToHex, privateToPublic, publicToAddress } from '@ethereumjs/util'
76
import { fromBase64URL } from '@masknet/shared-base'
87

@@ -23,11 +22,9 @@ export async function generateBackupSummary(raw: string) {
2322

2423
const wallets = backup.wallets.map((x) => x.address)
2524

26-
const chainId = await SmartPayBundler.getSupportedChainId()
27-
const accounts = await SmartPayOwner.getAccountsByOwners(chainId, [...compact(personas), ...wallets])
2825
return {
2926
...getBackupSummary(backup),
30-
countOfWallets: sum([accounts.filter((x) => x.deployed).length, wallets.length]),
27+
countOfWallets: sum([wallets.length]),
3128
}
3229
})
3330
}

packages/mask/background/services/wallet/database/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import type { EIP2255Permission } from '@masknet/sdk'
33
import type { LegacyWalletRecord } from '@masknet/shared-base'
44

55
export interface RequestPayload extends JsonRpcPayload {
6-
owner?: string
76
identifier?: string
8-
paymentToken?: string
9-
allowMaskAsGas?: boolean
107
}
118
interface UnconfirmedRequestChunkRecord {
129
/** A chunk of unconfirmed rpc requests */

packages/mask/background/services/wallet/services/send.ts

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import type { JsonRpcPayload } from 'web3-core-helpers'
22
import { ECKeyIdentifier, type SignType } from '@masknet/shared-base'
3-
import { EVMRequestReadonly, SmartPayAccount, EVMWeb3Readonly } from '@masknet/web3-providers'
3+
import { EVMRequestReadonly, EVMWeb3Readonly } from '@masknet/web3-providers'
44
import {
55
ChainId,
66
createJsonRpcResponse,
77
ErrorEditor,
88
EthereumMethodType,
9-
isValidAddress,
109
PayloadEditor,
1110
type TransactionOptions,
1211
Signer,
@@ -18,7 +17,7 @@ import { signWithPersona } from '../../identity/persona/sign.js'
1817
* The entrance of all RPC requests to MaskWallet.
1918
*/
2019
export async function send(payload: JsonRpcPayload, options?: TransactionOptions) {
21-
const { owner, paymentToken, providerURL } = options ?? {}
20+
const { owner, providerURL } = options ?? {}
2221
const {
2322
pid = 0,
2423
from,
@@ -40,22 +39,13 @@ export async function send(payload: JsonRpcPayload, options?: TransactionOptions
4039
if (!signableConfig) throw new Error('No transaction to be sent.')
4140

4241
try {
43-
if (owner && paymentToken) {
44-
return createJsonRpcResponse(
45-
pid,
46-
await SmartPayAccount.sendTransaction(chainId, owner, signableConfig, signer, {
47-
paymentToken,
48-
}),
49-
)
50-
} else {
51-
return createJsonRpcResponse(
52-
pid,
53-
await EVMWeb3Readonly.sendSignedTransaction(await signer.signTransaction(signableConfig), {
54-
chainId,
55-
providerURL,
56-
}),
57-
)
58-
}
42+
return createJsonRpcResponse(
43+
pid,
44+
await EVMWeb3Readonly.sendSignedTransaction(await signer.signTransaction(signableConfig), {
45+
chainId,
46+
providerURL,
47+
}),
48+
)
5949
} catch (error) {
6050
throw ErrorEditor.from(error, null, 'Failed to send transaction.').error
6151
}
@@ -81,14 +71,6 @@ export async function send(payload: JsonRpcPayload, options?: TransactionOptions
8171
} catch (error) {
8272
throw ErrorEditor.from(error, null, 'Failed to sign transaction.').error
8373
}
84-
case EthereumMethodType.MASK_DEPLOY:
85-
try {
86-
const [owner] = payload.params as [string]
87-
if (!isValidAddress(owner)) throw new Error('Invalid sender address.')
88-
return createJsonRpcResponse(pid, await SmartPayAccount.deploy(chainId, owner, signer))
89-
} catch (error) {
90-
throw ErrorEditor.from(error, null, 'Failed to deploy.').error
91-
}
9274
default:
9375
try {
9476
const result = await EVMRequestReadonly.request(

packages/mask/dashboard/pages/CreateMaskWallet/CreateMnemonic/index.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import { useAsync, useAsyncFn } from 'react-use'
44
import urlcat from 'urlcat'
55
import { toBlob } from 'html-to-image'
66
import { Icons } from '@masknet/icons'
7-
import { timeout } from '@masknet/kit'
87
import { CopyButton } from '@masknet/shared'
98
import { DashboardRoutes } from '@masknet/shared-base'
109
import { makeStyles } from '@masknet/theme'
1110
import { useWallets } from '@masknet/web3-hooks-base'
12-
import { MaskWalletProvider, EVMWeb3 } from '@masknet/web3-providers'
13-
import { generateNewWalletName, isSameAddress } from '@masknet/web3-shared-base'
11+
import { EVMWeb3 } from '@masknet/web3-providers'
12+
import { generateNewWalletName } from '@masknet/web3-shared-base'
1413
import { ProviderType } from '@masknet/web3-shared-evm'
1514
import { Telemetry } from '@masknet/web3-telemetry'
1615
import { EventID, EventType } from '@masknet/web3-telemetry/types'
@@ -166,17 +165,6 @@ const useStyles = makeStyles()((theme) => ({
166165
},
167166
}))
168167

169-
async function pollResult(address: string) {
170-
const subscription = MaskWalletProvider.subscription.wallets
171-
if (subscription.getCurrentValue().find((x) => isSameAddress(x.address, address))) return
172-
const { promise, resolve } = Promise.withResolvers()
173-
const unsubscribe = subscription.subscribe(() => {
174-
if (!subscription.getCurrentValue().find((x) => isSameAddress(x.address, address))) return
175-
resolve(true)
176-
})
177-
return timeout(promise, 10_000, 'It takes too long to create a wallet. You might try again.').finally(unsubscribe)
178-
}
179-
180168
export const Component = memo(function CreateMnemonic() {
181169
const location = useLocation()
182170
const navigate = useNavigate()
@@ -216,7 +204,6 @@ export const Component = memo(function CreateMnemonic() {
216204
const result = await handlePasswordAndWallets(location.state?.password, location.state?.isReset)
217205
if (!result) return
218206
const address = await Services.Wallet.createWalletFromMnemonicWords(walletName, words.join(' '))
219-
await pollResult(address)
220207
await EVMWeb3.connect({
221208
silent: true,
222209
providerType: ProviderType.MaskWallet,

packages/mask/dashboard/pages/SignUp/steps/PersonaRecovery.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { useState } from 'react'
22
import { useLocation, useNavigate } from 'react-router-dom'
33
import { useCustomSnackbar } from '@masknet/theme'
4-
import { DashboardRoutes, EMPTY_LIST, type ECKeyIdentifier, type EC_Public_JsonWebKey } from '@masknet/shared-base'
4+
import { DashboardRoutes, type ECKeyIdentifier, type EC_Public_JsonWebKey } from '@masknet/shared-base'
55
import Services from '#services'
66
import { PersonaNameUI } from './PersonaNameUI.js'
77
import { useCreatePersonaByPrivateKey, useCreatePersonaV2 } from '../../../hooks/useCreatePersonaV2.js'
88
import { delay } from '@masknet/kit'
99
import { useAsync, useAsyncFn } from 'react-use'
10-
import { SmartPayBundler, SmartPayOwner } from '@masknet/web3-providers'
1110
import urlcat from 'urlcat'
1211
import { Trans } from '@lingui/react/macro'
1312

@@ -53,10 +52,6 @@ export function Component() {
5352
return
5453
}
5554

56-
const chainId = await SmartPayBundler.getSupportedChainId()
57-
const accounts =
58-
result?.address ? await SmartPayOwner.getAccountsByOwner(chainId, result.address) : EMPTY_LIST
59-
6055
let identifier: ECKeyIdentifier
6156
if (state.mnemonic) {
6257
identifier = await createPersona(state.mnemonic.join(' '), personaName)
@@ -73,7 +68,7 @@ export function Component() {
7368
await delay(300)
7469
navigate(
7570
urlcat(DashboardRoutes.SignUpPersonaOnboarding, {
76-
count: accounts.filter((x) => x.deployed).length,
71+
count: 0,
7772
}),
7873
{ replace: true },
7974
)

packages/mask/popups/components/GasSettingMenu/index.tsx

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ import { BigNumber } from 'bignumber.js'
44
import { Box } from '@mui/system'
55
import { Button, Typography, useTheme } from '@mui/material'
66
import { Icons } from '@masknet/icons'
7-
import { FormattedBalance, FormattedCurrency, useGasCurrencyMenu } from '@masknet/shared'
7+
import { FormattedBalance, FormattedCurrency } from '@masknet/shared'
88
import { NetworkPluginID } from '@masknet/shared-base'
99
import {
1010
useChainContext,
1111
useChainIdSupport,
12-
useFungibleToken,
13-
useFungibleTokenPrice,
1412
useGasLimitRange,
1513
useGasOptions,
14+
useNativeToken,
1615
useNativeTokenAddress,
16+
useNativeTokenPrice,
1717
} from '@masknet/web3-hooks-base'
1818
import { GasOptionType, ZERO, formatBalance, formatCurrency, scale10, toFixed } from '@masknet/web3-shared-base'
1919
import { type GasConfig, type ChainId, formatWeiToEther } from '@masknet/web3-shared-evm'
2020
import { useGasOptionsMenu } from '../../hooks/index.js'
21-
import { useGasRatio } from '../../hooks/useGasRatio.js'
2221
import { Trans } from '@lingui/react/macro'
2322

2423
interface GasSettingMenuProps {
@@ -27,28 +26,19 @@ interface GasSettingMenuProps {
2726
defaultChainId?: ChainId
2827
disable?: boolean
2928
onChange?: (config: GasConfig) => void
30-
onPaymentTokenChange?: (paymentToken: string) => void
31-
/** Payment token address */
32-
paymentToken?: string
33-
owner?: string
34-
allowMaskAsGas?: boolean
3529
}
3630

3731
export const GasSettingMenu = memo<GasSettingMenuProps>(function GasSettingMenu({
3832
defaultGasLimit,
3933
defaultChainId,
4034
defaultGasConfig,
41-
paymentToken,
4235
disable,
43-
allowMaskAsGas,
44-
owner,
4536
onChange,
46-
onPaymentTokenChange,
4737
}) {
4838
const theme = useTheme()
4939

5040
const { chainId } = useChainContext<NetworkPluginID.PLUGIN_EVM>({ chainId: defaultChainId })
51-
const gasRatio = useGasRatio(paymentToken)
41+
5242
const [gasConfig = defaultGasConfig, setGasConfig] = useState<GasConfig | undefined>()
5343
const [, chainDefaultGasLimit] = useGasLimitRange(NetworkPluginID.PLUGIN_EVM, { chainId })
5444
const gasLimit = gasConfig?.gas || defaultGasLimit || chainDefaultGasLimit
@@ -66,13 +56,7 @@ export const GasSettingMenu = memo<GasSettingMenuProps>(function GasSettingMenu(
6656
[onChange],
6757
)
6858

69-
const [menu, openMenu] = useGasOptionsMenu(gasLimit, !disable ? handleChange : noop, paymentToken)
70-
71-
const [paymentTokenMenu, openPaymentTokenMenu] = useGasCurrencyMenu(
72-
NetworkPluginID.PLUGIN_EVM,
73-
onPaymentTokenChange ?? noop,
74-
paymentToken,
75-
)
59+
const [menu, openMenu] = useGasOptionsMenu(gasLimit, !disable ? handleChange : noop)
7660

7761
const { data: gasOptions } = useGasOptions(NetworkPluginID.PLUGIN_EVM, { chainId })
7862

@@ -102,17 +86,9 @@ export const GasSettingMenu = memo<GasSettingMenuProps>(function GasSettingMenu(
10286

10387
const nativeTokenAddress = useNativeTokenAddress(NetworkPluginID.PLUGIN_EVM, { chainId })
10488

105-
const { data: token } = useFungibleToken(
106-
NetworkPluginID.PLUGIN_EVM,
107-
paymentToken ? paymentToken : nativeTokenAddress,
108-
undefined,
109-
{ chainId },
110-
)
89+
const { data: token } = useNativeToken(NetworkPluginID.PLUGIN_EVM, { chainId })
11190

112-
const { data: tokenPrice } = useFungibleTokenPrice(
113-
NetworkPluginID.PLUGIN_EVM,
114-
paymentToken ? paymentToken : nativeTokenAddress,
115-
)
91+
const { data: tokenPrice } = useNativeTokenPrice(NetworkPluginID.PLUGIN_EVM, { chainId })
11692

11793
const gasOptionName = (() => {
11894
switch (gasOptionType) {
@@ -132,9 +108,8 @@ export const GasSettingMenu = memo<GasSettingMenuProps>(function GasSettingMenu(
132108
const maxGasPrice = 'maxFeePerGas' in gasConfig ? gasConfig.maxFeePerGas : gasConfig.gasPrice
133109
if (!maxGasPrice) return ZERO
134110
const maxPriceUsed = new BigNumber(maxGasPrice).times(gasLimit)
135-
if (!gasRatio) return toFixed(maxPriceUsed, 0)
136-
return toFixed(maxPriceUsed.multipliedBy(gasRatio), 0)
137-
}, [gasConfig, gasLimit, gasRatio])
111+
return toFixed(maxPriceUsed, 0)
112+
}, [gasConfig, gasLimit])
138113

139114
return (
140115
<Box display="flex" alignItems="center">
@@ -178,12 +153,6 @@ export const GasSettingMenu = memo<GasSettingMenuProps>(function GasSettingMenu(
178153
<Icons.Candle size={12} />
179154
</Button>
180155
: null}
181-
{owner && allowMaskAsGas ?
182-
<>
183-
<Icons.ArrowDrop size={20} sx={{ ml: 0.5, cursor: 'pointer' }} onClick={openPaymentTokenMenu} />
184-
{paymentTokenMenu}
185-
</>
186-
: null}
187156
{menu}
188157
</Box>
189158
)

packages/mask/popups/components/NFTAvatarPicker/CollectionList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const CollectionList = memo<CollectionListProps>(function CollectionList(
8282
{tokens.length ?
8383
tokens.map((x, index) => {
8484
const isSelected = isSameNFT(pluginID, x, selected)
85-
const disabled = (selected && !isSelected) || wallet?.owner
85+
const disabled = selected && !isSelected
8686
return (
8787
<CollectibleCard
8888
className={cx(classes.item, disabled ? classes.disabled : undefined)}

0 commit comments

Comments
 (0)