Skip to content

Commit

Permalink
use json-bigint when manipulating utxos
Browse files Browse the repository at this point in the history
  • Loading branch information
ThierryM1212 committed Feb 24, 2022
1 parent 81f1dfd commit 8c4d042
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/components/SendTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { sendTx } from '../ergo-related/node';
import { getUtxoBalanceForAddressList, parseSignedTx } from '../ergo-related/utxos';
import BigQRCode from './BigQRCode';
import TokenLabel from './TokenLabel';
import JSONBigInt from 'json-bigint';

export default class SendTransaction extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -252,7 +253,7 @@ export default class SendTransaction extends React.Component {
amountToSendFloat, feeFloat, this.state.tokens, tokenAmountToSendInt);

const unsignedTransaction = await createUnsignedTransaction(selectedUtxos, outputCandidates);
const jsonUnsignedTx = JSON.parse(unsignedTransaction.to_json());
const jsonUnsignedTx = JSONBigInt.parse(unsignedTransaction.to_json());
//console.log("sendTransaction unsignedTransaction", jsonUnsignedTx);
return [jsonUnsignedTx, selectedUtxos];
}
Expand Down Expand Up @@ -308,7 +309,7 @@ export default class SendTransaction extends React.Component {
var signedTx = {};

try {
signedTx = JSON.parse(await signTransaction(jsonUnsignedTx, selectedUtxos, [], signingWallet));
signedTx = JSONBigInt.parse(await signTransaction(jsonUnsignedTx, selectedUtxos, [], signingWallet));
console.log("signedTx", signedTx);
} catch (e) {
errorAlert("Failed to sign transaction", e);
Expand Down
3 changes: 2 additions & 1 deletion src/components/SignPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { errorAlert } from '../utils/Alerts';
import { sampleTxErgodex, TX_FEE_ERGO_TREE } from '../utils/constants';
import { decryptMnemonic, formatERGAmount, formatTokenAmount, getConnectedWalletByURL, getUnconfirmedTransactionsForAddressList, getWalletAddressList, getWalletById, getWalletUsedAddressList } from '../utils/walletUtils';
import BigQRCode from './BigQRCode';
import JSONBigInt from 'json-bigint';

/* global chrome */

Expand Down Expand Up @@ -162,7 +163,7 @@ export default class SignPopup extends React.Component {
data: {
type: "ergo_api_response",
result: true,
data: JSON.parse(signedTx),
data: JSONBigInt.parse(signedTx),
requestId: this.state.requestId,
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/TxBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export default class TxBuilder extends React.Component {
//console.log("signingWallet", signingWallet);
var signedTx = {};
try {
signedTx = JSON.parse(await signTransaction(jsonUnsignedTx, this.state.selectedBoxList, this.state.selectedDataBoxList, signingWallet));
signedTx = JSONBigInt.parse(await signTransaction(jsonUnsignedTx, this.state.selectedBoxList, this.state.selectedDataBoxList, signingWallet));
console.log("signedTx", signedTx);
this.setState({ signedTransaction: signedTx })
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/UnconfirmedBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class UnconfirmedBalance extends React.Component {
const unconfirmedInputs = this.state.unconfirmedTx.map(tx => tx.inputs).flat();
const unconfirmedOutputs = this.state.unconfirmedTx.map(tx => tx.outputs).flat();
const unconfirmedBalance = await getUtxoBalanceForAddressList(unconfirmedInputs, unconfirmedOutputs, this.state.addressList);
console.log("AddressListContent23", unconfirmedInputs, unconfirmedOutputs, this.state.addressList, JSON.stringify(unconfirmedBalance))
console.log("AddressListContent23", unconfirmedInputs, unconfirmedOutputs, this.state.addressList, JSONBigInt.stringify(unconfirmedBalance))
this.setState({
unconfirmedBalance: unconfirmedBalance,
})
Expand All @@ -30,7 +30,7 @@ export default class UnconfirmedBalance extends React.Component {
const unconfirmedInputs = this.state.unconfirmedTx.map(tx => tx.inputs).flat();
const unconfirmedOutputs = this.state.unconfirmedTx.map(tx => tx.outputs).flat();
const unconfirmedBalance = await getUtxoBalanceForAddressList(unconfirmedInputs, unconfirmedOutputs, this.state.addressList);
console.log("AddressListContent23", unconfirmedInputs, unconfirmedOutputs, this.state.addressList, JSON.stringify(unconfirmedBalance))
console.log("AddressListContent23", unconfirmedInputs, unconfirmedOutputs, this.state.addressList, JSONBigInt.stringify(unconfirmedBalance))
this.setState({
unconfirmedBalance: unconfirmedBalance,
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/WalletList.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class WalletList extends React.Component {
async componentDidMount() {
var intervalId = setInterval(this.timer, 60000);
this.setState({ intervalId: intervalId });
await updateUnusedAddresses();
updateUnusedAddresses();
await this.updateWalletAddressListContent();
}

Expand Down
5 changes: 3 additions & 2 deletions src/ergo-related/rest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { displayTransaction, errorAlert } from "../utils/Alerts";
import JSONBigInt from 'json-bigint';

export async function postTx(url, body = {}, apiKey = '') {
console.log("post", url)
Expand All @@ -11,7 +12,7 @@ export async function postTx(url, body = {}, apiKey = '') {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept',
},
body: JSON.stringify(body)
body: JSONBigInt.stringify(body)
}).then(response => Promise.all([response.ok, response.json()]))
.then(([responseOk, body]) => {
if (responseOk) {
Expand Down Expand Up @@ -41,7 +42,7 @@ export async function post(url, body = {}, apiKey = '') {
'Content-Type': 'application/json',
api_key: apiKey,
},
body: JSON.stringify(body),
body: JSONBigInt.stringify(body),
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/walletUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export function setAddressUsed(addressToSet) {
}

export async function updateUnusedAddresses() {
var alert = waitingAlert("Searching new used addresses");
//var alert = waitingAlert("Searching new used addresses");
var walletList = JSON.parse(localStorage.getItem('walletList'));
for (var k in walletList) {
var newWallet = { ...walletList[k] };
Expand All @@ -397,7 +397,7 @@ export async function updateUnusedAddresses() {
}
}
}
alert.close();
//alert.close();
}

export function setChangeAddress(walletId, address) {
Expand Down

0 comments on commit 8c4d042

Please sign in to comment.