1import { Just, Nothing } from 'folktale/maybe';
2import React from 'react';
3import * as ob from 'urbit-ob';
4import * as azimuth from 'azimuth-js';
5import * as need from '../lib/need';
15} from '../components/old/Base';
16import StatelessTransaction from '../components/old/StatelessTransaction';
17import { withNetwork } from '../store/network';
18import { compose } from '../lib/lib';
19import { withPointCursor } from '../store/pointCursor';
21class InvitesManage extends React.Component {
26 invitesWillWork: Nothing(),
28 targetPlanet: Nothing(),
29 currentPoolSize: Nothing(),
34 this.checkCurrentInvites = this.checkCurrentInvites.bind(this);
35 this.handlePointInput = this.handlePointInput.bind(this);
36 this.updatePoolSize = this.updatePoolSize.bind(this);
37 this.handlePoolSizeInput = this.handlePoolSizeInput.bind(this);
38 this.createUnsignedTxn = this.createUnsignedTxn.bind(this);
39 this.statelessRef = React.createRef();
43 this.point = need.pointCursor(this.props);
44 this.contracts = need.contracts(this.props);
50 this.contracts.delegatedSending.address
52 .then(isSpawnProxy => {
53 this.setState({ invitesWillWork: Just(isSpawnProxy) });
57 componentDidUpdate(prevProps) {
61 handlePointInput(targetPlanet) {
63 targetPlanet: Nothing(),
64 planetInput: targetPlanet,
66 currentPoolSize: Nothing(),
68 if (targetPlanet.length === 14 && ob.isValidPatp(targetPlanet)) {
69 const target = ob.patp2dec(targetPlanet);
70 //TODO there must be a simpler way to do this check
71 const isChild = ob.sein(targetPlanet) === ob.patp(this.point);
73 newState.targetPlanet = Just(target);
74 newState.currentPoolSize = this.checkCurrentInvites(target);
75 newState.canGenerate = true;
78 this.setState(newState);
81 checkCurrentInvites(who) {
82 const cachedPoolSizes = this.state.cachedPoolSizes;
83 if (typeof cachedPoolSizes[who] !== 'undefined') {
84 return Just(cachedPoolSizes[who]);
86 azimuth.delegatedSending.getPool(this.contracts, who).then(pool => {
87 azimuth.delegatedSending
88 .invitesInPool(this.contracts, pool, this.point)
90 this.updatePoolSize(who, size);
97 updatePoolSize(who, size) {
98 const cache = this.state.cachedPoolSizes;
100 this.setState({ cachedPoolSizes: cache });
101 const target = this.state.targetPlanet;
102 const match = Just.hasInstance(target) ? who === target.value : false;
104 this.setState({ currentPoolSize: Just(size) });
108 handlePoolSizeInput(targetSize) {
109 this.setState({ targetPoolSize: targetSize });
112 createUnsignedTxn() {
114 azimuth.delegatedSending.setPoolSize(
117 this.state.targetPlanet.value,
118 this.state.targetPoolSize
124 let spawnProxyWarning = null;
125 if (this.state.invitesWillWork.value === false) {
126 spawnProxyWarning = (
128 <h3 className={'mb-2'}>{'Warning'}</h3>
129 {'Planets under this star will not be able to send invites ' +
130 'until the invite contract ('}
131 <code>{this.contracts.delegatedSending.address}</code>
132 {') is made spawn proxy for this star.'}
137 let poolSizeText = this.state.currentPoolSize.matchWith({
138 Just: ps => `(currently ${ps.value})`,
147 'manage invites here, for stars. can only give invites to child planets'
154 prop-format="innerlabel"
156 placeholder={'~sampel-sipnem'}
157 value={this.state.planetInput}
158 onChange={this.handlePointInput}>
159 <InnerLabel>{'Planet to set invites for'}</InnerLabel>
161 patp={this.state.targetPlanet}
162 validator={() => this.validatePoint}
167 prop-format="innerlabel"
169 value={this.state.targetPoolSize}
170 onChange={this.handlePoolSizeInput}>
171 <InnerLabel>{`Available invites ${poolSizeText}`}</InnerLabel>
174 <StatelessTransaction
175 canGenerate={this.state.canGenerate}
176 createUnsignedTxn={this.createUnsignedTxn}
177 ref={this.statelessRef}
185export default compose(
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list