This repository was archived by the owner on Aug 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·145 lines (126 loc) · 3.52 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env node
import meow from 'meow'
import React, { useState, useEffect } from 'react'
import { render, Box, Color } from 'ink'
import { mineshaftStart, mineshaftStop } from '@jimpick/filecoin-pickaxe-mineshaft'
import { ConnectMineshaft } from '@jimpick/filecoin-pickaxe-mineshaft-context'
import { SelectBundle } from './bundleContext'
import { WatchDealRequests } from './dealRequestsContext'
import useFilecoinConfig from '@filecoin-shipyard/use-filecoin-config'
import useFilecoinHead from '@filecoin-shipyard/use-filecoin-head'
import useFilecoinNetworkInfo from '@filecoin-shipyard/use-filecoin-network-info'
import useFilecoinAsks from '@jimpick/use-filecoin-asks'
import InkWatchForExitKey from '@jimpick/ink-watch-for-exit-key'
import Bundle from './bundle'
import Duration from './duration'
import Scrollable from './scrollable'
import AsksAndDealRequests from './asksAndDealRequests'
const cli = meow(
`
Usage
$ filecoin-pickaxe-direct-deal [options]
Options:
--duration <blocks>
-d <blocks>
Deal duration in blocks (approx 30 seconds each)
`,
{
flags: {
duration: {
alias: 'd',
type: 'string'
}
}
}
)
const args = cli.flags
const duration = Number(args.duration) || 2880
const Main = () => {
const [, nickname] = useFilecoinConfig('heartbeat.nickname')
const [, , height, updateTime] = useFilecoinHead({
interval: 5000
})
const [, netName, , netHeight] = useFilecoinNetworkInfo({
interval: 30000
})
const [unfilteredAsks] = useFilecoinAsks()
const asks = unfilteredAsks &&
unfilteredAsks.filter(ask => ask.expiry > height + duration)
const { columns, rows } = process.stdout
if (!updateTime) {
return <Box>Loading...</Box>
}
const seconds = (
<Box>
({Math.floor((Date.now() - updateTime) / 1000)}s ago)
</Box>
)
const netInfo = (
<Box>
{netName}: {netHeight >= 0 ? netHeight : 'Loading...'}
</Box>
)
const content = (
<WatchDealRequests>
<Scrollable
height={rows - 5}
dataLength={asks && asks.length}
render={
({ height, scrollTop, cursorIndex }) => {
return (
<AsksAndDealRequests
asks={asks}
height={height}
scrollTop={scrollTop}
cursorIndex={cursorIndex}
duration={duration} />
)
}
} />
</WatchDealRequests>
)
return (
<ConnectMineshaft>
<SelectBundle>
<Box flexDirection="column" width={columns} height={rows - 1}>
<Box>
<Box flexGrow={1}>
<Color green>Filecoin Pickaxe Direct Deal</Color>
</Box>
<Box>
{asks && `${asks.length} asks`}
</Box>
</Box>
<Bundle />
<Duration duration={duration} height={height} />
{content}
<Box>
<Box>
{nickname && nickname + ' '}
</Box>
<Box flexGrow={1}>
{height} {seconds}
</Box>
<Box>
<Box>{netInfo}</Box>
</Box>
</Box>
<InkWatchForExitKey />
</Box>
</SelectBundle>
</ConnectMineshaft>
)
}
async function run () {
await mineshaftStart('filecoin-pickaxe')
const { rerender, waitUntilExit } = render(<Main/>)
process.on('SIGWINCH', () => rerender(<Main/>))
try {
await waitUntilExit()
process.exit(0)
} catch (e) {
console.error(e)
process.exit(1)
}
}
run()