Skip to content

Commit b08e99f

Browse files
committed
docs(importAccount add addressName): importAccount support add addressName
1 parent f7764b9 commit b08e99f

File tree

2 files changed

+17
-42
lines changed

2 files changed

+17
-42
lines changed

example/basic-dapp/index.html

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,30 +136,16 @@
136136
<input type="text" id=
137137
"import_address_input" placeholder="地址">
138138
</label>
139-
</form>
140-
<button id="import_address_button" disabled=
141-
"true">导入
142-
</button>
143-
<footer>
144-
Result: <span id="import_address_result">N/A</span>
145-
</footer>
146-
</article>
147-
148-
<article>
149-
<header>
150-
导入私钥
151-
</header>
152-
<form>
153-
<label>输入私钥用英文逗号风格分隔
139+
<label>地址对应名称(选填),填写时地址和名称的个数应一致,用英文逗号分隔
154140
<input type="text" id=
155-
"import_private_key_input" placeholder="地址">
141+
"import_address_name_input" placeholder="地址对应名称">
156142
</label>
157143
</form>
158-
<button id="import_private_key_button" disabled=
144+
<button id="import_address_button" disabled=
159145
"true">导入
160146
</button>
161147
<footer>
162-
Result: <span id="import_private_key_result">N/A</span>
148+
Result: <span id="import_address_result">N/A</span>
163149
</footer>
164150
</article>
165151
</div>

example/basic-dapp/index.js

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -480,14 +480,13 @@ async function walletInitialized() {
480480
const transferFromButton = getElement('transfer_from')
481481
const getCFXButton = getElement('get-cfx')
482482
const importAddressButton = getElement('import_address_button')
483-
const importPrivateKeyButton = getElement('import_private_key_button')
484483
const nativeReceiverAddressInput = getElement('native-receiver')
485484
const countInput = getElement('native-count')
486485
const approveAccountInput = getElement('approve-account')
487486
const transferFromAccountInput = getElement('from-account')
488487
const transferToAccountInput = getElement('to-account')
489488
const importAddressInput = getElement('import_address_input')
490-
const importPrivateKeyInput = getElement('import_private_key_input')
489+
const importAddressNameInput = getElement('import_address_name_input')
491490

492491
const deployContract = getElement('deploy_contract')
493492

@@ -508,7 +507,6 @@ async function walletInitialized() {
508507
connectButton.disabled = true
509508
logoutButton.disabled = false
510509
importAddressButton.disabled = false
511-
importPrivateKeyButton.disabled = false
512510
}
513511

514512
function unAuthed() {
@@ -523,7 +521,6 @@ async function walletInitialized() {
523521
connectButton.disabled = false
524522
logoutButton.disabled = true
525523
importAddressButton.disabled = true
526-
importPrivateKeyButton.disabled = true
527524
}
528525

529526
provider.on('accountsChanged', (accounts) => {
@@ -726,34 +723,26 @@ async function walletInitialized() {
726723
getElement('import_address_result').innerHTML = 'valid Params'
727724
return
728725
}
729-
try {
730-
const tx = {
731-
address: importAddressInput.value.replace(/\s+/g, '').split(','),
732-
}
733-
provider
734-
.request({ method: 'anyweb_importAccount', params: [tx] })
735-
.then((result) => {
736-
getElement('import_address_result').innerHTML = result
737-
console.log('result', result)
738-
})
739-
} catch (err) {
740-
console.log('err', err)
741-
}
742-
}
743-
744-
importPrivateKeyButton.onclick = async () => {
745-
if (importPrivateKeyInput.value.replace(/\s+/g, '') === '') {
746-
getElement('import_private_key_result').innerHTML = 'valid Params'
726+
const addressLength = importAddressInput.value.split(',').length
727+
const addressName = importAddressNameInput.value
728+
.split(',')
729+
.filter((name) => name !== '')
730+
const addressNamesLength = addressName.length
731+
console.log('addressNamesLength', addressNamesLength)
732+
if (addressNamesLength > 0 && addressNamesLength !== addressLength) {
733+
getElement('import_address_result').innerHTML =
734+
'address length not equal to address name length'
747735
return
748736
}
749737
try {
750738
const tx = {
751-
privateKey: importPrivateKeyInput.value.replace(/\s+/g, '').split(','),
739+
address: importAddressInput.value.replace(/\s+/g, '').split(','),
740+
addressName: addressName,
752741
}
753742
provider
754743
.request({ method: 'anyweb_importAccount', params: [tx] })
755744
.then((result) => {
756-
getElement('import_private_key_result').innerHTML = result
745+
getElement('import_address_result').innerHTML = result
757746
console.log('result', result)
758747
})
759748
} catch (err) {

0 commit comments

Comments
 (0)