Skip to content

Commit

Permalink
feat: support deploy contract transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Feb 28, 2024
1 parent d3c6730 commit b7f40a4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/mask/entry-sdk/README.md
Expand Up @@ -78,7 +78,7 @@ The list is built from what [MetaMask supported](https://docs.metamask.io/wallet

- [x] wallet_getPermissions
- [x] wallet_requestPermissions
- [ ] wallet_revokePermissions
- [ ] wallet_revokePermissions (not in EIP-2255)

## [EIP-712: Typed structured data hashing and signing](https://eips.ethereum.org/EIPS/eip-712)

Expand Down
5 changes: 1 addition & 4 deletions packages/mask/entry-sdk/bridge/eth.ts
Expand Up @@ -137,13 +137,10 @@ const methods = {
account: options.from,
silent: false,
readonly: false,
// this is strange. why I cannot pass options via request.params?
overrides: options as any,
})
return p.request({
method: EthereumMethodType.ETH_SEND_TRANSACTION,
// this options here actually get ignored!
params: options as any,
params: [options],
})
},
async [EthereumMethodType.ETH_SEND_RAW_TRANSACTION](
Expand Down
29 changes: 16 additions & 13 deletions packages/mask/popups/components/TransactionPreview/index.tsx
Expand Up @@ -70,7 +70,7 @@ const useStyles = makeStyles()((theme) => ({
}))

interface TransactionPreviewProps {
transaction?: TransactionDetail
transaction: TransactionDetail
paymentToken?: string
onConfigChange: (config: GasConfig) => void
onPaymentTokenChange: (paymentToken: string) => void
Expand All @@ -88,7 +88,7 @@ export const TransactionPreview = memo<TransactionPreviewProps>(function Transac
const contacts = useContacts()
const Utils = useWeb3Utils()
const { title, to, tokenAddress, amount } = useMemo(() => {
const type = transaction?.formattedTransaction?.type
const type = transaction.formattedTransaction?.type

if (!type) return {}

Expand All @@ -113,6 +113,10 @@ export const TransactionPreview = memo<TransactionPreviewProps>(function Transac
}

case TransactionDescriptorType.DEPLOYMENT:
console.log(transaction)
return {
title: t.wallet_transfer_deploy(),
}
case TransactionDescriptorType.RETRY:
case TransactionDescriptorType.CANCEL:
throw new Error('Method not implemented.')
Expand All @@ -121,7 +125,7 @@ export const TransactionPreview = memo<TransactionPreviewProps>(function Transac
}
}, [transaction])

const tokenId = transaction?.formattedTransaction?.popup?.tokenId
const tokenId = transaction.formattedTransaction?.popup?.tokenId

const { data: metadata } = useNonFungibleAsset(
NetworkPluginID.PLUGIN_EVM,
Expand All @@ -145,7 +149,6 @@ export const TransactionPreview = memo<TransactionPreviewProps>(function Transac
: '0'

const initConfig = useMemo(() => {
if (!transaction?.computedPayload) return
if (isSupport1559) {
if (transaction.computedPayload.maxFeePerGas && transaction.computedPayload.maxPriorityFeePerGas)
return {
Expand All @@ -162,16 +165,14 @@ export const TransactionPreview = memo<TransactionPreviewProps>(function Transac
gasPrice: transaction.computedPayload.gasPrice,
gasOptionType: transaction.gasOptionType,
}
}, [transaction?.computedPayload, transaction?.gasOptionType, isSupport1559])
}, [transaction.computedPayload, transaction.gasOptionType, isSupport1559])

const receiver = useMemo(() => {
if (domain) return Utils.formatDomainName(domain)
const target = contacts.find((x) => isSameAddress(x.address, to))
return target?.name
}, [domain, to, contacts])

if (!transaction) return

return (
<Box>
<Box className={classes.info}>
Expand All @@ -181,12 +182,14 @@ export const TransactionPreview = memo<TransactionPreviewProps>(function Transac
<Typography className={classes.title}>{receiver}</Typography>
: null}
</Box>
<Box mt={2} display="flex" columnGap={0.5} alignItems="center">
<Typography className={classes.addressTitle}>{t.to()}:</Typography>
<Typography fontSize={11} fontWeight={700} lineHeight="16px">
{to}
</Typography>
</Box>
{to ?
<Box mt={2} display="flex" columnGap={0.5} alignItems="center">
<Typography className={classes.addressTitle}>{t.to()}:</Typography>
<Typography fontSize={11} fontWeight={700} lineHeight="16px">
{to}
</Typography>
</Box>
: null}
</Box>

<Box display="flex" justifyContent="space-between" alignItems="center" mt={3}>
Expand Down
14 changes: 12 additions & 2 deletions packages/mask/popups/pages/Wallet/Interaction/index.tsx
Expand Up @@ -49,7 +49,12 @@ import { LoadingPlaceholder } from '../../../components/LoadingPlaceholder/index
import { UnlockERC20Token } from '../../../components/UnlockERC20Token/index.js'
import { UnlockERC721Token } from '../../../components/UnlockERC721Token/index.js'
import type { JsonRpcResponse } from 'web3-core-helpers'
import { type ReasonableMessage, parseEIP4361Message, type EIP4361Message } from '@masknet/web3-shared-base'
import {
type ReasonableMessage,
parseEIP4361Message,
type EIP4361Message,
TransactionDescriptorType,
} from '@masknet/web3-shared-base'
import { useQueryClient, useSuspenseQuery } from '@tanstack/react-query'
import { useInteractionWalletContext } from './InteractionContext.js'

Expand Down Expand Up @@ -342,9 +347,12 @@ const Interaction = memo((props: InteractionProps) => {
showSnackbar(
<Typography textAlign="center" width="275px">
{t.popups_wallet_rpc_error()}
<br />
{String((error as any).message)}
</Typography>,
{
variant: 'error',
autoHideDuration: 5000,
},
)
}
Expand Down Expand Up @@ -435,7 +443,9 @@ const InteractionItem = memo((props: InteractionItemProps) => {

const t = useMaskSharedTrans()
const { classes, cx } = useStyles()
const [expand, setExpand] = useState(false)
const [expand, setExpand] = useState(
transaction.formattedTransaction?.type === TransactionDescriptorType.DEPLOYMENT,
)

const [approvedAmount, setApproveAmount] = useState('')
const [gasConfig, setGasConfig] = useState<GasConfig | undefined>()
Expand Down
1 change: 1 addition & 0 deletions packages/mask/shared-ui/locales/en-US.json
Expand Up @@ -292,6 +292,7 @@
"wallet_transfer_receiving_account": "Receiving Account",
"wallet_transfer_to_address": "To Address",
"wallet_transfer_send": "Send",
"wallet_transfer_deploy": "Deploy Contract",
"wallet_transfer_placeholder": "Ens or Address(0x)",
"wallet_transfer_title": "Transfer",
"wallet_transfer_my_wallets_title": "My Wallets",
Expand Down

0 comments on commit b7f40a4

Please sign in to comment.