Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Add network switching capabilities to Truffle Dashboard #5045

Closed
wants to merge 80 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
c2fc3e5
Added initial comments to code.
michaeljohnbennett Mar 21, 2022
3b48a9b
added wagmi library.
michaeljohnbennett Mar 22, 2022
c063777
Refactored code to use Wagmi hooks.
michaeljohnbennett Mar 22, 2022
8b2b516
Cleaning up package.json.
michaeljohnbennett Mar 22, 2022
9ea4fd6
Temporarily delay exiting Truffle
gnidan Mar 22, 2022
295f507
Add DebugMessage for browser console display
gnidan Mar 22, 2022
ecf34be
Define DashboardMessageBusClient for events system
gnidan Mar 22, 2022
ad17580
Add example handler for compile:start
gnidan Mar 22, 2022
a54b6bf
Reworking wagmi.
michaeljohnbennett Mar 23, 2022
390742f
Reworking wagmi.
michaeljohnbennett Mar 23, 2022
73c3355
events: handle message bus connection failures
benjamincburns Mar 23, 2022
ac2f6c4
Merge pull request #4923 from trufflesuite/dashboard/events
gnidan Mar 23, 2022
8de3637
added in disconnect feature.
michaeljohnbennett Mar 23, 2022
46a1ce0
Cleaned up console logs and temporary debugging.
dkillen Mar 24, 2022
b2ab7b9
Merge branch 'develop' of github.com:trufflesuite/truffle into dash
gnidan Mar 25, 2022
719ce6b
Merge branch 'develop' of github.com:trufflesuite/truffle into dash
gnidan Mar 29, 2022
f95ce78
Fix removed messageBus instantiation in bad merge
gnidan Mar 29, 2022
b4e247c
Merge branch 'develop' of github.com:trufflesuite/truffle into dash
gnidan Mar 30, 2022
3e1666c
Prettification setup done correctly for the dashboard code.
michaeljohnbennett Mar 31, 2022
15c4c9f
reverted button change.
michaeljohnbennett Mar 31, 2022
7f81709
Merge branch 'develop' of github.com:trufflesuite/truffle into dash
gnidan Mar 31, 2022
25dc062
Merge remote-tracking branch 'origin/dash' into feature/4838_walletco…
michaeljohnbennett Mar 31, 2022
cdc891b
Merge remote-tracking branch 'origin/dash' into feature/4838_walletco…
michaeljohnbennett Mar 31, 2022
7b48ae8
Merge pull request #4926 from trufflesuite/feature/4838_walletconnect…
michaeljohnbennett Apr 3, 2022
39075b6
Added in new button code.
michaeljohnbennett Apr 4, 2022
1452a92
Rejigging the imports to be file relative again to get it working on …
michaeljohnbennett Apr 4, 2022
04e5450
Fixing the case sensitive folder common to be Common.
michaeljohnbennett Apr 4, 2022
a31a4c0
Fixing to be all lowercase. Testing relative package imports.
michaeljohnbennett Apr 4, 2022
3dbed79
Merge branch 'develop' of github.com:trufflesuite/truffle into dash
gnidan Apr 4, 2022
039223b
Merge remote-tracking branch 'origin/dash' into feature/4971_new_butt…
michaeljohnbennett Apr 5, 2022
d30bee1
Merge pull request #4972 from trufflesuite/feature/4971_new_button_co…
michaeljohnbennett Apr 12, 2022
5dc000d
Merge branch 'develop' into dash
benjamincburns Apr 22, 2022
781a991
add initialize message type
MicaiahReid Mar 22, 2022
e77b2fa
add temp public chain data to truffle config
MicaiahReid Mar 22, 2022
96465a1
add more data to default public chains
MicaiahReid Mar 22, 2022
9b8c775
seed dev server and cli dashboard w/ initial data
MicaiahReid Mar 22, 2022
5ed6f83
add type for PublicChain to dashboard server
MicaiahReid Mar 22, 2022
66e1da3
use public chain in dashboard server class
MicaiahReid Mar 22, 2022
71bd823
emit new initialize event containing publicChains
MicaiahReid Mar 22, 2022
75362df
handle initialize event type in dashboard ui
MicaiahReid Mar 22, 2022
f0aec33
confirm message bus connection before emitting
MicaiahReid Mar 22, 2022
e10ac6a
reformat emitted data
MicaiahReid Mar 22, 2022
1d526b7
add ugly network switcher class
MicaiahReid Mar 23, 2022
27a802d
use new NetworkSwitcher react class
MicaiahReid Mar 23, 2022
cffe73b
Publish init request from UI to Server
MicaiahReid Mar 23, 2022
452605c
Rename variables
MicaiahReid Mar 23, 2022
0c14e93
rerender component when publicChains is updated
MicaiahReid Mar 23, 2022
06d511b
remove unneeded logging
MicaiahReid Mar 23, 2022
bb02040
comment, cleanup
MicaiahReid Mar 23, 2022
ad25875
remove bsc from config defaults
MicaiahReid Mar 23, 2022
bb5eb5d
remove dashboard `--rpc` option
MicaiahReid Mar 23, 2022
3ec0da1
make socket initialization RACE!
MicaiahReid Mar 23, 2022
2f6f6bb
remove ui publish logging. reorg
MicaiahReid Apr 22, 2022
f63bace
remove unnecessary error handling
MicaiahReid Mar 23, 2022
6b29c40
move default chains from config to run.js
MicaiahReid Mar 23, 2022
d5b99e9
hack at merging truf-config nets and publicChains
MicaiahReid Mar 23, 2022
ec8ba30
get chainId from RPC if ommitted in publicChains
MicaiahReid Mar 23, 2022
453db77
remove/fix logging
MicaiahReid Mar 23, 2022
75309c0
rename `publicChains` to `dashboardChains`
MicaiahReid Mar 24, 2022
915ac10
merge config'd + publicChains into dashboardChains
MicaiahReid Mar 24, 2022
a242383
rename `publicChains` to `dashboardChains`
MicaiahReid Mar 24, 2022
690ae99
switch to wagmi on new network selector
MicaiahReid Apr 22, 2022
6e63fad
combine imports
MicaiahReid Mar 24, 2022
057f2ac
fix typo
MicaiahReid Mar 24, 2022
02a5a88
rename mainnet to ethereum mainnet
MicaiahReid Mar 24, 2022
0204522
remove logging
MicaiahReid Mar 25, 2022
4470949
reorganize. add fundAccount method
MicaiahReid Mar 25, 2022
79f916b
remove fantom opera from publicChains
MicaiahReid Mar 25, 2022
fce33f5
rename var. remove isLocalChain
MicaiahReid Mar 25, 2022
a543529
add dropdown menu to header
leeftk Mar 23, 2022
3f062f9
fix merge conflict
leeftk Mar 25, 2022
a294dbc
fix merge conflict
leeftk Mar 25, 2022
e1f4300
add event target to select element
leeftk Mar 25, 2022
7eed095
remove logging and unused files
leeftk Mar 25, 2022
aaa038e
add formatting to files
leeftk Mar 25, 2022
562d2f2
attempt to set missing chainIds on UI init
MicaiahReid Apr 22, 2022
d25b4b4
warn on unfundable account
MicaiahReid Mar 25, 2022
16387b2
remove logging
MicaiahReid Mar 25, 2022
69670ef
remove chain from defaults
MicaiahReid Apr 12, 2022
8adc8c0
fix merging of public chain from tf-config to dashboardChains
MicaiahReid Apr 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ packages/**/node_modules
node_modules
yarn-error.log
.vscode
.idea
.DS_Store
Thumbs.db
$RECYCLE.BIN/
Expand Down
13 changes: 5 additions & 8 deletions packages/compile-solidity/test/test_supplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe("CompilerSupplier", function () {
let oldPragmaFloatSource; // ^0.4.15
let version4PragmaSource; // ^0.4.21
let version5PragmaSource; // ^0.5.0
let version6PragmaSource; // ^0.6.0
let version8PragmaSource; // ^0.8.0
let versionLatestPragmaSource; // Currently: ^0.8.0
let compileConfig;
Expand Down Expand Up @@ -46,10 +45,6 @@ describe("CompilerSupplier", function () {
path.join(__dirname, "./sources/v0.5.x/Version5Pragma.sol"),
"utf-8"
);
const version6Pragma = await fse.readFile(
path.join(__dirname, "./sources/v0.6.x/Version6Pragma.sol"),
"utf-8"
);
const version8Pragma = await fse.readFile(
path.join(__dirname, "./sources/v0.8.x/Version8Pragma.sol"),
"utf-8"
Expand All @@ -60,7 +55,6 @@ describe("CompilerSupplier", function () {
oldPragmaFloatSource = { "OldPragmaFloat.sol": oldPragmaFloat };
version4PragmaSource = { "NewPragma.sol": version4Pragma };
version5PragmaSource = { "Version5Pragma.sol": version5Pragma };
version6PragmaSource = { "Version6Pragma.sol": version6Pragma };
version8PragmaSource = { "Version8Pragma.sol": version8Pragma };
versionLatestPragmaSource = { "Version8Pragma.sol": versionLatestPragma }; //update when necessary
});
Expand Down Expand Up @@ -122,9 +116,12 @@ describe("CompilerSupplier", function () {
});

it("compiles w/ local path solc when options specify path", async function () {
// If multiple child projects have same solc version dependency, then yarn hoists the solc dependency
// If multiple child projects have same solc version dependency, then yarn hoists the solc dependency
// in the truffle root node_modules folder rather than the local package node_modules folder
const pathToSolc = path.join(__dirname, "../../../node_modules/solc/index.js");
const pathToSolc = path.join(
__dirname,
"../../../node_modules/solc/index.js"
);

options.compilers = {
solc: {
Expand Down
4 changes: 3 additions & 1 deletion packages/core/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ if (userWantsGeneralHelp) {

command
.run(inputArguments, options)
.then(returnStatus => process.exit(returnStatus))
.then(returnStatus => {
setInterval(() => process.exit(returnStatus), 1000);
})
.catch(error => {
if (error instanceof TaskError) {
analytics.send({
Expand Down
12 changes: 7 additions & 5 deletions packages/core/lib/commands/create/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const replaceContents = (filePath, find, replacement) => {
fs.writeFileSync(filePath, result, { encoding: "utf8" });
};

const toUnderscoreFromCamel = (string) => {
const toUnderscoreFromCamel = string => {
string = string.replace(/([A-Z])/g, function ($1) {
return "_" + $1.toLowerCase();
});
Expand All @@ -41,9 +41,10 @@ const toUnderscoreFromCamel = (string) => {

// getLicense return the license property value from Truffle config first and
// in case that the file doesn't exist it will fallback to package.json
const getLicense = (options) => {
const getLicense = options => {
try {
if ((license = require("@truffle/config").detect(options).license)) {
const license = require("@truffle/config").detect(options).license;
if (license) {
return license;
}
} catch (err) {
Expand All @@ -53,7 +54,7 @@ const getLicense = (options) => {
try {
return require(path.join(process.cwd(), "package.json")).license;
} catch {}
}
};

const Create = {
contract: async function (directory, name, options) {
Expand All @@ -67,7 +68,8 @@ const Create = {
await copy(from, to);

replaceContents(to, templates.contract.name, name);
if ((license = getLicense(options))) {
const license = (license = getLicense(options));
if (license) {
replaceContents(to, templates.contract.license, license);
}
},
Expand Down
98 changes: 96 additions & 2 deletions packages/core/lib/commands/dashboard/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,103 @@ module.exports = async function (options) {
const port = options.port || config.dashboard.port;
const host = options.host || config.dashboard.host;
const verbose = options.verbose || config.dashboard.verbose;
const rpc = true;
const publicChains = [
{
chainId: "0x1",
chainName: "ethereum mainnet",
nativeCurrency: {
symbol: "ETH",
decimals: 18
},
rpcUrls: ["https://mainnet.infura.io/v3/"],
blockExplorerUrls: ["https://etherscan.com"]
},
{
chainId: "0x3",
chainName: "ropsten",
nativeCurrency: {
symbol: "ETH",
decimals: 18
},
rpcUrls: ["https://ropsten.infura.io/v3/"],
blockExplorerUrls: ["https://ropsten.etherscan.com"]
},
{
chainId: "0x4",
chainName: "rinkeby",
nativeCurrency: {
symbol: "ETH",
decimals: 18
},
rpcUrls: ["https://rinkeby.infura.io/v3/"],
blockExplorerUrls: ["https://rinkeby.etherscan.com"]
},
{
chainId: "0x2A",
chainName: "kovan",
nativeCurrency: {
symbol: "ETH",
decimals: 18
},
rpcUrls: ["https://ropsten.infura.io/v3/"],
blockExplorerUrls: ["https://kovan.etherscan.com"]
},
{
chainId: "0x5",
chainName: "goerli",
nativeCurrency: {
symbol: "ETH",
decimals: 18
},
rpcUrls: ["https://goerli.infura.io/v3/"],
blockExplorerUrls: ["https://goerli.etherscan.com"]
}
];

const dashboardServerOptions = { port, host, verbose, rpc };
const mainnet = publicChains[0];
const mergedChains = [...publicChains];
if (config.networks) {
const chainNames = Object.keys(config.networks);

// filters out all truffle-config chains that wouldn't make valid dashboard
// networks. for the rest, it assembles the relevant data and fills in
// mainnet data where needed to make a `dashboardChain`
const configuredNetworks = chainNames.reduce((filtered, chainName) => {
const chain = config.networks[chainName];
if (
chainName !== "dashboard" &&
chainName !== "test" &&
chainName !== "develop" &&
((chain.host && chain.port) || // either has a host/port
(chain.rpcUrls && chain.rpcUrls.length > 0)) // or they provided an rpc url
) {
filtered.push({
chainId: chain.chainId ? chain.chainId : undefined,
chainName: chainName,
nativeCurrency: chain.nativeCurrency
? chain.nativeCurrency
: mainnet.nativeCurrency,
rpcUrls: chain.rpcUrls
? chain.rpcUrls
: [`http://${chain.host}:${chain.port}`],
blockExplorerUrls: chain.blockExplorerUrls
? chain.blockExplorerUrls
: undefined
});
}
return filtered;
}, []);

mergedChains.push(...configuredNetworks);
console.log(configuredNetworks);
}

const dashboardServerOptions = {
port,
host,
verbose,
dashboardChains: mergedChains
};
const dashboardServer = new DashboardServer(dashboardServerOptions);
await dashboardServer.start();

Expand Down
31 changes: 31 additions & 0 deletions packages/dashboard-message-bus/lib/message/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ export interface LogMessage extends Message {
};
}

/**
* Message to log in Dashboard browser console
*/
export interface DebugMessage extends Message {
type: "debug";
payload: {
message: string;
};
}

/**
* Message intended to invalidate earlier messages.
* The payload is the ID of the message that should be invalidated.
Expand All @@ -41,6 +51,17 @@ export interface InvalidateMessage extends Message {
payload: number;
}

/**
* Message intended to be passed from Server to Dashboard UI on initialization
* of the dashboard.
*/
export interface InitializeMessage extends Message {
type: "initialize";
payload: {
dashboardChains: object[];
};
}

export const isDashboardProviderMessage = (
message: Message
): message is DashboardProviderMessage => {
Expand All @@ -51,8 +72,18 @@ export const isLogMessage = (message: Message): message is LogMessage => {
return message.type === "log";
};

export const isDebugMessage = (message: Message): message is DebugMessage => {
return message.type === "debug";
};

export const isInvalidateMessage = (
message: Message
): message is InvalidateMessage => {
return message.type === "invalidate";
};

export const isInitializeMessage = (
message: Message
): message is InitializeMessage => {
return message.type === "initialize";
};
4 changes: 3 additions & 1 deletion packages/dashboard-message-bus/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import axios from "axios";

any.shim();

export class MessageBusConnectionError extends Error {}

/**
* Convert any JS object or value to a base64 representation of it
*/
Expand Down Expand Up @@ -152,7 +154,7 @@ export const getMessageBusPorts = async (
}
}

throw new Error(
throw new MessageBusConnectionError(
`Could not connect to dashboard at http://${dashboardHost}:${dashboardPort}/ports`
);
};
55 changes: 53 additions & 2 deletions packages/dashboard/bin/start-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,59 @@ const options = {
port: 24012,
host: "localhost",
verbose: true,
rpc: true,
autoOpen: false
autoOpen: false,
dashboardChains: [
{
chainId: "0x1",
chainName: "ethereum mainnet",
nativeCurrency: {
symbol: "ETH",
decimals: 18
},
rpcUrls: ["https://mainnet.infura.io/v3/"],
blockExplorerUrls: ["https://etherscan.com"]
},
{
chainId: "0x3",
chainName: "ropsten",
nativeCurrency: {
symbol: "ETH",
decimals: 18
},
rpcUrls: ["https://ropsten.infura.io/v3/"],
blockExplorerUrls: ["https://ropsten.etherscan.com"]
},
{
chainId: "0x4",
chainName: "rinkeby",
nativeCurrency: {
symbol: "ETH",
decimals: 18
},
rpcUrls: ["https://rinkeby.infura.io/v3/"],
blockExplorerUrls: ["https://rinkeby.etherscan.com"]
},
{
chainId: "0x2A",
chainName: "kovan",
nativeCurrency: {
symbol: "ETH",
decimals: 18
},
rpcUrls: ["https://ropsten.infura.io/v3/"],
blockExplorerUrls: ["https://kovan.etherscan.com"]
},
{
chainId: "0x5",
chainName: "goerli",
nativeCurrency: {
symbol: "ETH",
decimals: 18
},
rpcUrls: ["https://goerli.infura.io/v3/"],
blockExplorerUrls: ["https://goerli.etherscan.com"]
}
]
};

const dashboardServer = new DashboardServer(options);
Expand Down
Loading