Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEP5 #370

Merged
merged 89 commits into from
Nov 29, 2017
Merged

NEP5 #370

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
d7e25f8
Fix for: Password is displayed as visible text when creating wallet #…
slipo Nov 22, 2017
5bbd312
Fix for: Give warning when API is down or wallet lacks connectivity #…
slipo Nov 22, 2017
3882ff5
Fix lint errors and refactor
evgenyboxer Nov 23, 2017
2dce865
Remove RPX from reducers
evgenyboxer Nov 23, 2017
f0bcfc6
Move loading indicator to the top
evgenyboxer Nov 23, 2017
76eef8d
hide scrollbars
evgenyboxer Nov 23, 2017
3aec2de
finetune the buttons
evgenyboxer Nov 23, 2017
c816882
Move the refresh button code to Dashboard.scss
evgenyboxer Nov 23, 2017
fbe3619
Remove unused styles
evgenyboxer Nov 23, 2017
5a7cf69
Split token balances into its own component
evgenyboxer Nov 23, 2017
b6f8764
Add info icon
evgenyboxer Nov 23, 2017
2b55120
add tokens balance to initiateGetBalance
evgenyboxer Nov 23, 2017
352495d
Remove unused methods
evgenyboxer Nov 23, 2017
f624e8c
POC tokenInfo
evgenyboxer Nov 23, 2017
332422f
Use PasswordField for WIF key in secret token sale screen (#351)
slipo Nov 24, 2017
4d2a023
Add token info modal and refactor the tokens state
evgenyboxer Nov 24, 2017
b3b0d73
Update snapshots
evgenyboxer Nov 24, 2017
83c6277
Remove uneeded code
evgenyboxer Nov 24, 2017
8ffc0a5
Better formatting (#350)
slipo Nov 24, 2017
e90dbde
Remove exclamation that's not needed in UI (#353)
slipo Nov 24, 2017
e308653
Enter in textfields submits alt (#354)
slipo Nov 24, 2017
e0f7677
Merge with dev
evgenyboxer Nov 25, 2017
b89cba2
Use tight version
evgenyboxer Nov 25, 2017
ff5f20a
Remove unused function
evgenyboxer Nov 25, 2017
2aaa996
Remove comment
evgenyboxer Nov 25, 2017
1286029
Remove ToggleAsset
evgenyboxer Nov 25, 2017
fe0df7b
Rename Gas -> GAS / Neo -> NEO
evgenyboxer Nov 25, 2017
0149f82
Add isToken method
evgenyboxer Nov 25, 2017
710aaf1
WIP
evgenyboxer Nov 25, 2017
b2ea451
Use tight versioning
evgenyboxer Nov 26, 2017
416102a
WIP
evgenyboxer Nov 26, 2017
d4ff9da
Rename rpx to sale, and clean it up
evgenyboxer Nov 26, 2017
104f250
Rename reducers to index
evgenyboxer Nov 26, 2017
8526f94
Fix paths
evgenyboxer Nov 26, 2017
8d2fffe
Add flow
evgenyboxer Nov 26, 2017
2e52331
Add flow
evgenyboxer Nov 26, 2017
c60090c
cleanups
evgenyboxer Nov 26, 2017
3c362e5
Rename initiateGetBalance to LoadWalletData
evgenyboxer Nov 26, 2017
18f49de
Add TokenInfo type
evgenyboxer Nov 26, 2017
e22ee9d
Fix tests
evgenyboxer Nov 26, 2017
4f99d75
Refactor prices (to support in the future)
evgenyboxer Nov 26, 2017
952ac1a
Add Type suffix for types
evgenyboxer Nov 26, 2017
5b27255
Cleanup
evgenyboxer Nov 26, 2017
5cbd766
Cleanup
evgenyboxer Nov 26, 2017
dbd4f67
Cleanup
evgenyboxer Nov 26, 2017
32a6a3a
Fix typo
evgenyboxer Nov 26, 2017
8f49178
Use neon-js constants
evgenyboxer Nov 26, 2017
5bb4216
Add support for test tokens
evgenyboxer Nov 26, 2017
63ca809
Add percent buttons
evgenyboxer Nov 26, 2017
c615d19
Fix token sale
evgenyboxer Nov 26, 2017
0946ef1
Sort imports
evgenyboxer Nov 26, 2017
0e87216
Fix typo
evgenyboxer Nov 26, 2017
c8872c5
Revert back to not using NeonJS for Network
evgenyboxer Nov 26, 2017
550d31b
Remove unsued functions
evgenyboxer Nov 26, 2017
ef0ddc3
Fix lint errors
evgenyboxer Nov 26, 2017
dcec15a
Refactor explorer
evgenyboxer Nov 26, 2017
03b4e43
Fix typo
evgenyboxer Nov 26, 2017
acde320
Revert back to local consts for ASSETS
evgenyboxer Nov 26, 2017
fc92c62
Load info when modal loads
evgenyboxer Nov 26, 2017
3d6d85f
Rename to openExplorerTx
evgenyboxer Nov 26, 2017
eea5ede
Pass retrieveTokenInfo to the token info modal
evgenyboxer Nov 26, 2017
93589cf
WIP
evgenyboxer Nov 26, 2017
ba8527b
Change token to symbol
evgenyboxer Nov 26, 2017
10f270f
Add flow-typed for npm modules
evgenyboxer Nov 27, 2017
5f932ea
Move declarations upper level
evgenyboxer Nov 27, 2017
923646e
Correct GAS decimal length
evgenyboxer Nov 27, 2017
3a4c4cb
Fix token info modal
evgenyboxer Nov 27, 2017
de0db4c
Symbol > Asset
evgenyboxer Nov 27, 2017
91dfd34
Add a border to the dashboard
evgenyboxer Nov 27, 2017
cb9604f
Disable claim when claim amount is 0
evgenyboxer Nov 27, 2017
0210c28
Fix lint errors
evgenyboxer Nov 27, 2017
0514e49
Resolve conflicts
evgenyboxer Nov 27, 2017
0ffae15
Merge and resolve conflicts
evgenyboxer Nov 27, 2017
1ba7723
Fix recieve modal height
evgenyboxer Nov 28, 2017
d63a335
format balance
evgenyboxer Nov 28, 2017
1cc41e0
Preload token info when getting token balance (if it doesn't exist)
evgenyboxer Nov 28, 2017
4497edb
Refactor formatters
evgenyboxer Nov 28, 2017
57bb7ac
Drop the state and grab the info from the token props
evgenyboxer Nov 28, 2017
e11bb3b
Add number formatting
evgenyboxer Nov 28, 2017
e6aa708
Use truncateToken
evgenyboxer Nov 28, 2017
fccd770
Rename formatNumber to formatBalance
evgenyboxer Nov 28, 2017
84751ed
Fix obtainTokenBalance
evgenyboxer Nov 28, 2017
930ae05
Increase modal size to show full address
evgenyboxer Nov 28, 2017
b3b058a
Fix sending NEO/GAS
evgenyboxer Nov 28, 2017
4fc431c
Remove unused functions/reducers
evgenyboxer Nov 29, 2017
9a280dd
Remove unused state
evgenyboxer Nov 29, 2017
8aa2dbc
Fix CopyToClipboard + Tooltips
evgenyboxer Nov 29, 2017
c352d09
hash lint error for now
evgenyboxer Nov 29, 2017
3d26667
Fix creating a new wallet
evgenyboxer Nov 29, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 7 additions & 39 deletions __tests__/modules/generateWallet.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import generateWalletReducer, { newWalletKeys, newWallet, generating, resetKey, NEW_WALLET_KEYS, NEW_WALLET, SET_GENERATING, RESET_KEY } from '../../app/modules/generateWallet'
import generateWalletReducer, {
newWallet,
resetKey,
NEW_WALLET,
RESET_KEY
} from '../../app/modules/generateWallet'

describe('generateWallet module tests', () => {
// TODO when looking into pulling axios mock adapter into helper file to stay DRY
Expand All @@ -12,8 +17,7 @@ describe('generateWallet module tests', () => {
wif: null,
address: null,
passphrase: null,
encryptedWif: null,
generating: false
encryptedWif: null
}

const account = {
Expand Down Expand Up @@ -41,42 +45,6 @@ describe('generateWallet module tests', () => {
})
})

describe('newWalletKeys tests', () => {
const expectedAction = {
type: NEW_WALLET_KEYS,
payload: {
passphrase
}
}

test('newWalletKeys action works', () => {
expect(newWalletKeys(passphrase)).toEqual(expectedAction)
})

test('generateWallet reducer should handle NEW_WALLET_KEYS', () => {
const expectedState = Object.assign({}, initialState, account)
expect(generateWalletReducer(undefined, expectedAction)).toEqual(expectedState)
})
})

describe('generating tests', () => {
const expectedAction = {
type: SET_GENERATING,
payload: {
generating: true
}
}

test('generating action works', () => {
expect(generating(true)).toEqual(expectedAction)
})

test('generateWallet reducer should handle SET_GENERATING', () => {
const expectedState = Object.assign({}, initialState, { generating: true })
expect(generateWalletReducer(undefined, expectedAction)).toEqual(expectedState)
})
})

describe('resetKey tests', () => {
const expectedAction = { type: RESET_KEY }

Expand Down
6 changes: 3 additions & 3 deletions app/components/DisplayWalletKeys/DisplayWalletKeys.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ class DisplayWalletKeys extends Component<Props, State> {
<div className='keyListItem'>
<span className='label'>Public Address:</span>
<span className='key'>{address}</span>
<CopyToClipboard text={address} tooltip='Copy Public Key' />
<CopyToClipboard text={address} tooltip='Copy Public Address' />
</div>
<div className='keyListItem'>
<span className='label'>Encrypted key:</span>
<span className='key'>{passphraseKey}</span>
<CopyToClipboard text={passphraseKey} tooltip='Copy Passphrase Encrypted Key' />
<CopyToClipboard text={passphraseKey} tooltip='Copy Encrypted Key' />
</div>
<div className='keyListItem'>
<span className='label'>Private Key:</span>
<span className='key'>{wif}</span>
<CopyToClipboard text={passphraseKey} tooltip='Copy Private Key' />
<CopyToClipboard text={wif} tooltip='Copy Private Key' />
</div>
</div>
<div className='saveKey'>
Expand Down
8 changes: 4 additions & 4 deletions app/components/Modals/ReceiveModal/ReceiveModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class ReceiveModal extends Component<Props> {
if (err) console.log(err)
})
}}
title='NEO/GAS Wallet Address'
title='NEO Wallet Address'
hideModal={hideModal}
style={{
content: {
width: '420px',
height: '390px'
height: '420px'
}
}}
>
Expand All @@ -38,8 +38,8 @@ class ReceiveModal extends Component<Props> {
<CopyToClipboard text={address} tooltip='Copy Public Address' />
</div>
<div className={styles.canvas}><canvas ref={(node) => { this.canvas = node }} /></div>
<div>Only send NEO/GAS to this address</div>
<div>Sending any other digital asset will result in permanent loss.</div>
<div>Only send assets, such as NEO and GAS, and tokens, such as RPX, that are compatible with the NEO Blockchain.</div>
<div>Sending any other digital asset or token will result in permanent loss.</div>
</div>
</BaseModal>
)
Expand Down
25 changes: 19 additions & 6 deletions app/components/Modals/SendModal/SendDisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React from 'react'
import classNames from 'classnames'

import { ASSETS } from '../../../core/constants'
import { isToken } from '../../../core/wallet'
import { formatBalance, formatGAS, formatNEO, truncateGAS, truncateTokenBalance } from '../../../core/formatters'

import styles from './SendModal.scss'

Expand Down Expand Up @@ -49,11 +51,20 @@ const SendDisplay = ({
</div>
<div className={styles.percentRow}>
{[25, 50, 75, 100].map((percent: number) => {
const value = percent * parseFloat(balance) / 100
return (<button
key={`percentButton${percent}`}
onClick={() => onChangeHandler('sendAmount', symbol === ASSETS.NEO ? Math.ceil(value) : value)}
className={styles.percentButton}>{percent}%</button>)
let value = percent * parseFloat(balance) / 100
if (symbol === ASSETS.NEO) {
value = Math.ceil(value)
} else if (symbol === ASSETS.GAS) {
value = truncateGAS(value)
} else {
value = truncateTokenBalance(value, tokens[symbol].info.decimals)
}
return (
<button
key={`percentButton${percent}`}
onClick={() => onChangeHandler('sendAmount', symbol === ASSETS.NEO ? Math.ceil(value) : value)}
className={styles.percentButton}>{percent}%</button>
)
})}
</div>
<div id='sendAmount' className={styles.column}>
Expand All @@ -71,7 +82,9 @@ const SendDisplay = ({
</div>
<div id='sendAmount' className={styles.column}>
<label className={styles.label}>Balance:</label>
{balance}
{symbol === ASSETS.NEO && formatNEO(balance)}
{symbol === ASSETS.GAS && formatGAS(balance)}
{isToken(symbol) && formatBalance(balance, tokens[symbol].info.decimals)}
</div>
<button className={classNames(styles.sendButton, {'disabled': sendButtonDisabled})} id='doSend' onClick={openAndValidate} disabled={sendButtonDisabled}>Send Asset</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/components/Modals/SendModal/SendModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class SendModal extends Component<Props, State> {
hideModal={hideModal}
style={{
content: {
width: '460px',
width: '480px',
height: '410px'
}
}}
Expand Down
117 changes: 42 additions & 75 deletions app/components/Modals/TokenInfoModal/TokenInfoModal.jsx
Original file line number Diff line number Diff line change
@@ -1,89 +1,56 @@
// @flow
import React, { Component } from 'react'
import numeral from 'numeral'
import React from 'react'

import BaseModal from '../BaseModal'
import Table from '../../Table'
import Loader from '../../Loader'

import { formatBalance } from '../../../core/formatters'

import styles from './TokenInfoModal.scss'

type Props = {
hideModal: Function,
token: TokenWithInfoType,
retrieveTokenInfo: Function
}

type State = {
token: TokenWithInfoType
}

class TokenInfoModal extends Component<Props, State> {
state = {
token: this.props.token
}

onAfterOpen = () => {
const { retrieveTokenInfo, token } = this.props
if (!token.info) {
retrieveTokenInfo(token.symbol).then((info) => {
this.setState({
token: {
...token,
info
}
})
})
}
}

render () {
const { hideModal } = this.props
const { token } = this.state

return (
<BaseModal
onAfterOpen={this.onAfterOpen}
title='Token Info'
hideModal={hideModal}
style={{
content: {
width: '350px',
height: '250px'
}
}}
>
<div className={styles.container}>
{!token.info ? <Loader /> : (
<Table>
<tbody>
<tr>
<td>Symbol:</td>
<td>{token.symbol}</td>
</tr>
<tr>
<td>Name:</td>
<td>{token.info.name}</td>
</tr>
<tr>
<td>Total Supply:</td>
<td>{numeral(token.info.totalSupply).format('0,0')}</td>
</tr>
<tr>
<td>Decimals</td>
<td>{token.info.decimals}</td>
</tr>
<tr>
<td>Balance</td>
<td>{token.balance}</td>
</tr>
</tbody>
</Table>
)}
</div>
</BaseModal>
)
}
}
const TokenInfoModal = ({ hideModal, token }: Props) => (
<BaseModal
title='Token Info'
hideModal={hideModal}
style={{
content: {
width: '350px',
height: '250px'
}
}}
>
<div className={styles.container}>
<Table>
<tbody>
<tr>
<td>Symbol:</td>
<td>{token.symbol}</td>
</tr>
<tr>
<td>Name:</td>
<td>{token.info.name}</td>
</tr>
<tr>
<td>Total Supply:</td>
<td>{formatBalance(token.info.totalSupply)}</td>
</tr>
<tr>
<td>Decimals</td>
<td>{token.info.decimals}</td>
</tr>
<tr>
<td>Balance</td>
<td>{formatBalance(token.balance, token.info.decimals)}</td>
</tr>
</tbody>
</Table>
</div>
</BaseModal>
)

export default TokenInfoModal
6 changes: 2 additions & 4 deletions app/containers/CreateWallet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
getWif,
getAddress,
getEncryptedWif,
getPassphrase,
getGenerating
getPassphrase
} from '../../modules/generateWallet'

import CreateWallet from './CreateWallet'
Expand All @@ -19,8 +18,7 @@ const mapStateToProps = (state: Object) => ({
wif: getWif(state),
address: getAddress(state),
encryptedWif: getEncryptedWif(state),
passphrase: getPassphrase(state),
generating: getGenerating(state)
passphrase: getPassphrase(state)
})

const actionCreators = {
Expand Down
6 changes: 2 additions & 4 deletions app/containers/EncryptKey/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
getWif,
getAddress,
getEncryptedWif,
getPassphrase,
getGenerating
getPassphrase
} from '../../modules/generateWallet'

import EncryptKey from './EncryptKey'
Expand All @@ -19,8 +18,7 @@ const mapStateToProps = (state: Object) => ({
wif: getWif(state),
address: getAddress(state),
encryptedWif: getEncryptedWif(state),
passphrase: getPassphrase(state),
generating: getGenerating(state)
passphrase: getPassphrase(state)
})

const actionCreators = {
Expand Down
5 changes: 3 additions & 2 deletions app/containers/WalletInfo/TokensBalance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react'
import Table from '../../components/Table'

import { MODAL_TYPES } from '../../core/constants'
import { formatBalance } from '../../core/formatters'

import InfoOutline from 'react-icons/lib/md/info-outline'

Expand All @@ -26,15 +27,15 @@ const tokens = ({ tokens, showModal, retrieveTokenInfo }: Props) => (
<tbody>
{Object.keys(tokens).map((symbol) => {
const token = tokens[symbol]
const { balance } = token
const { balance, info } = token
return (
<tr key={symbol}>
<td
className={styles.symbol}
onClick={() => showModal(MODAL_TYPES.TOKEN_INFO, { token, retrieveTokenInfo })}>
<InfoOutline className={styles.symbolIcon} />{symbol}
</td>
<td>{balance}</td>
<td>{info ? formatBalance(balance, info.decimals) : balance}</td>
</tr>
)
})}
Expand Down
18 changes: 14 additions & 4 deletions app/core/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@
import { truncateNumber } from './math'
import numeral from 'numeral'

const DEFAULT_DECIMAL_LENGTH = 8
const GAS_DECIMAL_LENGTH = 8
const GAS_DECIMAL_SHORT_DISPLAY_LENGTH = 4

export const formatBalance = (value: number | string, precision?: number) => {
return precision
? numeral(value).format('0,0.' + Array(precision + 1).join('0'))
: numeral(value).format('0,0')
}

export const truncateTokenBalance = (value: number | string, precision?: number = DEFAULT_DECIMAL_LENGTH) => truncateNumber(parseFloat(value), precision).toFixed(precision)

export const truncateGAS = (gas: number | string, precision?: number = GAS_DECIMAL_LENGTH) => truncateTokenBalance(gas, precision)

export const formatGAS = (gas: number | string, shortDisplay: boolean = false): string => {
const decimalLength = shortDisplay ? GAS_DECIMAL_SHORT_DISPLAY_LENGTH : GAS_DECIMAL_LENGTH
const customTruncatedNumber = truncateNumber(parseFloat(gas), decimalLength).toFixed(decimalLength)
return numeral(customTruncatedNumber).format('0,0.' + Array(decimalLength + 1).join('0'))
const precision = shortDisplay ? GAS_DECIMAL_SHORT_DISPLAY_LENGTH : GAS_DECIMAL_LENGTH
return formatBalance(truncateGAS(gas, precision), precision)
}

export const formatNEO = (neo: number | string): string => numeral(neo).format('0,0')
export const formatNEO = (neo: number | string): string => formatBalance(neo)

export const formatFiat = (value: number | string): string => numeral(value).format('0,0.00')
Loading