Skip to content

Commit 8d714bc

Browse files
DennyWanyeiNorthIsle
authored andcommitted
feat: improve address formatting in keypair manage (#89)
1 parent 00bdb9a commit 8d714bc

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

packages/keypair/src/CreateKeypairModal.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from '@obsidians/ui-components'
1616

1717
import notification from '@obsidians/notification'
18+
import { utils } from '@obsidians/eth-sdk'
1819

1920
import keypairManager from './keypairManager'
2021

@@ -47,6 +48,7 @@ export default class CreateKeypairModal extends PureComponent {
4748

4849
regenerateKeypair = async () => {
4950
const keypair = await keypairManager.newKeypair(this.props.kp, this.state.chain, this.state.secretType)
51+
keypair.address = utils.simplifyAddress(keypair.address)
5052
this.setState({ keypair })
5153
}
5254

@@ -57,28 +59,30 @@ export default class CreateKeypairModal extends PureComponent {
5759
}
5860

5961
onConfirm = async () => {
60-
const { name, keypair } = this.state
62+
const {name, keypair} = this.state
6163

6264
if (!keypair) {
6365
this.onResolve()
6466
return
6567
}
6668

69+
keypair.address = utils.simplifyAddress(keypair.address)
70+
6771
if (this.props.keypairs.find(k => k.name === name)) {
6872
notification.error(
69-
`Create Keypair Failed`,
70-
`The keypair name <b>${name}</b> has already been used.`
73+
`Create Keypair Failed`,
74+
`The keypair name <b>${name}</b> has already been used.`
7175
)
7276
return
7377
}
7478

75-
this.setState({ pending: true })
79+
this.setState({pending: true})
7680
await keypairManager.saveKeypair(name, keypair)
77-
this.setState({ pending: false })
81+
this.setState({pending: false})
7882

7983
this.modal.current.closeModal()
8084
this.onResolve(true)
81-
}
85+
};
8286

8387
renderChainOptions = () => {
8488
const { chains } = this.props
@@ -156,7 +160,7 @@ export default class CreateKeypairModal extends PureComponent {
156160
<Badge pill color='info' className='ml-1'>Address</Badge>
157161
</div>
158162
<div className='col-10 pl-0'>
159-
<code className='user-select small'>{address}</code>
163+
<code className='user-select small'>{utils.formatAddress(address)}</code>
160164
</div>
161165
</div>
162166
<div className='row align-items-center'>

packages/keypair/src/ImportKeypairModal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@obsidians/ui-components'
99

1010
import notification from '@obsidians/notification'
11+
import { utils } from '@obsidians/eth-sdk'
1112

1213
import keypairManager from './keypairManager'
1314

@@ -60,7 +61,7 @@ export default class ImportKeypairModal extends PureComponent {
6061
this.setState({
6162
keypair,
6263
valid: true,
63-
feedback: <span>Address: <code>{keypair.address}</code></span>
64+
feedback: <span>Address: <code>{utils.formatAddress(keypair.address)}</code></span>
6465
})
6566
} catch (e) {
6667
console.warn(e)

packages/keypair/src/KeypairManagerModal.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '@obsidians/ui-components'
1010

1111
import notification from '@obsidians/notification'
12+
import { utils } from '@obsidians/eth-sdk'
1213

1314
import keypairManager from './keypairManager'
1415

@@ -59,6 +60,10 @@ export default class KeypairManagerModal extends PureComponent {
5960
async refresh () {
6061
this.setState({ loading: true })
6162
const keypairs = await keypairManager.loadAllKeypairs()
63+
keypairs.forEach(item=>{
64+
item.address = utils.simplifyAddress(item.address)
65+
})
66+
6267
this.setState({ keypairs, loading: false })
6368
}
6469

@@ -185,7 +190,7 @@ export default class KeypairManagerModal extends PureComponent {
185190
</td>
186191
<td>
187192
<div className='d-flex align-items-center'>
188-
<code className='small'>{keypair.address}</code>
193+
<code className='small'>{utils.formatAddress(keypair.address)}</code>
189194
<span className='text-transparent'>.</span>
190195
<DeleteButton
191196
color='primary'

packages/keypair/src/RevealSecretModal.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
} from '@obsidians/ui-components'
77

88
import keypairManager from './keypairManager'
9+
import { utils } from '@obsidians/eth-sdk'
10+
911

1012
export default class RevealSecretModal extends PureComponent {
1113
constructor (props) {
@@ -41,7 +43,7 @@ export default class RevealSecretModal extends PureComponent {
4143
<Badge pill color='info' className='ml-1'>Address</Badge>
4244
</div>
4345
<div className='col-10 pl-0'>
44-
<code className='user-select small'>{address}</code>
46+
<code className='user-select small'>{utils.formatAddress(address)}</code>
4547
</div>
4648
</div>
4749
<div className='row align-items-center'>

0 commit comments

Comments
 (0)