Skip to content

Commit 6b3952f

Browse files
committed
feat: enable copy the mainnet addresses when it's not connected to the mainnet
1 parent 92e538a commit 6b3952f

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

packages/neuron-ui/src/components/Addresses/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ const Addresses = ({
204204
: addr.address,
205205
}))}
206206
onItemContextMenu={item => {
207-
if (!showMainnetAddress) {
207+
if (showMainnetAddress) {
208+
contextMenu({ type: 'copyMainnetAddress', id: item.identifier })
209+
} else {
208210
contextMenu({ type: 'addressList', id: item.identifier })
209211
}
210212
}}

packages/neuron-wallet/src/controllers/app/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export default class AppController {
158158
}
159159
const { id, type } = params
160160
switch (type) {
161+
case 'copyMainnetAddress':
161162
case 'networkList':
162163
case 'walletList':
163164
case 'addressList':

packages/neuron-wallet/src/controllers/app/options.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MenuItemConstructorOptions, clipboard, dialog, MessageBoxReturnValue } from 'electron'
2-
import { bech32Address } from '@nervosnetwork/ckb-sdk-utils'
2+
import { bech32Address, AddressPrefix, AddressType } from '@nervosnetwork/ckb-sdk-utils'
33

44
import WalletsService from 'services/wallets'
55
import NetworksService from 'services/networks'
@@ -19,6 +19,21 @@ const networksService = NetworksService.getInstance()
1919
export const contextMenuTemplate: {
2020
[key: string]: (id: string) => Promise<MenuItemConstructorOptions[]>
2121
} = {
22+
copyMainnetAddress: async (identifier: string) => {
23+
const address = bech32Address(identifier, {
24+
prefix: AddressPrefix.Mainnet,
25+
type: AddressType.HashIdx,
26+
codeHashIndex: '0x00',
27+
})
28+
return [
29+
{
30+
label: i18n.t('contextMenu.copy-address'),
31+
click: () => {
32+
clipboard.writeText(address)
33+
},
34+
},
35+
]
36+
},
2237
networkList: async (id: string) => {
2338
const [network, currentNetworkID] = await Promise.all([
2439
networksService.get(id).catch(() => null),

0 commit comments

Comments
 (0)