on master help sign in
- use ternary style for inviteTicket functions
commitff7df0dd122871c8207a2f53b93fef2b40c34c44 authorChris Johnson <chris@cjohnson.io> dateMon 29 Apr 2019, 15:44 (8 years ago) parented7b91b
1 file changed+79−87
src/bridge/views/InviteTicket.js+79−87
src/bridge/views/InviteTicket.js+79−87
@@ -179,34 +179,29 @@ class InviteTicket extends React.Component {
179179 }
180180
181181 getStageText() {
182− switch (this.state.stage) {
183− case INVITE_STAGES.INVITE_LOGIN:
184− return (
185− <h1 className="text-700 mt-15">Welcome</h1>
186− )
187− break
188− case INVITE_STAGES.INVITE_WALLET:
189− return (
182+ const { stage } = this.state
183+
184+ let progressWidth = this.state.transactionProgress.pct;
185+
186+ const stageText = stage === INVITE_STAGES.INVITE_LOGIN
187+ ? <h1 className="text-700 mt-15">Welcome</h1>
188+ : stage === INVITE_STAGES.INVITE_LOGIN
189+ ? (
190190 <div>
191191 <h1 className="fs-6 lh-8 mb-3">Passport</h1>
192192 <p>A passport is your digital identity. You will use your passport to access your true computer, send payments, and administer your identity. So naturally, you must keep this secure.</p>
193193 <p>After you’ve downloaded your passport, back up the ticket manually or store on a trusted device.</p>
194194 </div>
195195 )
196− break
197− case INVITE_STAGES.INVITE_VERIFY:
198− return (
196+ : stage === INVITE_STAGES.INVITE_VERIFY
197+ ? (
199198 <div>
200199 <h1 className="fs-6 lh-8 mb-3">Verify Passport</h1>
201200 <p>Afer you download your passport, verify your custody. Your passport should be a folder of image files. One of them is your Master Ticket. Open it and enter the 4 word phrase below (with hyphens).</p>
202201 </div>
203− )
204− break
205− case INVITE_STAGES.INVITE_TRANSACTIONS:
206− let progressWidth = this.state.transactionProgress.pct;
207−
208− if (this.state.transactionProgress.label === TRANSACTION_STATES.DONE.label) {
209− return (
202+ ) : INVITE_STAGES.INVITE_TRANSACTIONS
203+ ? this.state.transactionProgress.label === TRANSACTION_STATES.DONE.label
204+ ? (
210205 <div>
211206 <h1 className="fs-6 lh-8 mb-3">
212207 <span>Success</span>
@@ -215,8 +210,7 @@ class InviteTicket extends React.Component {
215210 <p>Transferring to Bridge...</p>
216211 </div>
217212 )
218− } else {
219− return (
213+ : (
220214 <div>
221215 <h1 className="fs-6 lh-8 mb-3">Submitting</h1>
222216 <p className="mt-4 mb-4">This step can take up to five minutes. Please do not leave this page until the transactions are complete.</p>
@@ -228,9 +222,9 @@ class InviteTicket extends React.Component {
228222 </div>
229223 </div>
230224 )
231− }
232− break
233− }
225+ : null
226+
227+ return stageText
234228 }
235229
236230 updateProgress(transactionProgress) {
@@ -240,75 +234,73 @@ class InviteTicket extends React.Component {
240234 }
241235
242236 getContinueButton() {
243− if (this.state.stage === INVITE_STAGES.INVITE_TRANSACTIONS) return null
244−
245− const { realPoint, realWallet, inviteWallet, verifyTicket, inviteTicket } = this.state
237+ const { realPoint, realWallet, inviteWallet, stage, walletStates,
238+ verifyTicket, inviteTicket } = this.state
246239 const { web3, contracts, setUrbitWallet } = this.props
247240
248− let clickHandler
249− let btnColor = this.state.walletStates.includes(WALLET_STATES.PAPER_READY)
241+ const btnColor = this.state.walletStates.includes(WALLET_STATES.PAPER_READY)
250242 ? 'green'
251243 : 'black'
252− let continueReady
253−
254− switch(this.state.stage) {
255− case INVITE_STAGES.INVITE_LOGIN:
256− clickHandler = () => {
257− this.unlockInviteWallet(inviteTicket)
258− }
259− continueReady = true
260− break
261− case INVITE_STAGES.INVITE_WALLET:
262− clickHandler = () => {
263− this.setState({
264− stage: INVITE_STAGES.INVITE_VERIFY
265− })
266− }
267− continueReady = this.state.walletStates.includes(WALLET_STATES.DOWNLOADED)
268− break
269− case INVITE_STAGES.INVITE_VERIFY:
270− clickHandler = () => {
271− const realTicket = realWallet.matchWith({
272− Just: w => w.value.ticket,
273− Nothing: null
274− })
275−
276− this.setState({
277− stage: INVITE_STAGES.INVITE_TRANSACTIONS,
278− walletStates: this.state.walletStates.concat(WALLET_STATES.TRANSACTIONS)
279− })
280−
281− startTransactions({
282− inviteWalletM: inviteWallet,
283− realWalletM: realWallet,
284− realPointM: realPoint,
285− realTicket: verifyTicket,
286− web3M: web3,
287− contractsM: contracts,
288− setUrbitWallet,
289− updateProgress: this.updateProgress
290− })
291− .then(() => {
292− setTimeout(() => {
293− this.props.popRoute()
294− }, 5000)
295− })
296− }
297− continueReady = true
298− break
299− }
300244
301− return (
302− <Button
303− className={'mt-4'}
304− prop-size={'lg'}
305− prop-color={btnColor}
306− disabled={!continueReady}
307− onClick={clickHandler}
308− >
309− { 'Continue →' }
310− </Button>
311− )
245+ const clickHandler = stage === INVITE_STAGES.INVITE_LOGIN
246+ ? () => {
247+ this.unlockInviteWallet(inviteTicket)
248+ }
249+ : stage === INVITE_STAGES.INVITE_WALLET
250+ ? () => {
251+ this.setState({
252+ stage: INVITE_STAGES.INVITE_VERIFY
253+ })
254+ }
255+ : stage === INVITE_STAGES.INVITE_TRANSACTIONS
256+ ? () => {
257+ const realTicket = realWallet.matchWith({
258+ Just: w => w.value.ticket,
259+ Nothing: null
260+ })
261+
262+ this.setState({
263+ stage: INVITE_STAGES.INVITE_TRANSACTIONS,
264+ walletStates: this.state.walletStates.concat(WALLET_STATES.TRANSACTIONS)
265+ })
266+
267+ startTransactions({
268+ inviteWalletM: inviteWallet,
269+ realWalletM: realWallet,
270+ realPointM: realPoint,
271+ realTicket: verifyTicket,
272+ web3M: web3,
273+ contractsM: contracts,
274+ setUrbitWallet,
275+ updateProgress: this.updateProgress
276+ })
277+ .then(() => {
278+ setTimeout(() => {
279+ this.props.popRoute()
280+ }, 5000)
281+ })
282+ }
283+ : null
284+
285+ const continueReady = stage === INVITE_STAGES.INVITE_WALLET
286+ ? walletStates.includes(WALLET_STATES.DOWNLOADED)
287+ : true
288+
289+ const buttonElem = stage === INVITE_STAGES.INVITE_TRANSACTIONS
290+ ? null
291+ : (
292+ <Button
293+ className={'mt-4'}
294+ prop-size={'lg'}
295+ prop-color={btnColor}
296+ disabled={!continueReady}
297+ onClick={clickHandler}
298+ >
299+ { 'Continue →' }
300+ </Button>
301+ )
302+
303+ return buttonElem
312304 }
313305
314306 getStageDisplay() {