Skip to content
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

Fix sora card phone and route #952

Merged
merged 7 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/App/Menu/AppMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<sidebar-item-content
tag="a"
rel="nofollow noopener"
tabindex="-1"
:href="item.href"
:icon="item.icon"
:title="t(`mainMenu.${item.title}`)"
Expand Down
6 changes: 5 additions & 1 deletion src/components/SidebarItemContent.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<component :is="tag" :class="classes">
<component :is="tag" :class="classes" :tabindex="tabindex">
<!-- TODO: [TECH] move from fonts provided values -->
<div v-if="icon === 'sora-card'" class="icon-container">
<side-menu-card class="sora-card-sidebar-icon" />
Expand All @@ -26,6 +26,7 @@ export default class SidebarItemContent extends Mixins(TranslationMixin) {
@Prop({ default: '', type: String }) readonly icon!: string;
@Prop({ default: '', type: String }) readonly title!: string;
@Prop({ default: 'div', type: String }) readonly tag!: string;
@Prop() readonly tabindex!: string | number;

get classes(): Array<string> {
const base = 'sidebar-item-content';
Expand Down Expand Up @@ -98,4 +99,7 @@ $icon-size: 42px;
background-repeat: no-repeat;
background-position: center center;
}
.el-menu-item:not(.is-active):not(.is-disabled):focus .sora-card-sidebar-icon path {
fill: var(--s-color-base-content-secondary) !important; // focus state of sora card item
}
</style>
65 changes: 53 additions & 12 deletions src/components/SoraCard/steps/Phone.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
<template>
<div>
<div class="sora-card__number-input">
<s-input
ref="number"
placeholder="Phone number"
type="number"
v-model="phoneNumber"
:disabled="phoneInputDisabled"
/>
<div class="phone-container s-flex">
<s-input
class="phone-code"
:placeholder="countryCodePlaceholder"
v-maska="'+###'"
v-model="countryCode"
:disabled="phoneInputDisabled"
/>
<s-input
ref="number"
class="phone-number"
placeholder="Phone number"
v-maska="'############'"
v-model="phoneNumber"
:disabled="phoneInputDisabled"
/>
</div>
<!-- <input v-mask="['+# (###) ### ## ##']" /> TODO: format number depending on country code-->
<s-button
type="secondary"
Expand Down Expand Up @@ -50,6 +60,8 @@ import { action, getter, state } from '@/store/decorators';
import { VerificationStatus } from '@/types/card';
import { XOR } from '@sora-substrate/util/build/assets/consts';

const MIN_PHONE_LENGTH_WITH_CODE = 8;

@Component
export default class Phone extends Mixins(TranslationMixin, mixins.LoadingMixin) {
@state.soraCard.authLogin authLogin!: any;
Expand All @@ -64,6 +76,7 @@ export default class Phone extends Mixins(TranslationMixin, mixins.LoadingMixin)
@Prop({ default: false, type: Boolean }) readonly userApplied!: boolean;

phoneNumber = '';
countryCode = '';
verificationCode = '';
smsSent = false;
smsResendTimer = null;
Expand Down Expand Up @@ -99,19 +112,26 @@ export default class Phone extends Mixins(TranslationMixin, mixins.LoadingMixin)
}

sendSms(): void {
this.authLogin.PayWingsSendOtp('+' + this.phoneNumber, 'Your verification code is: @Otp').catch((error) => {
console.error(error);
});
this.authLogin
.PayWingsSendOtp(`${this.countryCode}${this.phoneNumber}`, 'Your verification code is: @Otp')
.catch((error) => {
console.error(error);
});

this.startSmsCountDown();
}

/** Real example when `countryCode` is empty */
get countryCodePlaceholder(): string {
return this.countryCode ? 'Code' : '+1';
}

get buttonDisabled() {
return !this.verificationCode || this.notPassedKycAndNotHasXorEnough;
}

get otpInputDisabled(): boolean {
return !this.smsSent || !this.phoneNumber;
return !this.smsSent || !this.isPhoneNumberValid;
}

get buttonText(): string {
Expand Down Expand Up @@ -139,8 +159,13 @@ export default class Phone extends Mixins(TranslationMixin, mixins.LoadingMixin)
return this.soraNetwork === WALLET_CONSTS.SoraNetwork.Prod;
}

get isPhoneNumberValid(): boolean {
const code = this.countryCode.replace('+', '');
return !!(+code && this.phoneNumber && `${code}${this.phoneNumber}`.length >= MIN_PHONE_LENGTH_WITH_CODE);
}

get sendSmsDisabled(): boolean {
return !this.phoneNumber || this.smsSent;
return !this.isPhoneNumberValid || this.smsSent;
}

get phoneInputDisabled(): boolean {
Expand Down Expand Up @@ -292,3 +317,19 @@ input::-webkit-inner-spin-button {
-webkit-appearance: none;
}
</style>

<style lang="scss" scoped>
.phone {
&-code {
flex: 1;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
&-number {
flex: 5;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
margin-left: 2px;
}
}
</style>
4 changes: 2 additions & 2 deletions src/store/settings/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ const getters = defineGetters<SettingsState>()({
const { state } = settingsGetterContext(args);
return !!state.featureFlags.charts && state.сhartsEnabled;
},
soraCardEnabled(...args): boolean {
soraCardEnabled(...args): Nullable<boolean> {
const { state } = settingsGetterContext(args);
return !!state.featureFlags.soraCard;
return state.featureFlags.soraCard;
},
notificationActivated(...args): boolean {
const { state } = settingsGetterContext(args);
Expand Down
18 changes: 11 additions & 7 deletions src/views/SoraCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
</template>

<script lang="ts">
import { Component, Mixins, Watch } from 'vue-property-decorator';
import { mixins } from '@soramitsu/soraneo-wallet-web';

import SubscriptionsMixin from '@/components/mixins/SubscriptionsMixin';
import { action, getter } from '@/store/decorators';
import { goTo, lazyComponent } from '@/router';
import { Components, PageNames } from '@/consts';

import { Component, Mixins } from 'vue-property-decorator';
import { VerificationStatus } from '@/types/card';
import type { VerificationStatus } from '@/types/card';

enum Step {
StartPage = 'StartPage',
Expand All @@ -31,7 +31,7 @@ enum Step {
})
export default class SoraCardIntroPage extends Mixins(mixins.LoadingMixin, SubscriptionsMixin) {
@getter.soraCard.currentStatus private currentStatus!: VerificationStatus;
@getter.settings.soraCardEnabled private soraCardEnabled!: boolean;
@getter.settings.soraCardEnabled private soraCardEnabled!: Nullable<boolean>;

@action.soraCard.getUserStatus private getUserStatus!: AsyncFnWithoutArgs;
@action.soraCard.subscribeToTotalXorBalance private subscribeToTotalXorBalance!: AsyncFnWithoutArgs;
Expand All @@ -42,6 +42,13 @@ export default class SoraCardIntroPage extends Mixins(mixins.LoadingMixin, Subsc

Step = Step;

@Watch('soraCardEnabled', { immediate: true })
private checkAvailability(value: Nullable<boolean>): void {
if (value === false) {
goTo(PageNames.Swap);
}
}

confirmApply(userApplied: boolean): void {
this.userApplied = userApplied;
this.step = Step.KYC;
Expand All @@ -67,9 +74,6 @@ export default class SoraCardIntroPage extends Mixins(mixins.LoadingMixin, Subsc
}

created(): void {
if (!this.soraCardEnabled) {
goTo(PageNames.Swap);
}
this.subscribeToTotalXorBalance();
}

Expand Down