Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/v0.30.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
yknl committed Jul 17, 2018
2 parents 5b905ce + 5e81f7a commit 48689cf
Show file tree
Hide file tree
Showing 93 changed files with 9,260 additions and 4,824 deletions.
9 changes: 8 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@
}
}
]
]
],
"env": {
"test": {
"plugins": ["rewire"],
"sourceMaps": "both",
"ignore": ["node_modules"]
}
}
}
12 changes: 6 additions & 6 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ build/*
gulp/*
flow-typed/*

tests/fixtures/*
tests/profiles/*
tests/store/*
tests/utils/a*
tests/utils/e*
tests/utils/n*
test/fixtures/*
test/profiles/*
test/store/*
test/utils/a*
test/utils/e*
test/utils/n*

app/js/profiles/components/VerificationInfo*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bower_components
# Build files
build
__coverage__
.nyc_output

.elasticbeanstalk/

Expand Down
23 changes: 23 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"require": [
"babel-register"
],
"coverageVariable": "__MY_TEST_COVERAGE__",
"exclude": [
"node_modules",
"test",
"build",
"gulp",
"testHelpers"
],
"extension": [
".js",
".jsx"
],
"reporter": [
"text-summary",
"html"
],
"report-dir": "__coverage__/",
"produce-source-map": true
}
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,10 @@ This repository is maintained by [yukan.id](https://explorer.blockstack.org/name

1. If you haven't already, follow steps 1 & 2 above
2. If you haven't already run `npm run dev` or `npm run build` at least once, run `npm run build`
3. Run all tests in the `tests/` directory with the `npm run test` command
* A single file can be run by specifing an `-f` flag: `npm run test -f <PATH_TO_TEST_FILE>`
* In the `PATH_TO_TEST_FILE`, it is possible to omit the `tests/` prefix, as well as the `.test.js` suffix. They will be automatically added if not detected.
3. Run all tests in the `test/` directory with the `npm run test` command
* A single file can be run by specifing an `-f` flag: `npm run test <PATH_TO_TEST_FILE>`

*Note: When running tests, code coverage will be automatically calculated and output to an HTML file using the [Istanbul](https://github.com/gotwarlost/istanbul) library. These files can be seen in the generated `coverage/` directory.*
*Note: When running tests, code coverage will be automatically calculated and output to an HTML file using the [Istanbul](https://istanbul.js.org/) library. These files can be seen in the generated `__coverage__/` directory.*

## App Development
### Run the browser in the Blockstack Test Environment
Expand Down
179 changes: 81 additions & 98 deletions app/js/account/store/account/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ import {
authorizationHeaderValue,
btcToSatoshis,
satoshisToBtc,
deriveIdentityKeyPair,
encrypt,
getIdentityPrivateKeychain,
getBitcoinPrivateKeychain,
getIdentityOwnerAddressNode,
getBitcoinAddressNode,
getInsightUrl
getInsightUrls,
getBlockchainIdentities
} from '@utils'
import { isCoreEndpointDisabled } from '@utils/window-utils'
import { transactions, config, network } from 'blockstack'
Expand Down Expand Up @@ -39,38 +35,14 @@ function createAccount(
identitiesToGenerate
) {
logger.debug(`createAccount: identitiesToGenerate: ${identitiesToGenerate}`)
const identityPrivateKeychainNode = getIdentityPrivateKeychain(masterKeychain)
const bitcoinPrivateKeychainNode = getBitcoinPrivateKeychain(masterKeychain)

const identityPublicKeychainNode = identityPrivateKeychainNode.neutered()
const identityPublicKeychain = identityPublicKeychainNode.toBase58()

const bitcoinPublicKeychainNode = bitcoinPrivateKeychainNode.neutered()
const bitcoinPublicKeychain = bitcoinPublicKeychainNode.toBase58()

const firstBitcoinAddress = getBitcoinAddressNode(
bitcoinPublicKeychainNode
).getAddress()

const identityAddresses = []
const identityKeypairs = []

// We pre-generate a number of identity addresses so that we
// don't have to prompt the user for the password on each new profile
for (
let addressIndex = 0;
addressIndex < identitiesToGenerate;
addressIndex++
) {
const identityOwnerAddressNode = getIdentityOwnerAddressNode(
identityPrivateKeychainNode,
addressIndex
)
const identityKeyPair = deriveIdentityKeyPair(identityOwnerAddressNode)
identityKeypairs.push(identityKeyPair)
identityAddresses.push(identityKeyPair.address)
logger.debug(`createAccount: identity index: ${addressIndex}`)
}

const {
identityPublicKeychain,
bitcoinPublicKeychain,
firstBitcoinAddress,
identityAddresses,
identityKeypairs
} = getBlockchainIdentities(masterKeychain, identitiesToGenerate)

return {
type: types.CREATE_ACCOUNT,
Expand Down Expand Up @@ -227,15 +199,15 @@ function refreshCoreWalletBalance(addressBalanceUrl, coreAPIPassword) {
if (isCoreEndpointDisabled(addressBalanceUrl)) {
logger.debug('Mocking core wallet balance in webapp build')
dispatch(updateCoreWalletBalance(0))
return
return Promise.resolve()
}

logger.trace('refreshCoreWalletBalance: Beginning refresh...')
logger.debug(
`refreshCoreWalletBalance: addressBalanceUrl: ${addressBalanceUrl}`
)
const headers = { Authorization: authorizationHeaderValue(coreAPIPassword) }
fetch(addressBalanceUrl, { headers })
return fetch(addressBalanceUrl, { headers })
.then(response => response.text())
.then(responseText => JSON.parse(responseText))
.then(responseJson => {
Expand All @@ -256,11 +228,11 @@ function getCoreWalletAddress(walletPaymentAddressUrl, coreAPIPassword) {
return dispatch => {
if (isCoreEndpointDisabled(walletPaymentAddressUrl)) {
logger.error('Cannot use core wallet if core is disable')
return
return Promise.resolve()
}

const headers = { Authorization: authorizationHeaderValue(coreAPIPassword) }
fetch(walletPaymentAddressUrl, { headers })
return fetch(walletPaymentAddressUrl, { headers })
.then(response => response.text())
.then(responseText => JSON.parse(responseText))
.then(responseJson => {
Expand Down Expand Up @@ -297,7 +269,7 @@ function withdrawBitcoinClientSide(

const amountSatoshis = Math.floor(amountBTC * 1e8)

transactions
return transactions
.makeBitcoinSpend(recipientAddress, paymentKey, amountSatoshis)
.then(transactionHex => {
const myNet = config.network
Expand Down Expand Up @@ -329,7 +301,7 @@ function withdrawBitcoinFromCoreWallet(
'Core wallet withdrawls not allowed in the simple webapp build'
)
)
return
return Promise.resolve()
}

const requestBody = {
Expand Down Expand Up @@ -375,7 +347,7 @@ function withdrawBitcoinFromCoreWallet(
)
}

fetch(coreWalletWithdrawUrl, {
return fetch(coreWalletWithdrawUrl, {
method: 'POST',
headers: requestHeaders,
body: JSON.stringify(requestBody)
Expand All @@ -399,61 +371,72 @@ function withdrawBitcoinFromCoreWallet(
function refreshBalances(insightUrl, addresses, coreAPIPassword) {
return dispatch => {
const results = []
addresses.forEach(address => {
logger.debug(
`refreshBalances: refreshing balances for address ${address}`
)
const urlBase = getInsightUrl(insightUrl, address, coreAPIPassword)
const confirmedBalanceUrl = `${urlBase}/balance`
const unconfirmedBalanceUrl = `${urlBase}/unconfirmedBalance`
fetch(confirmedBalanceUrl)
.then(response => response.text())
.then(responseText => {
const confirmedBalance = parseInt(responseText, 10)
fetch(unconfirmedBalanceUrl)
.then(response => response.text())
.then(balanceResponseText => {
const unconfirmedBalance = parseInt(balanceResponseText, 10)
results.push({
address,
balance: satoshisToBtc(unconfirmedBalance + confirmedBalance)
})

if (results.length >= addresses.length) {
const balances = {}
let total = 0.0

for (let i = 0; i < results.length; i++) {
const thisAddress = results[i].address
if (!balances.hasOwnProperty(thisAddress)) {
const balance = results[i].balance
total = total + balance
balances[address] = balance
} else {
logger.error(
`refreshBalances: Duplicate address ${thisAddress} in addresses array`
)
return Promise.all(
addresses.map(address => {
logger.debug(
`refreshBalances: refreshing balances for address ${address}`
)
const insightUrls = getInsightUrls(insightUrl, address, coreAPIPassword)
const confirmedBalanceUrl = insightUrls.confirmedBalanceUrl
const unconfirmedBalanceUrl = insightUrls.unconfirmedBalanceUrl
return fetch(confirmedBalanceUrl)
.then(response => response.text())
.then(responseText => {
const confirmedBalance = parseInt(responseText, 10)
fetch(unconfirmedBalanceUrl)
.then(response => response.text())
.then(balanceResponseText => {
const unconfirmedBalance = parseInt(balanceResponseText, 10)
results.push({
address,
balance: satoshisToBtc(unconfirmedBalance + confirmedBalance)
})

if (results.length >= addresses.length) {
const balances = {}
let total = 0.0

for (let i = 0; i < results.length; i++) {
const thisAddress = results[i].address
if (!balances.hasOwnProperty(thisAddress)) {
const balance = results[i].balance
total = total + balance
balances[thisAddress] = balance
} else {
logger.error(
`refreshBalances: Duplicate address ${thisAddress} in addresses array`
)
}
}
}

balances.total = total

dispatch(updateBalances(balances))
}
})
.catch(error => {
logger.error(
'refreshBalances: error fetching ${address} unconfirmed balance',
error
)
})
})
.catch(error => {
logger.error(
'refreshBalances: error fetching ${address} confirmed balance',
error
)
})
balances.total = total

dispatch(updateBalances(balances))
}
})
.catch(error => {
logger.error(
`refreshBalances: error fetching ${address} unconfirmed balance`,
error
)
})
})
.catch(error => {
logger.error(
`refreshBalances: error fetching ${address} confirmed balance`,
error
)
})
})
).then(() => {
logger.debug(
'refreshBalances: done refreshing balances for all addresses'
)
}).catch(error => {
logger.error(
'refreshBalances: error refreshing balances for addresses',
error
)
})
}
}
Expand Down
38 changes: 38 additions & 0 deletions app/js/clear-auth/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { PureComponent } from 'react'
import { withRouter } from 'react-router'

class ClearAuthPage extends PureComponent {
clearData = () => {
localStorage.clear()
window.location = `${this.props.location.query.redirect_uri}://?authCleared=1`
}

cancel = () => {
window.location = `${this.props.location.query.redirect_uri}://?authCleared=0`
}

render() {
return (
<div className="container-fluid">
<h3 className="p-t-20">Sign Out</h3>
<p>
<i>
Erase your keychain and settings so you can create a new one or restore another keychain.
</i>
</p>
<div className="m-t-40">
<button className="btn btn-danger btn-block" onClick={this.clearData}>
Confirm
</button>
</div>
<div className="m-t-10">
<button className="btn btn-tertiary btn-block" onClick={this.cancel}>
Cancel
</button>
</div>
</div>
)
}
}

export default withRouter(ClearAuthPage)
Loading

0 comments on commit 48689cf

Please sign in to comment.