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

feat: Add ENS resolution #362

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,37 @@ <h4 class="card-title">
</div>
</div>
</section>
<section>
<div class="row d-flex justify-content-center">
<div class="col-xl-4 col-lg-6 col-md-12 col-sm-12 col-12">
<div class="card">
<div class="card-body">
<h4 class="card-title">
ENS Resolution
</h4>
<div class="form-group">
<label>Address</label>
<input
class="form-control"
type="text"
id="ensInput"
/>
</div>
<button
class="btn btn-primary btn-lg btn-block mb-3"
id="ensSubmit"
>
Submit
</button>
<p class="info-text alert alert-warning">
Result:
<span id="ensResult"></span>
</p>
</div>
</div>
</div>
</div>
</section>
</main>

<script src="main.js" defer></script>
Expand Down
25 changes: 25 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ const maliciousPermitHexPaddedChain = document.getElementById(
const maliciousPermitIntAddress = document.getElementById(
'maliciousPermitIntAddress',
);

// ENS Resolution
const ensInput = document.getElementById('ensInput');
const ensSubmit = document.getElementById('ensSubmit');
const ensResult = document.getElementById('ensResult');

// Buttons that require connecting an account
const allConnectedButtons = [
deployButton,
Expand Down Expand Up @@ -457,6 +463,7 @@ const allConnectedButtons = [
maliciousPermitHexPaddedChain,
maliciousPermitIntAddress,
maliciousPermitIntAddress,
ensSubmit,
];

// Buttons that are available after initially connecting an account
Expand Down Expand Up @@ -509,6 +516,7 @@ const initialConnectedButtons = [
maliciousApproveERC20WithOddHexData,
maliciousPermitHexPaddedChain,
maliciousPermitIntAddress,
ensSubmit,
];

/**
Expand Down Expand Up @@ -3298,6 +3306,23 @@ const initializeFormElements = () => {
console.log(result);
};

/**
* ENS Resolution
*/
ensSubmit.onclick = async () => {
try {
ensResult.innerHTML = 'Resolving...';
const ensAddress = ensInput.value;
const ensResolver = await ethersProvider.getResolver(ensAddress);
const ethAddress = await ensResolver.getAddress();

ensResult.innerHTML = String(ethAddress);
} catch (error) {
console.error(error);
ensResult.innerHTML = 'Failed to resolve address';
}
};

/**
* Providers
*/
Expand Down
Loading