Skip to content

Commit b524d9f

Browse files
fix: add spinner to feed print command (#404)
* fix: remove elipssis on print feed and add spinner * chore: remove unnecessarry import * fix: several minor changes on feed pirnt * fix: validate feed print exception obj * fix: use an existing file on feed upload unit test * fix: modified hash resultant in feed print unit test * test: try modifying hash again * test: pick different hash * fix: print feed topic Co-authored-by: Cafe137 <[email protected]>
1 parent 9f977b9 commit b524d9f

File tree

3 files changed

+39
-20
lines changed

3 files changed

+39
-20
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ coverage
1919
# node-waf configuration
2020
.lock-wscript
2121

22+
#babel RC
23+
.babelrc.js
24+
2225
build
2326
dist
2427

src/command/feed/print.ts

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { exit } from 'process'
44
import { isSimpleWallet, isV3Wallet } from '../../service/identity'
55
import { Identity } from '../../service/identity/types'
66
import { pickStamp } from '../../service/stamp'
7+
import { getFieldOrNull } from '../../utils'
8+
import { createSpinner } from '../../utils/spinner'
79
import { createKeyValue } from '../../utils/text'
810
import { FeedCommand } from './feed-command'
911

@@ -26,26 +28,39 @@ export class Print extends FeedCommand implements LeafCommand {
2628
await super.init()
2729

2830
const topic = this.topic || this.bee.makeFeedTopic(this.topicString)
29-
this.console.info('Looking up feed topic ' + topic + '...')
30-
const addressString = this.address || (await this.getAddressString())
31-
const reader = this.bee.makeFeedReader('sequence', topic, addressString)
32-
const { reference, feedIndex, feedIndexNext } = await reader.download()
31+
const spinner = createSpinner(`Looking up feed topic ${topic}`)
32+
spinner.start()
33+
try {
34+
const addressString = this.address || (await this.getAddressString())
35+
const reader = this.bee.makeFeedReader('sequence', topic, addressString)
36+
const { reference, feedIndex, feedIndexNext } = await reader.download()
37+
38+
if (!this.stamp) {
39+
spinner.stop()
40+
this.stamp = await pickStamp(this.beeDebug, this.console)
41+
spinner.start()
42+
}
3343

34-
if (!this.stamp) {
35-
this.stamp = await pickStamp(this.beeDebug, this.console)
44+
const { reference: manifest } = await this.bee.createFeedManifest(this.stamp, 'sequence', topic, addressString)
45+
46+
spinner.stop()
47+
this.console.verbose(createKeyValue('Chunk Reference', reference))
48+
this.console.verbose(createKeyValue('Chunk Reference URL', `${this.bee.url}/bzz/${reference}/`))
49+
this.console.verbose(createKeyValue('Feed Index', feedIndex))
50+
this.console.verbose(createKeyValue('Next Index', feedIndexNext))
51+
this.console.verbose(createKeyValue('Feed Manifest', manifest))
52+
53+
this.console.quiet(manifest)
54+
this.console.log(createKeyValue('Topic', `${topic}`))
55+
this.console.log(createKeyValue('Feed Manifest URL', `${this.bee.url}/bzz/${manifest}/`))
56+
this.console.log(createKeyValue('Number of Updates', parseInt(feedIndex, 10) + 1))
57+
} catch (error) {
58+
spinner.stop()
59+
const message = getFieldOrNull(error, 'message')
60+
throw Error(`Feed topic lookup error: ${message || 'unknown'}`)
61+
} finally {
62+
spinner.stop()
3663
}
37-
38-
const { reference: manifest } = await this.bee.createFeedManifest(this.stamp, 'sequence', topic, addressString)
39-
40-
this.console.verbose(createKeyValue('Chunk Reference', reference))
41-
this.console.verbose(createKeyValue('Chunk Reference URL', `${this.bee.url}/bzz/${reference}/`))
42-
this.console.verbose(createKeyValue('Feed Index', feedIndex))
43-
this.console.verbose(createKeyValue('Next Index', feedIndexNext))
44-
this.console.verbose(createKeyValue('Feed Manifest', manifest))
45-
46-
this.console.quiet(manifest)
47-
this.console.log(createKeyValue('Feed Manifest URL', `${this.bee.url}/bzz/${manifest}/`))
48-
this.console.log(createKeyValue('Number of Updates', parseInt(feedIndex, 10) + 1))
4964
}
5065

5166
private async getAddressString(): Promise<string> {
@@ -80,7 +95,8 @@ export class Print extends FeedCommand implements LeafCommand {
8095

8196
return wallet.address
8297
} else if (isSimpleWallet(wallet, identityType)) {
83-
const ethereumWallet = Wallet.fromPrivateKey(Buffer.from(wallet.privateKey, 'hex'))
98+
const privateKey = wallet.privateKey.replace('0x', '')
99+
const ethereumWallet = Wallet.fromPrivateKey(Buffer.from(privateKey, 'hex'))
84100

85101
return ethereumWallet.getAddressString()
86102
} else {

test/quality-of-life/topic.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describeCommand(
1717
'topic',
1818
'-P',
1919
'topic',
20-
'.babelrc.js',
20+
'test/message.txt',
2121
...getStampOption(),
2222
])
2323
})

0 commit comments

Comments
 (0)