Skip to content

Commit e777de7

Browse files
committed
fixed bug for receive free nim in tour
1 parent bac6717 commit e777de7

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

src/lib/tour/onboarding/02_TransactionListStep.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { watch } from '@vue/composition-api';
12
import { defaultTooltipModifiers, ITooltipModifier, IWalletHTMLElements } from '..';
23
import { IOnboardingGetStepFnArgs, ITourStep, OnboardingTourStep } from '../types';
34
import { getOnboardingTexts } from './OnboardingTourTexts';
@@ -23,7 +24,7 @@ export function getTransactionListStep(
2324
IWalletHTMLElements.ADDRESS_OVERVIEW_MOBILE_ACTION_BAR,
2425
],
2526
disabledElements: [
26-
...(txsLen() > 0
27+
...(txsLen.value > 0
2728
? [IWalletHTMLElements.ADDRESS_OVERVIEW_TRANSACTIONS]
2829
: [
2930
`${IWalletHTMLElements.ADDRESS_OVERVIEW_TRANSACTIONS} h2`,
@@ -37,14 +38,14 @@ export function getTransactionListStep(
3738
disabledButtons: [
3839
IWalletHTMLElements.BUTTON_SIDEBAR_BUY,
3940
IWalletHTMLElements.BUTTON_SIDEBAR_SELL,
40-
txsLen() === 0 ? '' : IWalletHTMLElements.BUTTON_ADDRESS_OVERVIEW_BUY,
41+
txsLen.value === 0 ? '' : IWalletHTMLElements.BUTTON_ADDRESS_OVERVIEW_BUY,
4142
],
4243
scrollLockedElements: [
4344
`${IWalletHTMLElements.ACCOUNT_OVERVIEW_ADDRESS_LIST} .vue-recycle-scroller`,
4445
`${IWalletHTMLElements.ADDRESS_OVERVIEW_TRANSACTIONS} .vue-recycle-scroller`,
4546
],
4647
explicitInteractableElements: [
47-
txsLen() === 0 ? IWalletHTMLElements.BUTTON_ADDRESS_OVERVIEW_BUY : '',
48+
txsLen.value === 0 ? IWalletHTMLElements.BUTTON_ADDRESS_OVERVIEW_BUY : '',
4849
],
4950
};
5051

@@ -54,7 +55,7 @@ export function getTransactionListStep(
5455
},
5556
tooltip: {
5657
get target() {
57-
if (txsLen() > 0) {
58+
if (txsLen.value > 0) {
5859
return isSmallScreen.value
5960
? `${IWalletHTMLElements.ADDRESS_OVERVIEW_TRANSACTIONS}
6061
.vue-recycle-scroller__item-view:nth-child(2)`
@@ -66,21 +67,21 @@ export function getTransactionListStep(
6667
},
6768
get content() {
6869
return getOnboardingTexts(
69-
OnboardingTourStep.TRANSACTION_LIST)[txsLen() <= 1 ? 'default' : 'alternative'] || [];
70+
OnboardingTourStep.TRANSACTION_LIST)[txsLen.value <= 1 ? 'default' : 'alternative'] || [];
7071
},
7172
params: {
7273
get placement() {
7374
if (!isSmallScreen.value) {
7475
return 'left';
7576
}
76-
return txsLen() > 0 ? 'bottom' : 'top';
77+
return txsLen.value > 0 ? 'bottom' : 'top';
7778
},
7879
get modifiers() {
7980
return [
8081
{
8182
name: 'offset',
8283
options: {
83-
offset: txsLen() > 0 && isSmallScreen.value ? [0, 32] : [0, 20],
84+
offset: txsLen.value > 0 && isSmallScreen.value ? [0, 32] : [0, 20],
8485
},
8586
} as ITooltipModifier,
8687
...defaultTooltipModifiers.filter((d) => d.name !== 'offset'),
@@ -90,25 +91,26 @@ export function getTransactionListStep(
9091
},
9192
lifecycle: {
9293
mounted: ({ goToNextStep }) => {
93-
if (txsLen() > 0) return undefined;
94+
if (txsLen.value > 0) return undefined;
9495

95-
const freeNimBtnSelector = IWalletHTMLElements.ADDRESS_OVERVIEW_ACTIONS;
96-
const freeNimBtn = document.querySelector(freeNimBtnSelector);
97-
if (!freeNimBtn) return undefined;
98-
99-
freeNimBtn.addEventListener('click', () => goToNextStep(), { once: true });
96+
const unwatch = watch(txsLen, (newVal) => {
97+
if (newVal > 0) goToNextStep();
98+
});
10099

101100
// Add hightlight effect to 'Get Free NIM' button
102-
toggleHighlightButton(freeNimBtnSelector, true, 'green');
103-
return () => toggleHighlightButton(freeNimBtnSelector, false, 'green');
101+
toggleHighlightButton(IWalletHTMLElements.ADDRESS_OVERVIEW_ACTIONS, true, 'green');
102+
return () => {
103+
unwatch();
104+
return toggleHighlightButton(IWalletHTMLElements.ADDRESS_OVERVIEW_ACTIONS, false, 'green');
105+
};
104106
},
105107
},
106108
get ui() {
107109
return {
108110
...ui,
109111

110112
// User is expected to click on the 'Get Free NIM' button
111-
isNextStepDisabled: txsLen() === 0,
113+
isNextStepDisabled: txsLen.value === 0,
112114
};
113115
},
114116
};

src/lib/tour/onboarding/03_FirstTransactionStep.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function getFirstTransactionStep({ isSmallScreen, txsLen }: IOnboardingGe
5050
: '.vue-recycle-scroller__item-view:nth-child(2)'}`;
5151
},
5252
content: getOnboardingTexts(OnboardingTourStep.FIRST_TRANSACTION)[
53-
txsLen() === 1 ? 'default' : 'alternative'],
53+
txsLen.value === 1 ? 'default' : 'alternative'],
5454
params: {
5555
get placement() {
5656
return isSmallScreen.value ? 'bottom-start' : 'left';

src/lib/tour/onboarding/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ScreenTypes } from '@/composables/useWindowSize';
22
import { AccountType, useAccountStore } from '@/stores/Account';
3-
import { SetupContext } from '@vue/composition-api';
3+
import { computed, SetupContext } from '@vue/composition-api';
44
import { ITourOrigin, searchComponentByName } from '..';
55
import { IOnboardingGetStepFnArgs, ITourSteps, OnboardingTourStep } from '../types';
66
import { getFirstAddressStep } from './01_FirstAddressStep';
@@ -29,10 +29,10 @@ export function getOnboardingTourSteps({ root }: SetupContext, screenTypes: Scre
2929
// Returns the length of the transaction list for the current active account and active address
3030
// Easier to access component transaction-list which has already been mounted and has the list
3131
// of valid transactions for the current active account and active address
32-
const txsLen = () => {
33-
const txs = (searchComponentByName(root, 'transactions-list') as any).transactions || [];
32+
const txsLen = computed<number>(() => {
33+
const txs = (searchComponentByName(root, 'transactions-list') as any).txsForActiveAddress || [];
3434
return txs.length || 0;
35-
};
35+
});
3636

3737
const { state, activeAccountInfo } = useAccountStore();
3838
const { startedFrom } = (state.tour as { startedFrom: ITourOrigin });

src/lib/tour/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ScreenTypes } from '@/composables/useWindowSize';
2-
import { SetupContext } from '@vue/composition-api';
2+
import { Ref, SetupContext } from '@vue/composition-api';
33
import { NodeHexagon } from '../NetworkMap';
44

55
export enum TourName { ONBOARDING = 'onboarding', NETWORK = 'network' }
@@ -133,7 +133,7 @@ export type IOnboardingGetStepFnArgs = ScreenTypes & {
133133
sleep: (ms: number) => Promise<unknown>,
134134
startedFrom: ITourOrigin,
135135
toggleHighlightButton: (selector: string, highlight: boolean, color: 'gray' | 'orange' | 'green') => void,
136-
txsLen: () => number,
136+
txsLen: Readonly<Ref<number>>,
137137
};
138138

139139
// Every step is defined in its own file as a function. The function receives this interface as a parameter

0 commit comments

Comments
 (0)