Show modal for proxy deployment confirmation and provided type definition for Openzeppelin apis

pull/2260/head
David Disu 2 years ago
parent cf4fecbca9
commit d6b711a7f5
  1. 20
      apps/remix-ide/src/blockchain/blockchain.js
  2. 14
      libs/remix-core-plugin/src/lib/openzeppelin-proxy.ts
  3. 6
      libs/remix-ui/helper/src/lib/helper-components.tsx
  4. 1
      libs/remix-ui/run-tab/src/index.ts

@ -12,6 +12,7 @@ import NodeProvider from './providers/node.js'
import { execution, EventManager, helpers } from '@remix-project/remix-lib' import { execution, EventManager, helpers } from '@remix-project/remix-lib'
import { etherScanLink } from './helper' import { etherScanLink } from './helper'
import { logBuilder } from "@remix-ui/helper" import { logBuilder } from "@remix-ui/helper"
import { cancelProxyMsg } from '@remix-ui/helper'
const { txFormat, txExecution, typeConversion, txListener: Txlistener, TxRunner, TxRunnerWeb3, txHelper } = execution const { txFormat, txExecution, typeConversion, txListener: Txlistener, TxRunner, TxRunnerWeb3, txHelper } = execution
const { txResultHelper: resultToRemixTx } = helpers const { txResultHelper: resultToRemixTx } = helpers
const packageJson = require('../../../../package.json') const packageJson = require('../../../../package.json')
@ -139,6 +140,25 @@ export class Blockchain extends Plugin {
} }
async deployProxy (proxyData, implementationContractObject) { async deployProxy (proxyData, implementationContractObject) {
const proxyModal = {
id: 'confirmProxyDeployment',
title: 'ERC1967',
message: 'Confirm proxy deployment?',
modalType: 'modal',
okLabel: 'OK',
cancelLabel: 'Cancel',
okFn: () => {
this.runProxyTx(proxyData, implementationContractObject)
},
cancelFn: () => {
this.call('notification', 'toast', cancelProxyMsg())
},
hideFn: () => null
}
this.call('notification', 'modal', proxyModal)
}
async runProxyTx (proxyData, implementationContractObject) {
const args = { useCall: false, data: proxyData } const args = { useCall: false, data: proxyData }
const confirmationCb = (network, tx, gasEstimation, continueTxExecution, cancelCb) => { const confirmationCb = (network, tx, gasEstimation, continueTxExecution, cancelCb) => {
// continue using original authorization given by user // continue using original authorization given by user

@ -1,3 +1,4 @@
import { DeployOption } from '@remix-ui/run-tab';
import { Plugin } from '@remixproject/engine'; import { Plugin } from '@remixproject/engine';
import { ContractABI, ContractAST } from '../types/contract'; import { ContractABI, ContractAST } from '../types/contract';
import { UUPS, UUPSABI, UUPSBytecode, UUPSfunAbi } from './constants/uups'; import { UUPS, UUPSABI, UUPSBytecode, UUPSfunAbi } from './constants/uups';
@ -16,7 +17,7 @@ export class OpenZeppelinProxy extends Plugin {
this.blockchain = blockchain this.blockchain = blockchain
} }
async isConcerned(ast: ContractAST = {} as ContractAST) { async isConcerned(ast: ContractAST = {} as ContractAST): Promise<boolean> {
// check in the AST if it's an upgradable contract // check in the AST if it's an upgradable contract
if (ast.nodes && ast.nodes.find(node => node.absolutePath && node.absolutePath.includes(UUPS))) { if (ast.nodes && ast.nodes.find(node => node.absolutePath && node.absolutePath.includes(UUPS))) {
this.kind = 'UUPS' this.kind = 'UUPS'
@ -28,10 +29,10 @@ export class OpenZeppelinProxy extends Plugin {
return false return false
} }
async getDeployOptions (contracts: ContractABI) { async getDeployOptions (contracts: ContractABI): Promise<{ [name: string]: DeployOption }> {
const inputs = {}
if (this.kind === 'UUPS') { if (this.kind === 'UUPS') {
const inputs = {}
Object.keys(contracts).map(name => { Object.keys(contracts).map(name => {
const abi = contracts[name].abi const abi = contracts[name].abi
const initializeInput = abi.find(node => node.name === 'initialize') const initializeInput = abi.find(node => node.name === 'initialize')
@ -43,11 +44,8 @@ export class OpenZeppelinProxy extends Plugin {
} }
} }
}) })
if (Object.keys(inputs).length > 0) {
this.kind = 'UUPS'
return inputs
}
} }
return inputs
} }
async execute(implAddress: string, args: string | string [] = '', initializeABI, implementationContractObject) { async execute(implAddress: string, args: string | string [] = '', initializeABI, implementationContractObject) {

@ -88,3 +88,9 @@ export const recursivePasteToastMsg = () => (
export const logBuilder = (msg: string) => { export const logBuilder = (msg: string) => {
return <pre>{msg}</pre> return <pre>{msg}</pre>
} }
export const cancelProxyMsg = () => (
<div>
<b>Proxy deployment cancelled.</b>
</div>
)

@ -1 +1,2 @@
export * from './lib/run-tab' export * from './lib/run-tab'
export * from './lib/types'

Loading…
Cancel
Save