preinit blockchain events

pull/5370/head
ioedeveloper 3 years ago committed by yann300
parent 8dd8ab4259
commit 87aea627b6
  1. 30
      apps/remix-ide/src/app/udapp/run-tab.js
  2. 59
      libs/remix-ui/run-tab/src/lib/actions/index.ts
  3. 41
      libs/remix-ui/run-tab/src/lib/components/account.tsx
  4. 2
      libs/remix-ui/run-tab/src/lib/components/settingsUI.tsx
  5. 2
      libs/remix-ui/run-tab/src/lib/reducers/runTab.ts
  6. 2
      libs/remix-ui/run-tab/src/lib/run-tab.tsx
  7. 16
      libs/remix-ui/run-tab/src/lib/types/index.ts

@ -4,10 +4,7 @@ import { RunTabUI } from '@remix-ui/run-tab'
import { ViewPlugin } from '@remixproject/engine-web'
import * as packageJson from '../../../../../package.json'
const $ = require('jquery')
const yo = require('yo-yo')
const ethJSUtil = require('ethereumjs-util')
const Web3 = require('web3')
const EventManager = require('../../lib/events')
const Card = require('../ui/card')
@ -220,33 +217,6 @@ export class RunTab extends ViewPlugin {
render () {
return this.el
this.udappUI = new UniversalDAppUI(this.blockchain, this.logCallback)
this.blockchain.resetAndInit(this.config, {
getAddress: (cb) => {
cb(null, $('#txorigin').val())
},
getValue: (cb) => {
try {
const number = document.querySelector('#value').value
const select = document.getElementById('unit')
const index = select.selectedIndex
const selectedUnit = select.querySelectorAll('option')[index].dataset.unit
let unit = 'ether' // default
if (['ether', 'finney', 'gwei', 'wei'].indexOf(selectedUnit) >= 0) {
unit = selectedUnit
}
cb(null, Web3.utils.toWei(number, unit))
} catch (e) {
cb(e)
}
},
getGasLimit: (cb) => {
try {
cb(null, '0x' + new ethJSUtil.BN($('#gasLimit').val(), 10).toString(16))
} catch (e) {
cb(e.message)
}
}
})
this.renderInstanceContainer()
this.renderSettings()
this.renderDropdown(this.udappUI, this.fileManager, this.compilersArtefacts, this.config, this.editor, this.logCallback)

@ -1,5 +1,7 @@
import { shortenAddress } from '@remix-ui/helper'
import React from 'react'
import { shortenAddress } from '@remix-ui/helper'
import * as ethJSUtil from 'ethereumjs-util'
import Web3 from 'web3'
import { fetchAccountsListFailed, fetchAccountsListRequest, fetchAccountsListSuccess } from './payload'
let plugin, dispatch: React.Dispatch<any>
@ -9,11 +11,10 @@ export const initSettingsTab = (udapp) => async (reducerDispatch: React.Dispatch
plugin = udapp
dispatch = reducerDispatch
setupEvents()
setInterval(() => {
fillAccountsList()
}, 1000)
fillAccountsList()
}
}
@ -28,20 +29,48 @@ const setupEvents = () => {
updateAccountBalances()
})
const updateAccountBalances = () => {
// const accounts = $(this.el.querySelector('#txorigin')).children('option')
plugin.blockchain.resetAndInit(plugin.config, {
getAddress: (cb) => {
cb(null, $('#txorigin').val())
},
getValue: (cb) => {
try {
const number = document.querySelector('#value').value
const select = document.getElementById('unit')
const index = select.selectedIndex
const selectedUnit = select.querySelectorAll('option')[index].dataset.unit
let unit = 'ether' // default
if (['ether', 'finney', 'gwei', 'wei'].indexOf(selectedUnit) >= 0) {
unit = selectedUnit
}
cb(null, Web3.utils.toWei(number, unit))
} catch (e) {
cb(e)
}
},
getGasLimit: (cb) => {
try {
cb(null, '0x' + new ethJSUtil.BN($('#gasLimit').val(), 10).toString(16))
} catch (e) {
cb(e.message)
}
}
})
}
// accounts.each((index, account) => {
// plugin.blockchain.getBalanceInEther(account.value, (err, balance) => {
// if (err) return
// const updated = shortenAddress(account.value, balance)
const updateAccountBalances = () => {
// const accounts = $(this.el.querySelector('#txorigin')).children('option')
// if (updated !== account.innerText) { // check if the balance has been updated and update UI accordingly.
// account.innerText = updated
// }
// })
// })
}
// accounts.each((index, account) => {
// plugin.blockchain.getBalanceInEther(account.value, (err, balance) => {
// if (err) return
// const updated = shortenAddress(account.value, balance)
// if (updated !== account.innerText) { // check if the balance has been updated and update UI accordingly.
// account.innerText = updated
// }
// })
// })
}
const fillAccountsList = async () => {

@ -1,42 +1,17 @@
// eslint-disable-next-line no-use-before-define
import React, { useRef, useState } from 'react'
import React, { useEffect, useRef, useState } from 'react'
import { CopyToClipboard } from '@remix-ui/clipboard'
import { AccountProps } from '../types'
export function AccountUI (props: AccountProps) {
const accounts = Object.keys(props.accounts.loadedAccounts)
const [selectedAccount, setSelectedAccount] = useState<string>('')
const plusBtn = useRef(null)
const plusTitle = useRef(null)
// // TODO: unclear what's the goal of accountListCallId, feels like it can be simplified
// async fillAccountsList () {
// this.accountListCallId++
// const callid = this.accountListCallId
// const txOrigin = this.el.querySelector('#txorigin')
// let accounts = []
// try {
// accounts = await this.blockchain.getAccounts()
// } catch (e) {
// addTooltip(`Cannot get account list: ${e}`)
// }
// if (!accounts) accounts = []
// if (this.accountListCallId > callid) return
// this.accountListCallId++
// for (const loadedaddress in this.loadedAccounts) {
// if (accounts.indexOf(loadedaddress) === -1) {
// txOrigin.removeChild(txOrigin.querySelector('option[value="' + loadedaddress + '"]'))
// delete this.loadedAccounts[loadedaddress]
// }
// }
// for (const i in accounts) {
// const address = accounts[i]
// if (!this.loadedAccounts[address]) {
// txOrigin.appendChild(yo`<option value="${address}" >${address}</option>`)
// this.loadedAccounts[address] = 1
// }
// }
// txOrigin.setAttribute('value', accounts[0])
// }
useEffect(() => {
if (!selectedAccount && accounts.length > 0) setSelectedAccount(accounts[0])
}, [accounts, selectedAccount])
const updatePlusButton = () => {
// enable/disable + button
@ -140,7 +115,11 @@ export function AccountUI (props: AccountProps) {
</span>
</label>
<div className="udapp_account">
<select id="txorigin" data-id="runTabSelectAccount" name="txorigin" className="form-control udapp_select custom-select pr-4" value={selectedAccount} onChange={(e) => { setSelectedAccount(e.target.value) }}></select>
<select id="txorigin" data-id="runTabSelectAccount" name="txorigin" className="form-control udapp_select custom-select pr-4" value={selectedAccount} onChange={(e) => { setSelectedAccount(e.target.value) }}>
{
Object.keys(props.accounts.loadedAccounts).map((value) => <option value={value}>{ value }</option>)
}
</select>
<div style={{ marginLeft: -5 }}><CopyToClipboard content={selectedAccount} direction='top' /></div>
<i id="remixRunSignMsg" data-id="settingsRemixRunSignMsg" className="mx-1 fas fa-edit udapp_icon" aria-hidden="true" onClick={signMessage} title="Sign a message using this account key"></i>
</div>

@ -129,7 +129,7 @@ export function SettingsUI (props: SettingsProps) {
<div className="udapp_settings">
<EnvironmentUI updateExEnv={props.updateExEnv} />
<NetworkUI />
<AccountUI selectExEnv={props.selectExEnv} />
<AccountUI selectExEnv={props.selectExEnv} accounts={props.accounts} />
<GasPriceUI />
<ValueUI />
</div>

@ -8,7 +8,7 @@ export interface RunTabState {
loadedAccounts: Record<string, any>,
isRequesting: boolean,
isSuccessful: boolean,
error: null
error: string
}
}

@ -24,7 +24,7 @@ export function RunTabUI (props: RunTabProps) {
return (
<div className="udapp_runTabView run-tab" id="runTabView" data-id="runTabView">
<div className="list-group list-group-flush">
<SettingsUI selectExEnv={selectExEnv} updateExEnv={updateExEnv} />
<SettingsUI selectExEnv={selectExEnv} updateExEnv={updateExEnv} accounts={runTab.accounts} />
<ContractDropdownUI exEnvironment={selectExEnv} />
<RecorderUI />
<InstanceContainerUI />

@ -4,7 +4,13 @@ export interface RunTabProps {
export interface SettingsProps {
selectExEnv: string,
updateExEnv: (env: string) => void
updateExEnv: (env: string) => void,
accounts: {
loadedAccounts: Record<string, any>,
isRequesting: boolean,
isSuccessful: boolean,
error: string
}
}
export interface EnvironmentProps {
@ -16,7 +22,13 @@ export interface NetworkProps {
}
export interface AccountProps {
selectExEnv: string
selectExEnv: string,
accounts: {
loadedAccounts: Record<string, any>,
isRequesting: boolean,
isSuccessful: boolean,
error: string
}
}
export interface GasPriceProps {

Loading…
Cancel
Save