Skip to content

Commit

Permalink
fix balance and transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
TerenceGe committed Sep 23, 2018
1 parent ce47b4a commit 8a5ec2d
Show file tree
Hide file tree
Showing 21 changed files with 1,131 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"react/jsx-one-expression-per-line": [0],
"no-else-return": [0],
"react/destructuring-assignment": [0],
"prefer-arrow-callback": [0]
"prefer-arrow-callback": [0],
"no-prototype-builtins": [0]
},
"env": {
"browser": true,
Expand Down
2 changes: 1 addition & 1 deletion shared/components/Form/TransferAssetsForm/index.native.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default class TransferAssetsForm extends Component {

componentDidMount() {
const { activeAsset, eosAccountName } = this.props
this.props.actions.getEOSAssetBalanceRequested({ code: activeAsset.get('contract'), eosAccountName })
this.props.actions.getEOSAssetBalanceRequested({ code: activeAsset.get('contract'), eosAccountName, symbol: activeAsset.get('symbol') })
}

render() {
Expand Down
6 changes: 6 additions & 0 deletions shared/core/scatter/Blockchains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const Blockchains = {
EOS: 'eos',
ETH: 'eth'
}

export const BlockchainsArray = Object.keys(Blockchains).map(key => ({ key, value: Blockchains[key] }))
63 changes: 63 additions & 0 deletions shared/core/scatter/Error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as ErrorTypes from './ErrorTypes'

export const ErrorCodes = {
NO_SIGNATURE: 402,
FORBIDDEN: 403,
TIMED_OUT: 408,
LOCKED: 423,
UPGRADE_REQUIRED: 426,
TOO_MANY_REQUESTS: 429
}

export default class Error {
constructor(_type, _message, _code = ErrorCodes.LOCKED){
this.type = _type
this.message = _message
this.code = _code
this.isError = true
}

static locked(){
return new Error(ErrorTypes.LOCKED, "The user's Scatter is locked. They have been notified and should unlock before continuing.")
}

static promptClosedWithoutAction(){
return new Error(ErrorTypes.PROMPT_CLOSED, 'The user closed the prompt without any action.', ErrorCodes.TIMED_OUT)
}

static maliciousEvent(){
return new Error(ErrorTypes.MALICIOUS, 'Malicious event discarded.', ErrorCodes.FORBIDDEN)
}

static signatureError(_type, _message){
return new Error(_type, _message, ErrorCodes.NO_SIGNATURE)
}

static requiresUpgrade(){
return new Error(ErrorTypes.UPGRADE_REQUIRED, "The required version is newer than the User's Scatter", ErrorCodes.UPGRADE_REQUIRED)
}

static identityMissing(){
return this.signatureError('identity_missing', "Identity no longer exists on the user's keychain")
}

static signatureAccountMissing(){
return this.signatureError('account_missing', 'Missing required accounts, repull the identity')
}

static malformedRequiredFields(){
return this.signatureError('malformed_requirements', 'The requiredFields you passed in were malformed')
}

static noNetwork(){
return this.signatureError('no_network', 'You must bind a network first')
}

static usedKeyProvider(){
return new Error(
ErrorTypes.MALICIOUS,
'Do not use a `keyProvider` with a Scatter. Use a `signProvider` and return only signatures to this object. A malicious person could retrieve your keys otherwise.',
ErrorCodes.NO_SIGNATURE
)
}
}
4 changes: 4 additions & 0 deletions shared/core/scatter/ErrorTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const MALICIOUS = 'malicious';
export const LOCKED = 'locked';
export const PROMPT_CLOSED = 'prompt_closed';
export const UPGRADE_REQUIRED = 'upgrade_required';
40 changes: 40 additions & 0 deletions shared/core/scatter/Network.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Blockchains } from './Blockchains'

export default class Network {
constructor(_name = '', _protocol = 'https', _host = '', _port = 0, blockchain = Blockchains.EOS, chainId = ''){
this.name = _name
this.protocol = _protocol
this.host = _host
this.port = _port
this.blockchain = blockchain
this.chainId = chainId.toString()
}

static placeholder(){ return new Network() }

static fromJson(json){
const p = Object.assign(Network.placeholder(), json)
p.chainId = p.chainId ? p.chainId.toString() : ''
return p
}

static fromUnique(netString){
const blockchain = netString.split(':')[0]
if (netString.indexOf(':chain:') > -1) return new Network('', '', '', '', blockchain, netString.replace(`${blockchain}:chain:`, ''))

const splits = netString.replace(`${blockchain}:`, '').split(':')
return new Network('', '', splits[0], parseInt(splits[1] || 80, 10), blockchain)
}

unique(){ return (`${this.blockchain}:${this.chainId.length ? `chain:${this.chainId}` : `${this.host}:${this.port}`}`).toLowerCase() }

hostport(){ return `${this.host}${this.port ? ':' : ''}${this.port}` }

fullhost(){ return `${this.protocol}://${this.host}${this.port ? ':' : ''}${this.port}` }

clone(){ return Network.fromJson(JSON.parse(JSON.stringify(this))) }

isEmpty(){ return !this.host.length }

isValid(){ return (this.host.length && this.port) || this.chainId.length }
}
11 changes: 11 additions & 0 deletions shared/core/scatter/NetworkMessageTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const ERROR = 'error';
export const PUSH_SCATTER = 'pushScatter';
export const GET_OR_REQUEST_IDENTITY = 'getOrRequestIdentity';
export const IDENTITY_FROM_PERMISSIONS = 'identityFromPermissions';
export const FORGET_IDENTITY = 'forgetIdentity';
export const REQUEST_SIGNATURE = 'requestSignature';
export const ABI_CACHE = 'abiCache';
export const REQUEST_ARBITRARY_SIGNATURE = 'requestArbitrarySignature';
export const REQUEST_ADD_NETWORK = 'requestAddNetwork';
export const REQUEST_VERSION_UPDATE = 'requestVersionUpdate';
export const AUTHENTICATE = 'authenticate';
85 changes: 85 additions & 0 deletions shared/core/scatter/ObjectHelpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/***
* A set of helpers for Objects/Arrays
*/
export default class ObjectHelpers {
/***
* Groups an array by key
* @param array
* @param key
* @returns {*}
*/
static groupBy(array, key){
return array.reduce((acc, item) => {
(acc[item[key]] = acc[item[key]] || []).push(item);
return acc;
}, {});
}

/***
* Makes a single level array distinct
* @param array
* @returns {*}
*/
static distinct(array){
return array.reduce((a, b) => ((a.includes(b)) ? a : a.concat(b)), []);
}

/***
* Makes an object array distinct ( uses deep checking )
* @param array
* @returns {*}
*/
static distinctObjectArray(array){
return array.reduce((a, b) => ((a.find(x => this.deepEqual(x, b))) ? a : a.concat(b)), []);
}

/***
* Checks deep equality for objects
* @param objA
* @param objB
* @returns {boolean}
*/
static deepEqual(objA, objB) {
const keys = Object.keys
const typeA = typeof objA
const typeB = typeof objB
return objA && objB && typeA === 'object' && typeA === typeB ? (
keys(objA).length === keys(objB).length
&& keys(objA).every(key => this.deepEqual(objA[key], objB[key]))
) : (objA === objB);
}

/***
* Flattens an array into a single dimension
* @param array
* @returns {*}
*/
static flatten(array){
return array.reduce(
(a, b) => a.concat(Array.isArray(b) ? this.flatten(b) : b), []
);
}

/***
* Flattens an objects keys into a single dimension
* @param object
* @returns {*}
*/
static objectToFlatKeys(object){
return this.flatten(Object.keys(object).map((key) => {
if (object[key] !== null && typeof object[key] === 'object') return this.objectToFlatKeys(object[key])
else return key;
}))
}

/***
* Gets a field from an object by string dot notation, such as `location.country.code`
* @param object
* @param dotNotation
* @returns {*}
*/
static getFieldFromObjectByDotNotation(object, dotNotation){
const props = dotNotation.split('.');
return props.reduce((obj, key) => obj[key], object)
}
}
6 changes: 6 additions & 0 deletions shared/core/scatter/Plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default class Plugin {
constructor(_name = '', _type = ''){
this.name = _name;
this.type = _type;
}
}
1 change: 1 addition & 0 deletions shared/core/scatter/PluginTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const BLOCKCHAIN_SUPPORT = 'blockchain_support';
Loading

0 comments on commit 8a5ec2d

Please sign in to comment.