Skip to content

Commit

Permalink
Disabled wallet transactions & fixed account balance refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelFedora committed Dec 16, 2018
1 parent 1f1040b commit eed6376
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
19 changes: 11 additions & 8 deletions src/common/vuex/stores/account.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AccountStateType, SATOSHIS_IN_BTC } from './types/account.state';
import { StateType } from './types/state';
import { decrypt, encrypt } from '../../util';
import { validateMnemonic, mnemonicToSeed } from 'bip39';
import Axios from 'axios';
import Axios, { AxiosPromise, AxiosResponse } from 'axios';
import { config, transactions, network } from 'blockstack';
import { WrappedNode } from '../../data/wrapped-node';

Expand Down Expand Up @@ -88,15 +88,18 @@ export const accountModule: Module<AccountStateType, StateType> = {
},
async refreshBalances({ state, commit, rootState }) {
const balances: { [key: string]: number } = { };
const insightUrl = 'https://utxo.blockstack.org/insight-api/addr/{address}'; // only one that works
const insightUrl = 'https://blockstack-explorer-api.herokuapp.com/api/addresses/{address}?page=0'

for(const addr of state.bitcoinAccount.addresses) {
const rootUrl = insightUrl.replace('{address}', addr);
const results = await Promise.all([
Axios.get(rootUrl + '/balance'),
Axios.get(rootUrl + '/unconfirmedBalance')
]);
balances[addr] = 1.0 * (results[0].data + results[1].data) / SATOSHIS_IN_BTC;
const url = insightUrl.replace('{address}', addr);
let res: AxiosResponse;
try {
res = await Axios.get(url);
} catch(e) {
console.error(`Error getting balances for address ${addr}:`, e);
continue;
}
balances[addr] = 1.0 * (res.data.balance) / SATOSHIS_IN_BTC;
}
commit('updateBalances', { balances });
},
Expand Down
22 changes: 10 additions & 12 deletions src/main/components/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default (Vue as VVue).component('bs-main-wallet', {
btcPrice: 1000,
refreshing: false,
selected: 'btc',
txs: [],
// txs: [],

btcPriceUrl: 'https://www.bitstamp.net/api/v2/ticker/btcusd/?cors=1',
networkFeeUrl: 'https://bitcoinfees.21.co/api/v1/fees/recommended',
Expand All @@ -39,32 +39,30 @@ export default (Vue as VVue).component('bs-main-wallet', {
if(this.refreshing) return;
this.refreshing = true;
try {
const [_, txs, btcPrice] = await Promise.all([
const [_, /*txs,*/ btcPrice] = await Promise.all([
dispatch('account/refreshBalances'),
// v-- also nice, gets balance, stuff like that
// https://explorer.blockstack.org/insight-api/addr/1J3PUxY5uDShUnHRrMyU6yKtoHEUPhKULs
// https://explorer.blockstack.org/insight-api/currency
Axios.get('https://explorer.blockstack.org/insight-api/txs?address=' + this.address + '&pageNum=0')
.then(res => res.data.txs),
/*Axios.get('https://blockstack-explorer-api.herokuapp.com/api/addresses/' + '1J3PUxY5uDShUnHRrMyU6yKtoHEUPhKULs' + '?page=0')
.then(res => res.data.fullTransactions),*/
Axios.get(this.btcPriceUrl)
.catch(() => fetch(this.btcPriceUrl).then(res => ({ data: res.json() })))
.then(res => res.data.last)/*,
() => Axios.get('https://api.coindesk.com/v1/bpi/currentprice/usd.json')
.then(res => res.data.bpi.USD.rate))*/
]);
this.btcPrice = btcPrice || 1000;
this.txs.splice(0, this.txs.length, ...(txs || []));
// this.txs.splice(0, this.txs.length, ...(txs || []));
} catch(e) { console.error('Error refreshing balances:', e); }
this.refreshing = false;
},
formatBlocktime(millis: number) {
/*formatBlocktime(millis: number) {
return DateTime.fromMillis(millis * 1000, { zone: 'utc' }).toLocaleString(DateTime.DATETIME_MED);
},
profit(tx: { vin: any[], vout: any[] }) {
profit(tx: { inputs: any[], outputs: any[] }) {
if(!tx) return;
let val = 0;
if(tx.vin && tx.vin.length) {
val = tx.vin.reduce((acc, v) => acc + v.addr === this.address ? v.value : 0, val);
if(tx.inputs && tx.inputs.length) {
val = tx.inputs.reduce((acc, v) => acc + v.addr === this.address ? v.value : 0, val);
}
if(tx.vout && tx.vout.length) {
Expand All @@ -76,7 +74,7 @@ export default (Vue as VVue).component('bs-main-wallet', {
}
return val;
},
},*/

openSendDialog() {
this.$modal.open({
Expand Down
6 changes: 3 additions & 3 deletions src/main/components/wallet/wallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
</div>
</div>

<h4 class='title is-5' style='width: 100%'>Transaction History</h4>
<!-- h4 class='title is-5' style='width: 100%'>Transaction History</h4>
<div id='history'>
<div class='notification tx' v-for='tx in txs' :key='tx.txid' :class='{ "is-success": profit(tx) > 0, "is-danger": profit(tx) < 0 }'>
<div>
<span>tx id:</span>
<a :href='"https://explorer.blockstack.org/tx/" + tx.txid'>{{tx.txid}}</a>
<span>date: {{formatBlocktime(tx.blocktime)}}</span>
<span>date: {{formatBlocktime(tx.time)}}</span>
</div>
<div class='tx-inner'>
Expand Down Expand Up @@ -75,7 +75,7 @@
<div v-if='txs.length === 0' class='notification'>
<span>Nothing here...</span>
</div>
</div>
</div -->

</div>
</div>
Expand Down

0 comments on commit eed6376

Please sign in to comment.