-
Notifications
You must be signed in to change notification settings - Fork 3
feat: toggle phone number registration #1157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jackdishman
wants to merge
3
commits into
main
Choose a base branch
from
feat/toggle-phone
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| <template> | ||
| <article> | ||
| <h1 class="text-lightPrimaryText dark:text-gray1 text-4xl font-bold">Sign up</h1> | ||
| <!-- Enter phone number --> | ||
| <div v-show="!otpSent"> | ||
| <p class="text-gray7 dark:text-gray3 my-10 text-center"> | ||
| Verify you’re a human with your phone number so that Blogchain can fund your wallet. | ||
| </p> | ||
| <label for="phoneNumber" class="text-gray5 dark:text-gray3 block pb-1 text-sm font-semibold">Phone Number</label> | ||
| <input | ||
| id="phoneNumber" | ||
| v-model="phoneNumber" | ||
| type="tel" | ||
| class="focus:outline-none focus:border-primary text-primary dark:text-darkPrimaryText bg-gray2 dark:bg-gray7 mt-1 mb-5 w-full rounded-lg px-3 py-2 font-sans text-sm" | ||
| /> | ||
| <div class="flex w-full justify-end mt-4"> | ||
| <BrandedButton :text="otpSent ? `Re-send code` : `Send Code`" :action="sendOTP" /> | ||
| </div> | ||
| <h6 v-show="isLoading" class="text-primary text-center">Sending SMS...</h6> | ||
| </div> | ||
| <!-- Enter SMS code to complete verify --> | ||
| <div v-show="otpSent" class="mt-10"> | ||
| <label for="otp" class="text-gray5 dark:text-gray3 block pb-1 text-sm font-semibold" | ||
| >Enter the one-time verification code sent to your phone number.</label | ||
| > | ||
| <input | ||
| id="otp" | ||
| v-model="otp" | ||
| type="text" | ||
| placeholder="" | ||
| class="focus:outline-none focus:border-primary text-primary dark:text-darkPrimaryText bg-gray2 dark:bg-gray7 mt-1 mb-5 w-full rounded-lg px-3 py-2 font-sans text-sm" | ||
| /> | ||
| <BrandedButton v-show="!isLoading && !waitingForFunds" :text="`Verify`" class="w-full" :action="validateOTP" /> | ||
| <h6 v-show="isLoading" class="text-primary text-center">Verifying...</h6> | ||
| <h6 v-show="waitingForFunds" class="text-primary text-center">Executing smart contract...</h6> | ||
| </div> | ||
| <p v-show="otpSent" class="text-gray7 dark:text-gray2 mt-10 text-center text-sm"> | ||
| Didn't receive a code? | ||
| <button class="text-primary font-bold" @click="otpSent = false"> | ||
| Check your phone number and request a new one | ||
| </button> | ||
| </p> | ||
| </article> | ||
| </template> | ||
|
|
||
| <script lang="ts"> | ||
| import Vue from 'vue' | ||
| import intlTelInput from 'intl-tel-input' | ||
| import { AxiosError } from 'axios' | ||
| import BrandedButton from '@/components/BrandedButton.vue' | ||
| import { requestOTP, requestPhoneOnboard, waitForFunds } from '@/backend/funder' | ||
| interface IData { | ||
| otp: string | ||
| otpSent: boolean | ||
| iti: null | intlTelInput.Plugin | ||
| phoneNumber: string | ||
| inputCode: string | ||
| isLoading: boolean | ||
| waitingForFunds: boolean | ||
| } | ||
| export default Vue.extend({ | ||
| components: { | ||
| BrandedButton, | ||
| }, | ||
| props: { | ||
| accountId: { | ||
| type: String, | ||
| required: true, | ||
| }, | ||
| }, | ||
| data(): IData { | ||
| return { | ||
| otp: ``, | ||
| otpSent: false, | ||
| iti: null, | ||
| phoneNumber: ``, | ||
| inputCode: ``, | ||
| isLoading: false, | ||
| waitingForFunds: false, | ||
| } | ||
| }, | ||
| mounted() { | ||
| const input = document.querySelector(`#phoneNumber`) | ||
| if (input) { | ||
| this.iti = intlTelInput(input, { | ||
| utilsScript: require(`intl-tel-input/build/js/utils`), | ||
| // any initialisation options go here | ||
| }) | ||
| } | ||
| }, | ||
| methods: { | ||
| async sendOTP() { | ||
| if (this.iti === null) { | ||
| return | ||
| } | ||
| this.phoneNumber = this.iti.getNumber() | ||
| if (!this.iti.isValidNumber()) { | ||
| this.$toastError(`Invalid phone number`) | ||
| return | ||
| } | ||
| this.isLoading = true | ||
| await requestOTP(this.phoneNumber) | ||
| this.otpSent = true | ||
| this.$toastSuccess( | ||
| `If you haven't used this phone number before on Blogchain, you'll receive a code on your phone`, | ||
| ) | ||
| this.isLoading = false | ||
| }, | ||
| async validateOTP() { | ||
| try { | ||
| if (this.otp.length !== 6) { | ||
| this.$toastError(`OTP should have 6 digits`) | ||
| return | ||
| } | ||
| if (!this.accountId) { | ||
| return | ||
| } | ||
| this.isLoading = true | ||
| await requestPhoneOnboard(this.phoneNumber, this.otp, this.accountId) | ||
| this.isLoading = false | ||
| this.waitingForFunds = true | ||
| const { balance } = await waitForFunds(this.accountId) | ||
| this.waitingForFunds = false | ||
| this.$emit(`setIsOnboarded`, true) | ||
| this.$emit(`updateFunds`, balance) | ||
| } catch (err: any) { | ||
| this.isLoading = false | ||
| this.waitingForFunds = false | ||
| if (err instanceof AxiosError && err.response) { | ||
| this.otp = `` | ||
| this.$toastError(err.response.data.error) | ||
| return | ||
| } | ||
| this.$toastError(err.message) | ||
| throw err | ||
| } | ||
| }, | ||
| }, | ||
| }) | ||
| </script> | ||
| <style> | ||
| .iti { | ||
| width: 100%; | ||
| } | ||
| </style> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also add a
captchaRestorequestOTP()function. Basically, when phone number toggle is on, we want the user to solve captcha when request for an OTP from their phone number (ie.requestOTP()function)