Skip to content

Commit

Permalink
feat: Remove miner info feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ashchan committed Nov 2, 2019
1 parent 07dc1b3 commit 4dcdad4
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 143 deletions.
102 changes: 4 additions & 98 deletions packages/neuron-ui/src/components/WalletSetting/index.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
import React, { useState, useCallback, useMemo } from 'react'
import React, { useCallback } from 'react'
import { RouteComponentProps } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import {
Stack,
PrimaryButton,
ChoiceGroup,
IChoiceGroupOption,
Text,
Callout,
MessageBar,
MessageBarType,
ActionButton,
getTheme,
} from 'office-ui-fabric-react'
import { Stack, PrimaryButton, ChoiceGroup, IChoiceGroupOption } from 'office-ui-fabric-react'

import { StateWithDispatch } from 'states/stateProvider/reducer'
import { setCurrentWallet, addPopup } from 'states/stateProvider/actionCreators'
import { setCurrentWallet } from 'states/stateProvider/actionCreators'

import { WalletWizardPath } from 'components/WalletWizard'

import { contextMenu } from 'services/remote'
import { Routes, MnemonicAction, ErrorCode } from 'utils/const'

const theme = getTheme()
import { Routes, MnemonicAction } from 'utils/const'

const buttons = [
{
Expand All @@ -41,33 +28,11 @@ const buttons = [

const WalletSetting = ({
wallet: { id: currentID = '' },
chain: { codeHash = '' },
settings: { wallets = [] },
dispatch,
history,
}: React.PropsWithoutRef<StateWithDispatch & RouteComponentProps>) => {
const [t] = useTranslation()
const [target, setTarget] = useState<any>(null)
const [minerInfo, setMinerInfo] = useState<{ address: string; identifier: string }>({
address: '',
identifier: '',
})

const [showMinerInfo, hideMinerInfo] = useMemo(
() => [
(info: { address: string; identifier: string }) => setMinerInfo(info),
() => setMinerInfo({ address: '', identifier: '' }),
],
[setMinerInfo]
)

const onCopyPubkeyHash = useCallback(() => {
if (minerInfo) {
window.navigator.clipboard.writeText(minerInfo.identifier)
hideMinerInfo()
addPopup('lock-arg-copied')(dispatch)
}
}, [minerInfo, hideMinerInfo, dispatch])

const onChange = useCallback(
(_e, option) => {
Expand Down Expand Up @@ -105,24 +70,6 @@ const WalletSetting = ({
<span className="ms-ChoiceFieldLabel" onContextMenu={onContextMenu(wallet.id)}>
{text}
</span>
{wallet.minerAddress ? (
<Text
variant="tiny"
className="ms-ChoiceFieldLabel"
onClick={(e: React.MouseEvent<HTMLDivElement>) => {
e.preventDefault()
setTarget(e.target)
if (wallet.minerAddress) {
showMinerInfo(wallet.minerAddress)
}
}}
styles={{
root: [{ color: theme.semanticColors.bodySubtext, fontSize: '12px!important' }],
}}
>
{t('overview.miner-info')}
</Text>
) : null}
</Stack>
)
},
Expand All @@ -135,47 +82,6 @@ const WalletSetting = ({
<PrimaryButton key={label} onClick={navTo(url)} text={t(label)} />
))}
</Stack>
<Callout target={target} hidden={!minerInfo.address} onDismiss={hideMinerInfo} gapSpace={0}>
<Stack tokens={{ padding: 15 }}>
{minerInfo.address ? (
<Stack tokens={{ childrenGap: 15 }} styles={{ root: { padding: 5 } }}>
<Stack tokens={{ childrenGap: 15 }}>
<Text variant="small" style={{ fontWeight: 600 }}>
{t('overview.address')}
</Text>
<Text variant="small" className="monospacedFont">
{minerInfo.address}
</Text>
</Stack>
<Stack tokens={{ childrenGap: 15 }}>
<Text variant="small" style={{ fontWeight: 600 }}>
{t('overview.code-hash')}
</Text>
<Text variant="small" className="monospacedFont">
{codeHash}
</Text>
</Stack>
<Stack tokens={{ childrenGap: 15 }}>
<Text variant="small" style={{ fontWeight: 600 }}>
{t('overview.lock-arg')}
</Text>
<Text variant="small" className="monospacedFont">
{minerInfo.identifier}
</Text>
</Stack>
<Stack horizontalAlign="end">
<ActionButton iconProps={{ iconName: 'MiniCopy' }} onClick={onCopyPubkeyHash}>
{t('overview.copy-pubkey-hash')}
</ActionButton>
</Stack>
</Stack>
) : (
<MessageBar messageBarType={MessageBarType.error}>
{t(`messages.codes.${ErrorCode.FieldNotFound}`, { fieldName: `default-address` })}
</MessageBar>
)}
</Stack>
</Callout>
</Stack>
)
}
Expand Down
5 changes: 0 additions & 5 deletions packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
"tip-block-number": "Block Number",
"epoch": "Epoch",
"difficulty": "Difficulty",
"miner-info": "Miner Info",
"lock-arg": "Lock Arg",
"address": "Address",
"code-hash": "Code Hash",
"copy-pubkey-hash": "Copy Lock Arg (Pubkey Hash)",
"confirmation": "{{confirmationCount}} Confirmation",
"confirmations": "{{confirmationCount}} Confirmations",
"sent": "Sent",
Expand Down Expand Up @@ -260,7 +256,6 @@
"update-network-successfully": "The network was updated",
"addr-copied": "Address has been copied to the clipboard",
"qrcode-copied": "QR Code has been copied to the clipboard",
"lock-arg-copied": "Lock Arg has been copied to the clipboard",
"fields": {
"wallet": "Wallet",
"name": "Name",
Expand Down
5 changes: 0 additions & 5 deletions packages/neuron-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
"tip-block-number": "区块高度",
"epoch": "Epoch",
"difficulty": "难度",
"miner-info": "挖矿信息",
"lock-arg": "Lock Arg",
"address": "地址",
"code-hash": "Code Hash",
"copy-pubkey-hash": "复制 Lock Arg (Pubkey Hash)",
"confirmation": "{{confirmationCount}} 个确认",
"confirmations": "{{confirmationCount}} 个确认",
"sent": "已发送",
Expand Down Expand Up @@ -260,7 +256,6 @@
"update-network-successfully": "已更新节点信息",
"addr-copied": "已复制地址到剪贴板",
"qrcode-copied": "已复制二维码到剪贴板",
"lock-arg-copied": "已复制 Lock Arg 到剪贴板",
"fields": {
"wallet": "钱包",
"name": "名称",
Expand Down
1 change: 0 additions & 1 deletion packages/neuron-ui/src/types/App/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ declare namespace State {
interface WalletIdentity {
id: string
name: string
minerAddress?: { address: string; identifier: string }
}

interface Address {
Expand Down
18 changes: 1 addition & 17 deletions packages/neuron-wallet/src/controllers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,6 @@ export default class ApiController {
}),
])

const minerAddresses = await Promise.all(
wallets.map(({ id }) =>
WalletsController.getAllAddresses(id).then(addrRes => {
if (addrRes.result) {
const minerAddr = addrRes.result.find(addr => addr.type === 0 && addr.index === 0)
if (minerAddr) {
return {
address: minerAddr.address,
identifier: minerAddr.identifier,
}
}
}
return undefined
}),
),
)
const addresses: Controller.Address[] = await (currentWallet
? WalletsController.getAllAddresses(currentWallet.id).then(res => res.result)
: [])
Expand All @@ -102,7 +86,7 @@ export default class ApiController {

const initState = {
currentWallet,
wallets: [...wallets.map(({ name, id }, idx: number) => ({ id, name, minerAddress: minerAddresses[idx] }))],
wallets: [...wallets.map(({ name, id }) => ({ id, name }))],
currentNetworkID,
networks,
addresses,
Expand Down
18 changes: 1 addition & 17 deletions packages/neuron-wallet/src/controllers/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,9 @@ export default class WalletsController {
if (!wallets) {
throw new ServiceHasNoResponse('Wallet')
}
const minerAddresses = await Promise.all(
wallets.map(({ id }) =>
WalletsController.getAllAddresses(id).then(addrRes => {
if (addrRes.result) {
const minerAddr = addrRes.result.find(addr => addr.type === 0 && addr.index === 0)
if (minerAddr) {
return {
address: minerAddr.address,
identifier: minerAddr.identifier,
}
}
}
return undefined
})
)
)
return {
status: ResponseCode.Success,
result: wallets.map(({ name, id }, idx) => ({ name, id, minerAddress: minerAddresses[idx] })),
result: wallets.map(({ name, id }) => ({ name, id })),
}
}

Expand Down

0 comments on commit 4dcdad4

Please sign in to comment.