Skip to content

Commit

Permalink
synced with the latest graphene-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
valzav committed Oct 14, 2015
2 parents b6b2e58 + 3d1cd22 commit aa85e61
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 69 deletions.
3 changes: 2 additions & 1 deletion dl/src/dl_cli_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import BackupActions from "actions/BackupActions"

import alt from 'alt-instance'
import iDB from 'idb-instance'

import chain_config from "chain/config"

module.exports = {

Expand All @@ -24,6 +24,7 @@ module.exports = {
AccountStore,
BackupActions,
ChainStore,
chain_config,

alt, iDB, Apis,
db: ()=> Apis.instance().db_api(),
Expand Down
134 changes: 95 additions & 39 deletions dl/src/stores/AccountStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import PrivateKeyStore from "./PrivateKeyStore"
import validation from "common/validation"
import ChainStore from "api/ChainStore"
import AccountRefsStore from "stores/AccountRefsStore"
import AddressIndex from "stores/AddressIndex"

/**
* This Store holds information about accounts in this wallet
Expand All @@ -27,7 +28,7 @@ class AccountStore extends BaseStore {
// onNewPrivateKeys: [ PrivateKeyActions.loadDbData, PrivateKeyActions.addKey ]
});
this._export("loadDbData", "tryToSetCurrentAccount", "onCreateAccount",
"getMyAccounts", "isMyAccount", "getMyAuthorityForAccount");
"getMyAccounts", "isMyAccount");
}

_getInitialState() {
Expand Down Expand Up @@ -89,53 +90,25 @@ class AccountStore extends BaseStore {
continue
}
if(account == null) {
console.log("... ChainStore.getAccount("+account_name+") == null")
console.log("WARN: non-chain account name in linkedAccounts", account_name)
continue
}
if(this.getMyAuthorityForAccount(account) === "full") {
var auth = getMyAuthorityForAccount(account)
if(auth === undefined) {
this.state.update = true
continue
}
if(auth === 1) {
accounts.push(account_name)
}
}
return accounts.sort()
}

/**
@todo "partial"
@return string "none", "full", "partial"
*/
getMyAuthorityForAccount(account) {
return "full" // pending support for Addresses and Accounts
}

// Balance claims will still use this as a security precaution
getMyAuthorityForAccount_pubkeyonly(account) {
if (! account) return undefined
// @return 3 full, 2 partial, 0 none
function pubkeyThreshold(authority) {
var available = 0
var required = authority.get("weight_threshold")
for (let k of authority.get("key_auths")) {
if (PrivateKeyStore.hasKey(k.get(0))) {
available += k.get(1)
}
if(available >= required) break
}
return available >= required ? 3 : available > 0 ? 2 : 0
}
var owner = pubkeyThreshold(account.get("owner"))
if(owner == 3) return "full"

var active = pubkeyThreshold(account.get("active"))
if(active == 3) return "full"

if(owner == 2 || active == 2) return "partial"

return "none"
}

isMyAccount(account) {
let authority = this.getMyAuthorityForAccount(account);
return authority === "partial" || authority === "full";
let weight = getMyAuthorityForAccount(account);
if( weight === undefined ) return undefined
return weight === 1 // full
}

onAccountSearch(payload) {
Expand Down Expand Up @@ -224,3 +197,86 @@ class AccountStore extends BaseStore {
}

module.exports = alt.createStore(AccountStore, "AccountStore");

/** @return threshold percent 1 full, .n partial, 0 none */
function getMyAuthorityForAccount(account, recursion_count = 1) {
if (! account) return undefined

var owner_authority = account.get("owner")
var owner_threshold = owner_authority.get("weight_threshold")
var active_authority = account.get("active")
var active_threshold = active_authority.get("weight_threshold")

var owner_pubkey_threshold = pubkeyThreshold(owner_authority)
if(owner_pubkey_threshold >= owner_threshold) return 1
var active_pubkey_threshold = pubkeyThreshold(active_authority)
if(active_pubkey_threshold >= active_threshold) return 1

var owner_address_threshold = addressThreshold(owner_authority)
if(owner_address_threshold >= owner_threshold) return 1
var active_address_threshold = addressThreshold(active_authority)
if(active_address_threshold >= active_threshold) return 1

var owner_account_threshold, active_account_threshold
if(recursion_count < 3) {
owner_account_threshold = accountThreshold(owner_authority, recursion_count)
if ( owner_account_threshold === undefined ) return undefined
if(owner_account_threshold >= owner_threshold) return 1
active_account_threshold = accountThreshold(active_authority, recursion_count)
if ( active_account_threshold === undefined ) return undefined
if(active_account_threshold >= active_threshold) return 1
}
var threshold = 0
threshold = Math.max(threshold, owner_pubkey_threshold / owner_threshold)
threshold = Math.max(threshold, active_pubkey_threshold / active_threshold)
threshold = Math.max(threshold, owner_address_threshold / owner_threshold)
threshold = Math.max(threshold, active_address_threshold / active_threshold)
threshold = Math.max(threshold, owner_account_threshold / owner_threshold)
threshold = Math.max(threshold, active_account_threshold / active_threshold)
return threshold
}

function accountThreshold(authority, recursion_count) {
var account_auths = authority.get("account_auths")
if( ! account_auths.size ) return 0
for (let k of account_auths) {
// get all accounts in the queue for fetching
var account_id = k.get(0)
ChainStore.getAccount(account_id)
}
var available = 0
for (let k of account_auths) {
var account_id = k.get(0)
var account = ChainStore.getAccount(account_id)
if(account === undefined) return undefined
var weight = getMyAuthorityForAccount(account, ++recursion_count)
if( weight === 1) available += k.get(1)
}
return available
}

function pubkeyThreshold(authority) {
var available = 0
var key_auths = authority.get("key_auths")
for (let k of key_auths) {
if (PrivateKeyStore.hasKey(k.get(0))) {
available += k.get(1)
}
}
return available
}

function addressThreshold(authority) {
var available = 0
var address_auths = authority.get("address_auths")
if( ! address_auths.size) return 0
var addresses = AddressIndex.getState().addresses
for (let k of address_auths) {
var address = k.get(0)
var pubkey = addresses.get(address)
if (PrivateKeyStore.hasKey(pubkey)) {
available += k.get(1)
}
}
return available
}
2 changes: 1 addition & 1 deletion electron/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"productName": "BitShares2_light",
"identifier": "org.bitshares.graphene",
"description": "BitShares - cryptocurrency and decentralized exchange",
"version": "2.0.0",
"version": "2.15.287",
"author": "community@bitshares.org",
"main": "electron.js",
"config": {
Expand Down
2 changes: 1 addition & 1 deletion electron/tasks/release_linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var init = function () {
tmpDir = projectDir.dir('./tmp', { empty: true });
releasesDir = projectDir.dir('./releases');
manifest = projectDir.read('build/package.json', 'json');
packName = manifest.name + '_' + manifest.version;
packName = manifest.name.toLowerCase() + '_' + manifest.version;
packDir = tmpDir.dir(packName);
readyAppDir = packDir.cwd('opt', manifest.name);

Expand Down
10 changes: 8 additions & 2 deletions web/app/assets/index-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
<title>BitShares 2.0</title>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<style>
body {background-color: #2a2a2a}
.centerDiv{ width:140px; border-radius: 5px; color:lightgrey;
body {
background-color: #2a2a2a
}
.centerDiv {
width:140px; border-radius: 5px; color:lightgrey;
padding:10px; height:50px; position:absolute;
margin-top:-25px; margin-left:-70px; top:50%; left:50%;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight: 100;
font-size: 44px;
}
</style>
</head>
Expand Down
10 changes: 8 additions & 2 deletions web/app/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
<title>BitShares 2.0</title>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<style>
body {background-color: #2a2a2a}
.centerDiv{ width:140px; border-radius: 5px; color:lightgrey;
body {
background-color: #2a2a2a
}
.centerDiv {
width:140px; border-radius: 5px; color:lightgrey;
padding:10px; height:50px; position:absolute;
margin-top:-25px; margin-left:-70px; top:50%; left:50%;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight: 100;
font-size: 44px;
}
</style>
<link rel="stylesheet" href="app.css">
Expand Down
2 changes: 1 addition & 1 deletion web/app/assets/locales/locale-cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ module.exports = {
confirm_buy: "确认订单: 以 %(price_amount)s %(price_symbol)s 的价格,买入 %(buy_amount)s %(buy_symbol)s ",
confirm_sell: "确认订单: 以 %(price_amount)s %(price_symbol)s 的价格,卖出 %(sell_amount)s %(sell_symbol)s ",
settle: "清算价格",
core_rate: "喂价",
core_rate: "转账手续费汇率",
squeeze: "强制平仓价",
maintenance: "维持保证金价",
your_price: "你的强平触发价",
Expand Down
1 change: 1 addition & 0 deletions web/app/assets/locales/locale-en.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@
precision: "Precision"
},
asset: {
title: "Asset",
not_found: "The asset %(name)s does not exist",
summary: {
asset_type: "Asset type",
Expand Down
31 changes: 15 additions & 16 deletions web/app/components/Blockchain/Block.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Block extends BaseComponent {
!Immutable.is(nextProps.blocks, this.props.blocks) ||
nextProps.height !== this.props.height ||
nextProps.dynGlobalObject !== this.props.dynGlobalObject
);
);
}

_getBlock(height) {
Expand Down Expand Up @@ -117,30 +117,29 @@ class Block extends BaseComponent {
let height = parseInt(this.props.height, 10);
let block = blocks.get(height);

if (!block) {
return null;
}

return (
<div className="grid-block">
<div className="grid-container">
<div className="grid-content">

<h4><Translate style={{textTransform: "uppercase"}} component="span" content="explorer.block.title" /> #{height}</h4>
<div className="grid-content">
<div className="grid-content no-overflow medium-offset-2 medium-8 large-offset-3 large-6 small-12">
<h4 className="text-center"><Translate style={{textTransform: "uppercase"}} component="span" content="explorer.block.title" /> #{height}</h4>
<ul>
<li><Translate component="span" content="explorer.block.date" />: <FormattedDate
<li><Translate component="span" content="explorer.block.date" />: {block ? <FormattedDate
value={block.timestamp}
formats={intlData.formats}
format="full"
/>
/> : null}
</li>
<li><Translate component="span" content="explorer.block.witness" />: <LinkToWitnessById witness={block.witness} /></li>
<li><Translate component="span" content="explorer.block.previous" />: {block.previous}</li>
<li><Translate component="span" content="explorer.block.transactions" />: {block.transactions.length}</li>
<li><Translate component="span" content="explorer.block.witness" />: {block ? <LinkToWitnessById witness={block.witness} /> : null}</li>
<li><Translate component="span" content="explorer.block.previous" />: {block ? block.previous : null}</li>
<li><Translate component="span" content="explorer.block.transactions" />: {block ? block.transactions.length : null}</li>
</ul>
<TransactionList
<div className="clearfix" style={{marginBottom: "1rem"}}>
<div className="button float-left outline" onClick={this._previousBlock.bind(this)}>&#8592;</div>
<div className="button float-right outline" onClick={this._nextBlock.bind(this)}>&#8594;</div>
</div>
{block ? <TransactionList
block={block}
/>
/> : null}
</div>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion web/app/components/Blockchain/Transaction.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,6 @@ class Transaction extends React.Component {
case "asset_publish_feed":
color = "warning";
let {feed} = op[1];
console.log("op:", op, feed);

rows.push(
<tr>
Expand Down
5 changes: 3 additions & 2 deletions web/app/components/Explorer/witnesses.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.active-witness {
> td {
background-color: rgba(80, 210, 194, 0.74902);
background-color: rgba(80, 210, 194, 0.4);
transition: background-color 0.6s ease;
}
}

Expand All @@ -11,4 +12,4 @@
.view-switcher {
padding-top: 1rem;
text-align: right;
}
}
4 changes: 2 additions & 2 deletions web/app/components/Forms/MyAccounts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class MyAccounts extends Component {
render() {
var account_names = this.props.accounts
.filter( account => !!account )
.filter( account => AccountStore.getMyAuthorityForAccount_pubkeyonly(account) === "full" )
.filter( account => AccountStore.isMyAccount(account) )
.map( account => account.get("name") ).sort()

return <span>
Expand All @@ -28,4 +28,4 @@ export default class MyAccounts extends Component {
this.props.onChange(account_name)
}

}
}
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"scripts": {
"test": "jest",
"start": "node server.js",
"build": "webpack --config conf/webpack-prod.js --progress --profile --colors"
"build": "webpack --config conf/webpack-prod.js --progress --profile --colors; echo 'copying to electron/build..'; cp -r dist/* ../electron/build/; echo 'done.'"
},
"dependencies": {
"alt": "~0.17.1",
Expand Down

0 comments on commit aa85e61

Please sign in to comment.