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

Added radio button toggle to use Web3 provider to send transaction #146

Closed
wants to merge 5 commits into from
Closed

Added radio button toggle to use Web3 provider to send transaction #146

wants to merge 5 commits into from

Conversation

VSaric
Copy link

@VSaric VSaric commented Dec 23, 2021

fixes: #137

Description: Added a radio button toggle on the top of the page. The options in the toggle is ethers and web3. Default toggle is ethers. If ethers is selected, the create token and deploy contract buttons are behave as they do today. If web3 is selected, create token and deploy contract use web3 instead of the current factories created by the ethers provider. The transactions created by the buttons are the same.

Screenshot of radio button toggle:

Screenshot from 2021-12-24 10-46-31

Switching ethers/web3 sreencast:

Screencast.2021-12-27.11.23.37.mp4

@VSaric VSaric self-assigned this Dec 23, 2021
src/index.html Outdated
@@ -30,6 +30,16 @@ <h1 id="logo-text" class="text-center">
</div>
</header>
<section>
<form name="myForm" class="form">

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".

Copy link
Author

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 {

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.

Copy link
Author

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>

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.

Copy link
Author

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

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.

Copy link
Author

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

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.

Copy link
Author

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';

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".

Copy link
Author

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';

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".

Copy link
Author

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);

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.

Copy link
Author

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';

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).

Copy link
Author

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';

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.

Copy link
Author

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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in: 91555c0

@mirjanaKukic
Copy link

Verified by QA.

@VSaric VSaric marked this pull request as ready for review December 28, 2021 11:09
@VSaric VSaric requested a review from a team as a code owner December 28, 2021 11:09
@VSaric VSaric requested a review from david0xd December 28, 2021 11:09
david0xd
david0xd previously approved these changes Dec 28, 2021
@VSaric
Copy link
Author

VSaric commented Jan 13, 2022

Hello @danjm, we implemented the web3 switching feature into the test-dapp and you can see it here in this PR. Just to remember you, if you have time, can you please review this changes, because when this PR be merged and done, we can unblocked ticket #18 and move it from Pending Consensys to Ready for development column.

Thank you in advance! :)

@EHaracic
Copy link

fixes: #137

mcmire
mcmire previously approved these changes Jan 24, 2022
Copy link
Collaborator

@mcmire mcmire left a 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.

@david0xd
Copy link

@mcmire I agree with you, just the purpose of this was to unblock the #18 at the moment.
Even before web3 integration was started, that index.js requires some heavy refactoring.
So, we should create a new task to do some good refactoring, probably to split these blocks of functionalities into the separate files, do the switching and call-delegation at the higher level from the index.js and propagate forward.

@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.

david0xd
david0xd previously approved these changes Jan 31, 2022
@EHaracic
Copy link

EHaracic commented Feb 4, 2022

@danjm can we merge this issue?

@VSaric VSaric dismissed stale reviews from david0xd and mcmire via 7f246d8 February 4, 2022 10:14
mcmire
mcmire previously approved these changes Feb 4, 2022
david0xd
david0xd previously approved these changes Feb 8, 2022
@danjm
Copy link
Contributor

danjm commented Feb 10, 2022

I checked that this is compatible with extension e2e tests

@danjm
Copy link
Contributor

danjm commented Feb 10, 2022

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?

@PeterYinusa
Copy link
Contributor

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

mcmire
mcmire previously approved these changes May 5, 2022
Copy link
Collaborator

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Collaborator

@mcmire mcmire left a 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!

@david0xd david0xd closed this by deleting the head repository Dec 8, 2022
@mcmire
Copy link
Collaborator

mcmire commented Dec 14, 2022

What was the final status on this PR, did we decide we didn't need it any more?

@danjm
Copy link
Contributor

danjm commented Dec 14, 2022

The changes from this PR are going to be incorporated into future changes to the test dapp made by the dapp api / devrel team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add button that uses Web3 provider to send transaction
7 participants