Browse Source

Add cache for addresses in existing Accounts

master
Loëck Vézien 7 years ago
parent
commit
025a6bbdcb
No known key found for this signature in database GPG Key ID: CBCDCE384E853AC4
  1. 2
      src/components/DashboardPage.js
  2. 1
      src/components/SideBar/Item.js
  3. 3
      src/components/base/Button/index.js
  4. 1
      src/components/base/Select/index.js
  5. 8
      src/helpers/btc.js
  6. 2
      src/renderer/events.js

2
src/components/DashboardPage.js

@ -123,7 +123,7 @@ class DashboardPage extends PureComponent<Props, State> {
align="center"
justify="center"
borderColor="mouse"
style={{ borderStyle: 'dashed', cursor: 'pointer' }}
style={{ borderStyle: 'dashed', cursor: 'pointer', textAlign: 'center' }}
onClick={() => openModal('add-account')}
>
{`+ ${t('addAccount.title')}`}

1
src/components/SideBar/Item.js

@ -10,7 +10,6 @@ import { connect } from 'react-redux'
import { openModal, isModalOpened } from 'reducers/modals'
import type { MapStateToProps } from 'react-redux'
import type { Element } from 'react'
import type { Location } from 'react-router'
import Box from 'components/base/Box'

3
src/components/base/Button/index.js

@ -13,6 +13,7 @@ const Base = styled.button.attrs({
${fontSize};
${fontWeight};
border-radius: 5px;
cursor: pointer;
border: none;
height: 40px;
box-shadow: ${p => (p.withShadow ? 'rgba(0, 0, 0, 0.2) 0 3px 10px' : '')};
@ -27,7 +28,7 @@ const Button = ({ primary, ...props }: Props) => {
if (primary) {
return <Base fontWeight="bold" color="white" bg="blue" withShadow {...props} />
}
return <Base {...props} />
return <Base color="white" {...props} />
}
Button.defaultProps = {

1
src/components/base/Select/index.js

@ -40,6 +40,7 @@ const TriggerBtn = styled(Box).attrs({
width: 100%;
color: ${p => p.theme.colors.steel};
background: ${p => p.theme.colors.white};
cursor: pointer;
&:focus {
outline: none;
box-shadow: rgba(0, 0, 0, 0.05) 0 2px 2px;

8
src/helpers/btc.js

@ -70,11 +70,13 @@ export function getTransactions(addresses: Array<string>) {
}
export async function getAccount({
allAddresses = [],
currentIndex = 0,
hdnode,
segwit,
network,
}: {
allAddresses?: Array<string>,
currentIndex?: number,
hdnode: Object,
segwit: boolean,
@ -84,7 +86,6 @@ export async function getAccount({
const script = segwit ? parseInt(network.scriptHash, 10) : parseInt(network.pubKeyHash, 10)
let transactions = []
let allAddresses = []
let lastAddress = null
const pubKeyToSegwitAddress = (pubKey, scriptVersion) => {
@ -135,7 +136,7 @@ export async function getAccount({
const addresses = results.reduce((result, v) => [...result, ...v], [])
const listAddresses = addresses.map(a => a.address)
allAddresses = [...allAddresses, ...listAddresses]
allAddresses = [...new Set([...allAddresses, ...listAddresses])]
const { txs } = await getTransactions(listAddresses)
@ -153,6 +154,7 @@ export async function getAccount({
result += v.balance
return result
}, 0),
allAddresses,
transactions,
...(lastAddress !== null
? {
@ -166,7 +168,7 @@ export async function getAccount({
}
})
if (currentIndex > 0) {
if (allAddresses.length === 0 && currentIndex > 0) {
for (let i = currentIndex; i--; ) {
allAddresses = [
...allAddresses,

2
src/renderer/events.js

@ -41,8 +41,10 @@ export function startSyncAccounts(accounts: Accounts) {
sendEvent('accounts', 'sync.all', {
accounts: Object.entries(accounts).map(([id, account]: [string, any]) => {
const currentIndex = get(account, 'data.currentIndex', 0)
const allAddresses = get(account, 'data.allAddresses', [])
return {
id,
allAddresses,
currentIndex,
}
}),

Loading…
Cancel
Save