Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lennardevertz committed Feb 16, 2024
2 parents fbdd383 + f982190 commit b24cb84
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@idriss-crypto/send-core",
"version": "0.4.11",
"version": "0.4.12",
"scripts": {
"build": "webpack",
"buildLocal": "webpack --watch --mode=none",
Expand Down
35 changes: 27 additions & 8 deletions src/subpages/revertPayment.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { defaultWeb3, defaultWeb3ETH, SendToAnyoneLogic } from "../sendToAnyoneLogic";
import { getProvider } from "../getWeb3Provider"
import template from "./revertPayment.mpts";
import {create} from "fast-creator";

let provider = null;


export class RevertPayment {
constructor(idriss) {
this.idriss = idriss;
constructor() {
this.html = create('div', {}, template({}));

this.html.querySelector('.revertButton')?.addEventListener('click', async (e) => {
console.log("revert clicked")
if (!this.provider) {
this.provider = await getProvider();
await SendToAnyoneLogic.prepareSendToAnyone(this.provider, 'Polygon', "")
this.idriss = SendToAnyoneLogic.idriss;
}
this.connectWalletUI();
let txnHash = this.html.querySelector('.customHash').value;
try {
await this.getTransaction(txnHash)
Expand All @@ -23,23 +30,35 @@ export class RevertPayment {

}

async connectWalletUI() {
document.querySelector('#connectWallet').classList.add('hidden');
document.querySelector('#connectedWallet').classList.remove('hidden');
let accounts = await SendToAnyoneLogic.web3.eth.getAccounts();
let reverse = await SendToAnyoneLogic.idriss.reverseResolve(accounts[0]);
let loginDisplay = reverse? reverse : accounts[0].substring(0, 6).concat("...").concat(accounts[0].substr(-4))
document.querySelector('#connectedWallet').firstElementChild.value = loginDisplay
document.querySelector('#polygon-scan-link').href = POLYGON_BLOCK_EXPLORER_ADDRESS + "/address/" + accounts[0];
}

async getTransaction(transactionHash) {

this.html.querySelector('#buttonRevertSpinner').style.display = '';
this.html.querySelector('#revertNext').style.display = 'none';
let transaction;
try {
transaction = await defaultWeb3.eth.getTransaction(transactionHash)
let transaction = await defaultWeb3.eth.getTransaction(transactionHash)
let method = transaction.input.slice(2, 10);
let remove = transaction.input.replace(method, "");
let [IDrissHash, type, address] = await this.getInputs(method, remove);
console.log(IDrissHash, type, address)
this.html.querySelector('.errorInput').style.display = 'none';
} catch {
console.log("Invalid txn hash")
this.html.querySelector('.errorInput').style.display = 'block';
this.html.querySelector('#buttonRevertSpinner').style.display = 'none';
this.html.querySelector('#revertNext').style.display = '';
return null
}
let method = transaction.input.slice(2, 10);
let remove = transaction.input.replace(method, "");
let [IDrissHash, type, address] = await this.getInputs(method, remove);
console.log(IDrissHash, type, address)


await this.idriss.revertPayment(IDrissHash, type, address)

Expand Down
12 changes: 6 additions & 6 deletions src/subpages/revertPayment.mpts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<header>
<h1>Reverse a Transaction</h1>
</header>
<main>
<h1>Revert Send</h1>
<label>Transaction hash to revert</label>
<input id="urlInput" type="text" class="customHash" placeholder="0x..." />
<input id="urlInput" type="text" class="customHash" placeholder="Transaction hash" />
<p class="errorInput">Input a valid transaction hash</p>
<button type="button" class="revertButton">
<span id="revertNext" >Revert</span>
<span id="revertNext" >Reverse</span>
<div id="buttonRevertSpinner" style="display: none;" class="spinnerWrapper">
<div class="spinner" role="status">
<span class="spinnerDot">•</span>
Expand All @@ -12,5 +14,3 @@
</div>
</button>
</main>
<footer>
</footer>

0 comments on commit b24cb84

Please sign in to comment.