Skip to content

Commit

Permalink
feat: enable copy the mainnet addresses when it's not connected to th…
Browse files Browse the repository at this point in the history
…e mainnet
  • Loading branch information
Keith-CY committed Sep 27, 2019
1 parent 92e538a commit 6b3952f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/neuron-ui/src/components/Addresses/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ const Addresses = ({
: addr.address,
}))}
onItemContextMenu={item => {
if (!showMainnetAddress) {
if (showMainnetAddress) {
contextMenu({ type: 'copyMainnetAddress', id: item.identifier })
} else {
contextMenu({ type: 'addressList', id: item.identifier })
}
}}
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-wallet/src/controllers/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export default class AppController {
}
const { id, type } = params
switch (type) {
case 'copyMainnetAddress':
case 'networkList':
case 'walletList':
case 'addressList':
Expand Down
17 changes: 16 additions & 1 deletion packages/neuron-wallet/src/controllers/app/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MenuItemConstructorOptions, clipboard, dialog, MessageBoxReturnValue } from 'electron'
import { bech32Address } from '@nervosnetwork/ckb-sdk-utils'
import { bech32Address, AddressPrefix, AddressType } from '@nervosnetwork/ckb-sdk-utils'

import WalletsService from 'services/wallets'
import NetworksService from 'services/networks'
Expand All @@ -19,6 +19,21 @@ const networksService = NetworksService.getInstance()
export const contextMenuTemplate: {
[key: string]: (id: string) => Promise<MenuItemConstructorOptions[]>
} = {
copyMainnetAddress: async (identifier: string) => {
const address = bech32Address(identifier, {
prefix: AddressPrefix.Mainnet,
type: AddressType.HashIdx,
codeHashIndex: '0x00',
})
return [
{
label: i18n.t('contextMenu.copy-address'),
click: () => {
clipboard.writeText(address)
},
},
]
},
networkList: async (id: string) => {
const [network, currentNetworkID] = await Promise.all([
networksService.get(id).catch(() => null),
Expand Down

0 comments on commit 6b3952f

Please sign in to comment.