Skip to content

Commit

Permalink
v0.6.6 fix isConnected, fix TxBuilder transactions from mempool, get …
Browse files Browse the repository at this point in the history
…headers from explorer
  • Loading branch information
ThierryM1212 committed Aug 12, 2022
1 parent d40ca9f commit 908f791
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 19 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,9 @@ v0.6.4

v0.6.5
- improve CSV export: review the format, remove 500 transaction limit, allow export by address
- fix isConnected ergoConnector function to really check if safew is connected
- fix isConnected ergoConnector function to really check if safew is connected

v0.6.6
- get headers from Explorer rather than node
- fix loading of unconfirmed transactions in Transaction Builder
- fix isConnected to return a promise
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "safew-wallet",
"version": "0.6.5",
"version": "0.6.6",
"private": true,
"dependencies": {
"@babel/polyfill": "^7.12.1",
Expand Down
2 changes: 1 addition & 1 deletion public/inject1.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ErgoAPIini {
connectRequests.push({ resolve: resolve, reject: reject });
});
} else {
return false;
return Promise.reject();
}
}

Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"short_name": "SAFEW",
"name": "SAFEW - Simple And Fast Ergo Wallet",
"version": "0.6.5",
"version": "0.6.6",
"action": {},
"icons": {
"16": "/images/safew_icon_16.png",
Expand Down
2 changes: 1 addition & 1 deletion public/manifest_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"short_name": "SAFEW",
"name": "SAFEW - Simple And Fast Ergo Wallet",
"version": "0.6.5",
"version": "0.6.6",
"icons": {
"16": "/images/safew_icon_16.png",
"32": "/images/safew_icon_32.png",
Expand Down
2 changes: 1 addition & 1 deletion public/manifest_v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"short_name": "SAFEW",
"name": "SAFEW - Simple And Fast Ergo Wallet",
"version": "0.6.5",
"version": "0.6.6",
"action": {},
"icons": {
"16": "/images/safew_icon_16.png",
Expand Down
22 changes: 16 additions & 6 deletions src/components/SignPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export default class SignPopup extends React.Component {
requestId: this.state.requestId,
}
});
window.close();
if (!this.state.debug) {
await this.delay(100);
window.close();
}
}
}

Expand Down Expand Up @@ -109,7 +112,10 @@ export default class SignPopup extends React.Component {
requestId: requestId,
}
});
window.close();
if (!this.state.debug) {
await this.delay(100);
window.close();
}
}

var wallet = await getConnectedWalletByURL(this.state.url);
Expand Down Expand Up @@ -178,8 +184,10 @@ export default class SignPopup extends React.Component {
requestId: this.state.requestId,
}
});
sleep(100);
window.close();
if (!this.state.debug) {
await this.delay(100);
window.close();
}
return;
}
//const res = await sendTx(signedTx);
Expand Down Expand Up @@ -212,8 +220,10 @@ export default class SignPopup extends React.Component {
requestId: this.state.requestId,
}
});
sleep(100);
window.close();
if (!this.state.debug) {
sleep(100);
window.close();
}
}

render() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/SignTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class SignTransaction extends React.Component {
const walletAddressList = getWalletAddressList(wallet);

if (wallet.type === 'ergopay') {
const [txId, txReducedB64safe] = await getTxReducedB64Safe(jsonUnsignedTx, selectedUtxos);
const [txId, txReducedB64safe] = await getTxReducedB64Safe(jsonUnsignedTx, selectedUtxos, jsonUnsignedTx.dataInputs);
var intervalId = setInterval(this.timer, 3000);
this.setState({
ergoPayTxId: txId,
Expand Down
6 changes: 4 additions & 2 deletions src/components/TxBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default class TxBuilder extends React.Component {
const initTx = this.state.initTx;
if (initTx.inputs && initTx.outputs && initTx.dataInputs) {
try {
this.loadTxFromJson(initTx);
await this.loadTxFromJson(initTx);
} catch (e) {
errorAlert("failed to load transaction: " + e.toString());
}
Expand Down Expand Up @@ -409,7 +409,7 @@ export default class TxBuilder extends React.Component {
async setErgoPayTx() {
var txId = '', txReducedB64safe = '';
try {
[txId, txReducedB64safe] = await getTxReducedB64Safe(this.getTransaction(), this.state.selectedBoxList);
[txId, txReducedB64safe] = await getTxReducedB64Safe(this.getTransaction(), this.state.selectedBoxList, this.state.selectedDataBoxList);
var intervalId = setInterval(this.timer, 3000);
this.setState({
ergoPayTxId: txId,
Expand Down Expand Up @@ -441,8 +441,10 @@ export default class TxBuilder extends React.Component {
}

async loadTxFromJson(json) {
console.log("loadTxFromJson", json);
var jsonFixed = json;
if ("tx" in json) { jsonFixed = json.tx; }
console.log("loadTxFromJson2", jsonFixed);
var alert = waitingAlert("Loading input boxes...")
const inputs = await enrichUtxos(jsonFixed.inputs, true);
const dataInputs = await enrichUtxos(jsonFixed.dataInputs, true);
Expand Down
4 changes: 4 additions & 0 deletions src/ergo-related/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export async function unspentBoxesFor(address) {
);
}

export async function getExplorerBlockHeaders() {
return getRequestV1(`/blocks/headers`).then((res) => res.data.items.slice(0,10));
}

export async function unspentBoxesForV1(address) {
return getRequestV1(`/boxes/unspent/byAddress/${address}`).then(
(res) => res.data.items
Expand Down
5 changes: 3 additions & 2 deletions src/ergo-related/serializer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Serializer} from "@coinbarn/ergo-ts";
import JSONBigInt from 'json-bigint';
import { getExplorerBlockHeaders } from "./explorer";
import { getLastHeaders } from "./node";


Expand Down Expand Up @@ -136,7 +137,7 @@ export async function ergoTreeToTemplate(ergoTree) {


export async function getErgoStateContext() {
const block_headers = (await ergolib).BlockHeaders.from_json(await getLastHeaders());
const block_headers = (await ergolib).BlockHeaders.from_json(await getExplorerBlockHeaders());
const pre_header = (await ergolib).PreHeader.from_block_header(block_headers.get(0));
return new (await ergolib).ErgoStateContext(pre_header, block_headers);
}
Expand Down Expand Up @@ -186,7 +187,7 @@ export async function signTransaction(unsignedTx, inputs, dataInputs, wallet) {
const inputBoxes = (await ergolib).ErgoBoxes.from_boxes_json(inputs);
const dataInputsBoxes = (await ergolib).ErgoBoxes.from_boxes_json(dataInputs);
const ctx = await getErgoStateContext();
//console.log("signTransaction2", unsignedTx, inputs, dataInputs);
//console.log("signTransaction2", unsignedTx, inputs, dataInputs, ctx);
const signedTx = wallet.sign_transaction(ctx, unsignedTransaction, inputBoxes, dataInputsBoxes);
return await signedTx.to_json();
}
Expand Down
10 changes: 10 additions & 0 deletions src/ergo-related/utxos.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function parseUtxos(utxos, addExtention, mode = 'input') {
}

export async function enrichUtxos(utxos, addExtension = false) {
console.log("enrichUtxos utxos", utxos);
var utxosFixed = [];
await ls_slim_flush();
var cache_newBoxes = await ls_slim_get('cache_newBoxes') ?? [];
Expand All @@ -83,6 +84,12 @@ export async function enrichUtxos(utxos, addExtension = false) {
box = cache_spentBoxes.find(b => b.boxId === utxos[i][key]);
} else {
box = await boxByBoxId(utxos[i][key]);

//console.log("enrichUtxos box", box);
if(!box && utxos[i]["address"]) {
const [spentBoxes, newBoxes] = getSpentAndUnspentBoxesFromMempool([utxos[i]["address"]]);
box = newBoxes.find(box => box.boxId === utxos[i][key]);
}
}
//console.log("enrichUtxos1", utxos[i][key]);
var newAssets = []
Expand Down Expand Up @@ -206,10 +213,12 @@ export function generateSwaggerTx(json) {
}

export function getUtxosListValue(utxos) {
console.log("getUtxosListValue", utxos);
return utxos.reduce((acc, utxo) => acc += BigInt(utxo.value), BigInt(0));
}

export function getTokenListFromUtxos(utxos) {
console.log("getTokenListFromUtxos", utxos);
var tokenList = {};
for (const i in utxos) {
for (const j in utxos[i].assets) {
Expand All @@ -225,6 +234,7 @@ export function getTokenListFromUtxos(utxos) {

export function enrichTokenInfoFromUtxos(utxos, tokInfo) {
//[TOKENID_SIGUSD]: ['SigUSD', "token-sigusd.svg", 2],
console.log("enrichTokenInfoFromUtxos", utxos);
var tokenInfo = { ...tokInfo };
for (const i in utxos) {
for (const j in utxos[i].assets) {
Expand Down

0 comments on commit 908f791

Please sign in to comment.