-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
Added radio button toggle to use Web3 provider to send transaction #146
Conversation
src/index.html
Outdated
@@ -30,6 +30,16 @@ <h1 id="logo-text" class="text-center"> | |||
</div> | |||
</header> | |||
<section> | |||
<form name="myForm" class="form"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name can be something like "librarySwitchForm".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in: 91555c0
src/index.css
Outdated
margin: 0 5px 0 5px; | ||
} | ||
|
||
#libraryLabel { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a class instead of an ID selector -> .libraryLabel
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in: 91555c0
src/index.html
Outdated
<div class="row justify-content-center"> | ||
<div class="justify-content-center"> | ||
<input type="radio" id="radio-ethers" name="libraryUsed" value="ethers" /> | ||
<label id="libraryLabel">Ethers</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace id
with class
here for both labels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in: 91555c0
src/index.js
Outdated
function handleLibraryChange(event) { | ||
libraryInUse = event.target.value; | ||
if (libraryInUse === 'web3') { | ||
// Deployed piggy bank smart contract with web3 library |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove these comments for this particular section because code already looks self-explainable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in: 91555c0
src/index.js
Outdated
// Deployed failing smart contract with web3 library | ||
failingContract = web3FailingContract; | ||
} else { | ||
// Deployed piggy bank smart contract with ethers library |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove these comments for this particular section because code already looks self-explainable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in: 91555c0
src/index.js
Outdated
depositButton.disabled = false; | ||
withdrawButton.disabled = false; | ||
} else { | ||
contractStatus.innerHTML = 'Not clicked'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably say something like "Not deployed" instead of "Not clicked".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in: 91555c0
src/index.js
Outdated
failingContractStatus.innerHTML = 'Deployed'; | ||
sendFailingButton.disabled = false; | ||
} else { | ||
failingContractStatus.innerHTML = 'Not clicked'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably say something like "Not deployed" instead of "Not clicked".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in: 91555c0
src/index.js
Outdated
sendFailingButton.disabled = true; | ||
} | ||
|
||
console.log(libraryInUse); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This console log can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in: 91555c0
src/index.js
Outdated
.then((receipt) => { | ||
console.log(receipt); | ||
}); | ||
contractStatus.innerHTML = 'Deposit completed'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved in then() callback function instead of being here.
Also, it would be nice to have catch on error and handle that as well (log to console and display status text with error message).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in: 91555c0
src/index.js
Outdated
.then((receipt) => { | ||
console.log(receipt); | ||
}); | ||
contractStatus.innerHTML = 'Withdrawn'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can also be moved to then() and error catch is welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in: 91555c0
src/index.js
Outdated
|
||
console.log(contract); | ||
console.log(piggyBankContract); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in: 91555c0
Verified by QA. |
Hello @danjm, we implemented the Thank you in advance! :) |
fixes: #137 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested these changes, and they seem to work.
There's one thing about this PR that we need to think about. This will add some tech debt that I think we will need to resolve in order to be able to make it easy to maintain the test dapp in the future. First, after this PR, the size of src/index.js
will be 1668 lines. It's not the most pleasant experience to maintain a file like this, and I think it'd be good if we split this up into separate files. Second, since we now have two ways of doing the same thing, I think we could benefit from using the strategy pattern to represent the logic between Web3 and ethers. That is, we could figure out all of the common actions between the two strategies and then create a Web3 object and an ethers object that implements the differences among all of the actions we've defined, then switch out the objects when the radio button is clicked.
I don't know if this change is time-sensitive, so if that's the case, I'm fine if we merge this now and refactor this later, but we're getting to a point now where the more we change, the more debt we create and the longer it will take to refactor. So it might be something we want to think about sooner rather than later.
@mcmire I agree with you, just the purpose of this was to unblock the #18 at the moment. @danjm can you consider creating new ticket for refactoring of the test-dapp (in complete)? I'm also wondering if this is a part of the TypeScript refactoring and should this also be TypeScript so we do all at once? I would just suggest that we finish with this with the merge and implementation of the batch transactions to unblock the requirements and then do the refactor. |
@danjm can we merge this issue? |
I checked that this is compatible with extension e2e tests |
I think we are close to being able to merge this. Before we do I'd like to get a look at this from @PeterYinusa: Peter, does this meet the needs we have for avoiding web3 compatibility bugs, from a QA perspective? |
Yes, this looks good |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
…s to use MM estimation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks good to me still!
What was the final status on this PR, did we decide we didn't need it any more? |
The changes from this PR are going to be incorporated into future changes to the test dapp made by the dapp api / devrel team |
fixes: #137
Description: Added a radio button toggle on the top of the page. The options in the toggle is
ethers
andweb3
. Default toggle isethers
. Ifethers
is selected, the create token and deploy contract buttons are behave as they do today. Ifweb3
is selected, create token and deploy contract useweb3
instead of the currentfactories
created by theethers
provider. The transactions created by the buttons are the same.Screenshot of radio button toggle:
Switching ethers/web3 sreencast:
Screencast.2021-12-27.11.23.37.mp4