7
7
<section class =" flex justify-center items-center" style =" height : 86% " >
8
8
<div class =" flex flex-col items-center w-full p-14 -mt-5" >
9
9
<!-- Step 0: Code redeem -->
10
- <article v-if =" !inviteCode && !isLoading" class =" w-1/2" >
10
+ <article v-if =" !hasInviteCode && !(userInfo || nearWallet) && !isLoading" class =" w-1/2" >
11
11
<h1 class =" font-semibold text-primary mb-10" style =" font-size : 2.6rem " >Welcome</h1 >
12
12
<p class =" text-center text-gray7 mt-10" >
13
13
Blogchain is a place for writers to do great work and for readers to discover it. For now, during our beta
69
69
</div >
70
70
</article >
71
71
<!-- Step 1: Choose Login / register -->
72
- <article v-show =" inviteCode && !(userInfo || nearWallet) && !isLoading" class =" w-1/2" >
72
+ <article v-show =" hasInviteCode && !(userInfo || nearWallet) && !isLoading" class =" w-1/2" >
73
73
<h1 class =" font-semibold text-primary mb-10" style =" font-size : 2.6rem " >Sign up</h1 >
74
74
<button
75
75
class =" w-full rounded-lg bg-gray2 mb-4 py-2 flex justify-center items-center focus:outline-none"
@@ -221,14 +221,15 @@ import {
221
221
} from ' @/backend/near'
222
222
import { sufficientFunds , torusVerifiers , TorusVerifiers } from ' @/backend/utilities/config'
223
223
import { requestOTP , requestSponsor } from ' @/backend/funder'
224
+ import { verifyCodeAndGetToken , verifyTokenAndOnboard } from ' @/backend/invite'
224
225
225
226
interface IData {
226
227
id: string
227
228
torus: DirectWebSdk
228
229
userInfo: null | TorusLoginResponse
229
230
username? : null | string
230
231
accountId: null | string
231
- inviteCode : null | string
232
+ hasInviteCode : boolean
232
233
inputCode: string
233
234
isLoading: boolean
234
235
phoneNumber: string
@@ -261,7 +262,7 @@ export default Vue.extend({
261
262
network: ` testnet ` , // details for test net
262
263
}),
263
264
accountId: null ,
264
- inviteCode: null ,
265
+ hasInviteCode: false ,
265
266
inputCode: ` ` ,
266
267
userInfo: null ,
267
268
isLoading: false ,
@@ -319,7 +320,8 @@ export default Vue.extend({
319
320
this .userInfo = await this .torus .triggerLogin (torusVerifiers [type ])
320
321
321
322
this .accountId = getAccountIdFromPrivateKey (this .userInfo .privateKey )
322
- this .username = await getUsernameNEAR (this .accountId )
323
+ const [username] = await Promise .all ([getUsernameNEAR (this .accountId ), this .onboardAccount ()])
324
+ this .username = username
323
325
if (this .username ) {
324
326
// If a username is found then proceed to login...
325
327
this .verify ()
@@ -349,7 +351,8 @@ export default Vue.extend({
349
351
return false
350
352
}
351
353
352
- ;[this .username ] = await Promise .all ([getUsernameNEAR (this .accountId ), this .checkFunds ()])
354
+ const [username] = await Promise .all ([getUsernameNEAR (this .accountId ), this .checkFunds (), this .onboardAccount ()])
355
+ this .username = username
353
356
if (this .username ) {
354
357
this .$toastError (` You cannot login with wallet, please import your private key ` )
355
358
removeNearPrivateKey (this .accountId )
@@ -366,7 +369,8 @@ export default Vue.extend({
366
369
this .isLoading = true
367
370
368
371
this .accountId = await generateAndSetKey ()
369
- ;[this .username ] = await Promise .all ([getUsernameNEAR (this .accountId ), this .checkFunds ()])
372
+ const [username] = await Promise .all ([getUsernameNEAR (this .accountId ), this .checkFunds (), this .onboardAccount ()])
373
+ this .username = username
370
374
if (this .username ) {
371
375
this .$toastError (` You cannot login with implicit account, please import your private key ` )
372
376
removeNearPrivateKey (this .accountId )
@@ -518,6 +522,45 @@ export default Vue.extend({
518
522
URL .revokeObjectURL (link .href )
519
523
this .$toastSuccess (` Downloaded private key ` )
520
524
},
525
+ async verifyCode() {
526
+ if (this .inputCode .length !== 8 ) {
527
+ this .$toastError (` Invite codes should be of length 8 ` )
528
+ return
529
+ }
530
+ try {
531
+ await verifyCodeAndGetToken (this .inputCode )
532
+ this .hasInviteCode = true
533
+ } catch (error : any ) {
534
+ if (axios .isAxiosError (error ) && error .response ) {
535
+ if (error .response .status === 429 ) {
536
+ this .$toastWarning (` Too many requests ` )
537
+ return
538
+ }
539
+ this .$toastError (error .response .data .error )
540
+ return
541
+ }
542
+ throw error
543
+ }
544
+ },
545
+ async onboardAccount() {
546
+ if (! this .accountId ) {
547
+ this .$toastError (` AccountId missing ` )
548
+ return
549
+ }
550
+ try {
551
+ await verifyTokenAndOnboard (this .accountId )
552
+ } catch (error : any ) {
553
+ if (axios .isAxiosError (error ) && error .response ) {
554
+ if (error .response .status === 429 ) {
555
+ this .$toastWarning (` Too many requests ` )
556
+ return
557
+ }
558
+ this .$toastError (error .response .data .error )
559
+ return
560
+ }
561
+ throw error
562
+ }
563
+ },
521
564
},
522
565
})
523
566
</script >
0 commit comments