Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generic multi call scheme #4

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
13 changes: 13 additions & 0 deletions src/assets/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@
"Delete3BoxPostConfirmation": "Delete this comment?",
"Yes": "Yes",
"No": "No",
"Required": "Required",
"Validate Non-Negative" : "Please enter a non-negative value",
"Add contract": "Add contract",
"Contract Add Success": "Contract added successfully!",
"Contract Exist": "Contract already exist!",
"Choose contract": "Choose contract",
"Choose method": "Choose method",
"Loading": "Loading...",
"Remove": "Remove",
"Cancel": "Cancel",
"Submit proposal": "Submit proposal",
"Whitelisted contracts": "Whitelisted contracts",
"User contracts": "User contracts",
"No Proposals Found": "No proposals found whose title contains the given text. Note the filter is case-sensitive.",
"Type and press Enter ": "Type and press Enter or Tab to filter proposals by title",
"Unregistered Plugin Proposal": "This proposal is in unregistered plugin",
Expand Down
28 changes: 26 additions & 2 deletions src/components/Proposal/Create/CreateProposal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,25 @@
}

fieldset {
margin: 10px 0px;
margin: 30px 0px;
}

.removeFieldSet {
float: right;
border: none;
color: $accent-2;
background: none;
}

.addFieldSet {
border: none;
background: none;
color: $sky;
}

.removeFieldSet:hover,
.addFieldSet:hover {
opacity: 0.7;
}

.createProposalWrapper {
Expand Down Expand Up @@ -67,6 +85,7 @@ fieldset {
}

form {
select,
input {
width: 100%;
margin-top: 3px;
Expand Down Expand Up @@ -123,11 +142,16 @@ fieldset {
}
}

.addContract {
position: relative;
}

.encodedData {
overflow-wrap: break-word;
margin: 5px 0 40px 0px;
margin: 5px 0 5px 0px; // margin: 5px 0 40px 0px; TEMP
border: 1px solid;
padding: 20px;
max-width: 480px; // TEMPORARY - NEED TO BE DYNAMIC
}

.proposerIsAdminCheckbox {
Expand Down
53 changes: 9 additions & 44 deletions src/components/Proposal/Create/PluginForms/ABIService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AbiItem } from "web3-utils";
import { Interface, isHexString } from "ethers/utils";
import { Interface } from "ethers/utils";
import { SortService } from "lib/sortService";
const Web3 = require("web3");
import axios from "axios";
import { isAddress, targetedNetwork } from "lib/util";
import { targetedNetwork } from "lib/util";

export interface IAllowedAbiItem extends AbiItem {
name: string
Expand Down Expand Up @@ -74,36 +74,6 @@ export const extractABIMethods = (abi: AbiItem[]): IAbiItemExtended[] => {
.sort(({ name: a }, { name: b }) => SortService.evaluateString(a, b, 1));
};

/**
* Given array of ABI parameters objects, returns true if all values are valid.
* Data example:
* [{ type: address, value: "0x25112235dDA2F775c81f0AA37a2BaeA21B470f65" }]
* @param {array} data
* @returns {boolean}
*/
export const validateABIInputs = (data: Array<any>): boolean => {
for (const input of data) {
switch (input.type) {
case "address":
if (!isAddress(input.value)) {
return false;
}
break;
case "bytes":
if (!isHexString(input.value)) {
return false;
}
break;
case "uint256":
if (/^\d+$/.test(input.value) === false) {
return false;
}
break;
}
}
return true;
};

/**
* Given contract address returns it's ABI data.
* @param {string} contractAddress
Expand All @@ -124,22 +94,17 @@ export const getABIByContract = async (contractAddress: string): Promise<Array<a
};

/**
* Given ABI, function name and it's parameters values returns the encoded data as string.
* Given ABI, function name and it's parameters values returns the encoded data as string, otherwise returns an error.
* @param {array} abi ABI methods array
* @param {string} name Method name
* @param {array} data array of ABI parameters objects. Example: [{ type: address, value: "0x25112235dDA2F775c81f0AA37a2BaeA21B470f65" }]
* @param {array} values array of ABI parameters values.
* @returns {string} The encoded data
*/
export const encodeABI = (abi: Array<any>, name: string, data: any[]): string => {
const interfaceABI = new Interface(abi);

if (validateABIInputs(data)) {
const values = [];
for (const input of data) {
values.push(input.value);
}
export const encodeABI = (abi: Array<any>, name: string, values: any[]): string => {
try {
const interfaceABI = new Interface(abi);
return interfaceABI.functions[name].encode(values);
} catch (error) {
return error.reason;
}

return "";
};
Loading