Skip to content

Commit

Permalink
Merge pull request #367 from z3us-dapps/feat/babylon-acc-export-v1
Browse files Browse the repository at this point in the history
Handle extended private key exports
  • Loading branch information
heathsnee authored Sep 13, 2023
2 parents 1961626 + e13499d commit c514a3d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "z3us-extension",
"version": "1.0.46",
"version": "1.0.47",
"scripts": {
"dev": "yarn start",
"start": "vite --mode development",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import HDNode from 'hdkey'
import { QRCodeSVG } from 'qrcode.react'
import React, { useRef } from 'react'
import { useImmer } from 'use-immer'
Expand Down Expand Up @@ -76,6 +77,7 @@ export const exportAsCode = (accounts: string[], payloadSize: number, mnemonicLe
interface ImmerT {
words: string[]
exports: string[]
privateExtendedKey: string
password: string
errorMessage: string
isQrModalOpen: boolean
Expand All @@ -96,6 +98,7 @@ const AccountExport: React.FC = () => {
const [state, setState] = useImmer<ImmerT>({
words: [],
exports: [],
privateExtendedKey: '',
password: '',
errorMessage: '',
isQrModalOpen: false,
Expand All @@ -107,14 +110,15 @@ const AccountExport: React.FC = () => {
draft.isExportingAccounts = true
})
try {
const { mnemonic } = await getWallet(state.password)
const { mnemonic, hdMasterNode } = await getWallet(state.password)
const summaries = []
Object.keys(publicAddresses).forEach(idx =>
summaries.push(accountSummary(publicAddresses[idx], +idx, keystore.type === KeystoreType.LOCAL)),
)
const exports = exportAsCode(summaries, 1800, mnemonic?.words.length || 24)
setState(draft => {
draft.words = mnemonic?.words || []
draft.privateExtendedKey = hdMasterNode ? HDNode.fromJSON(hdMasterNode).privateExtendedKey.toString() : ''
draft.exports = exports
draft.isQrModalOpen = true
})
Expand Down Expand Up @@ -241,6 +245,22 @@ const AccountExport: React.FC = () => {
</Flex>
</Box>
)}
{state.privateExtendedKey && (
<Box
css={{
background: '$bgPanel',
p: '$4',
pb: '30px',
br: '$2',
border: '1px solid $borderPanel',
position: 'relative',
}}
>
<Flex css={{ overflow: 'hidden', flexWrap: 'wrap', overflowWrap: 'anywhere' }}>
<Text size="4">{state.privateExtendedKey}</Text>
</Flex>
</Box>
)}
</Flex>
</Box>
<Box css={{ mt: '$2' }}>
Expand Down

0 comments on commit c514a3d

Please sign in to comment.