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';
13} from '../components/old/Base';
14import StatelessTransaction from '../components/old/StatelessTransaction';
15import { withNetwork } from '../store/network';
16import { compose } from '../lib/lib';
17import { withPointCursor } from '../store/pointCursor';
18import View from 'components/View';
20class InvitesManage extends React.Component {
25 invitesWillWork: Nothing(),
27 targetPlanet: Nothing(),
28 currentPoolSize: Nothing(),
33 this.checkCurrentInvites = this.checkCurrentInvites.bind(this);
34 this.handlePointInput = this.handlePointInput.bind(this);
35 this.updatePoolSize = this.updatePoolSize.bind(this);
36 this.handlePoolSizeInput = this.handlePoolSizeInput.bind(this);
37 this.createUnsignedTxn = this.createUnsignedTxn.bind(this);
38 this.statelessRef = React.createRef();
42 this.point = need.point(this.props.pointCursor);
43 this.contracts = need.contracts(this.props.contracts);
49 this.contracts.delegatedSending.address
51 .then(isSpawnProxy => {
52 this.setState({ invitesWillWork: Just(isSpawnProxy) });
56 componentDidUpdate(prevProps) {
60 handlePointInput(targetPlanet) {
62 targetPlanet: Nothing(),
63 planetInput: targetPlanet,
65 currentPoolSize: Nothing(),
67 if (targetPlanet.length === 14 && ob.isValidPatp(targetPlanet)) {
68 const target = ob.patp2dec(targetPlanet);
69 //TODO there must be a simpler way to do this check
70 const isChild = ob.sein(targetPlanet) === ob.patp(this.point);
72 newState.targetPlanet = Just(target);
73 newState.currentPoolSize = this.checkCurrentInvites(target);
74 newState.canGenerate = true;
77 this.setState(newState);
80 checkCurrentInvites(who) {
81 const cachedPoolSizes = this.state.cachedPoolSizes;
82 if (typeof cachedPoolSizes[who] !== 'undefined') {
83 return Just(cachedPoolSizes[who]);
85 azimuth.delegatedSending.getPool(this.contracts, who).then(pool => {
86 azimuth.delegatedSending
87 .invitesInPool(this.contracts, pool, this.point)
89 this.updatePoolSize(who, size);
96 updatePoolSize(who, size) {
97 const cache = this.state.cachedPoolSizes;
99 this.setState({ cachedPoolSizes: cache });
100 const target = this.state.targetPlanet;
101 const match = Just.hasInstance(target) ? who === target.value : false;
103 this.setState({ currentPoolSize: Just(size) });
107 handlePoolSizeInput(targetSize) {
108 this.setState({ targetPoolSize: targetSize });
111 createUnsignedTxn() {
113 azimuth.delegatedSending.setPoolSize(
116 this.state.targetPlanet.value,
117 this.state.targetPoolSize
123 let spawnProxyWarning = null;
124 if (this.state.invitesWillWork.value === false) {
125 spawnProxyWarning = (
127 <h3 className={'mb-2'}>{'Warning'}</h3>
128 {'Planets under this star will not be able to send invites ' +
129 'until the invite contract ('}
130 <code>{this.contracts.delegatedSending.address}</code>
131 {') is made spawn proxy for this star.'}
136 let poolSizeText = this.state.currentPoolSize.matchWith({
137 Just: ps => `(currently ${ps.value})`,
145 'manage invites here, for stars. can only give invites to child planets'
152 prop-format="innerlabel"
154 placeholder={'~sampel-sipnem'}
155 value={this.state.planetInput}
156 onChange={this.handlePointInput}>
157 <InnerLabel>{'Planet to set invites for'}</InnerLabel>
159 patp={this.state.targetPlanet}
160 validator={() => this.validatePoint}
165 prop-format="innerlabel"
167 value={this.state.targetPoolSize}
168 onChange={this.handlePoolSizeInput}>
169 <InnerLabel>{`Available invites ${poolSizeText}`}</InnerLabel>
172 <StatelessTransaction
173 canGenerate={this.state.canGenerate}
174 createUnsignedTxn={this.createUnsignedTxn}
175 ref={this.statelessRef}
182export 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