@jolibox/implement 1.1.37 → 1.1.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.rush/temp/package-deps_build.json +26 -15
- package/dist/common/rewards/registers/utils/coins/commands/index.d.ts +3 -0
- package/dist/common/rewards/registers/utils/coins/commands/use-jolicoin.d.ts +16 -0
- package/dist/common/rewards/registers/utils/coins/commands/use-payment.d.ts +16 -0
- package/dist/common/rewards/registers/utils/coins/commands/use-unlogin.d.ts +18 -0
- package/dist/common/rewards/registers/utils/coins/fetch-balance.d.ts +4 -0
- package/dist/common/rewards/registers/utils/coins/index.d.ts +3 -17
- package/dist/common/rewards/registers/utils/coins/rewards-command.d.ts +1 -0
- package/dist/common/rewards/registers/utils/common.d.ts +8 -0
- package/dist/common/rewards/registers/utils/event-listener.d.ts +1 -0
- package/dist/common/rewards/reward-emitter.d.ts +30 -4
- package/dist/common/utils/index.d.ts +19 -0
- package/dist/index.js +25 -25
- package/dist/index.native.js +132 -46
- package/dist/native/api/login.d.ts +20 -0
- package/dist/native/rewards/check-frequency.d.ts +13 -16
- package/dist/native/rewards/index.d.ts +3 -1
- package/dist/native/rewards/ui/payment-modal.d.ts +1 -0
- package/dist/native/rewards/ui/unlogin-modal.d.ts +1 -0
- package/dist/native/rewards/ui/use-modal.d.ts +1 -0
- package/dist/native/rewards/ui/utils.d.ts +6 -0
- package/implement.build.log +2 -2
- package/package.json +5 -5
- package/src/common/rewards/fetch-reward.ts +6 -3
- package/src/common/rewards/registers/use-jolicoin-only.ts +13 -13
- package/src/common/rewards/registers/use-jolicoin.ts +15 -11
- package/src/common/rewards/registers/utils/coins/commands/index.ts +3 -0
- package/src/common/rewards/registers/utils/coins/commands/use-jolicoin.ts +67 -0
- package/src/common/rewards/registers/utils/coins/commands/use-payment.ts +85 -0
- package/src/common/rewards/registers/utils/coins/commands/use-unlogin.ts +96 -0
- package/src/common/rewards/registers/utils/coins/fetch-balance.ts +15 -0
- package/src/common/rewards/registers/utils/coins/index.ts +45 -99
- package/src/common/rewards/registers/utils/coins/rewards-command.ts +3 -0
- package/src/common/rewards/registers/utils/common.ts +8 -0
- package/src/common/rewards/registers/utils/event-listener.ts +13 -0
- package/src/common/rewards/reward-emitter.ts +33 -4
- package/src/common/rewards/reward-helper.ts +3 -3
- package/src/common/utils/index.ts +20 -0
- package/src/h5/bootstrap/index.ts +20 -2
- package/src/h5/rewards/index.ts +29 -1
- package/src/native/api/ads.ts +17 -7
- package/src/native/api/login.ts +62 -32
- package/src/native/rewards/check-frequency.ts +46 -84
- package/src/native/rewards/index.ts +3 -370
- package/src/native/rewards/ui/payment-modal.ts +254 -0
- package/src/native/rewards/ui/unlogin-modal.ts +121 -0
- package/src/native/rewards/ui/use-modal.ts +104 -0
- package/src/native/rewards/ui/utils.ts +25 -0
|
@@ -1,4 +1,24 @@
|
|
|
1
|
+
type LoginExtra = {
|
|
2
|
+
firstLogin?: {
|
|
3
|
+
reward: {
|
|
4
|
+
rewardType: 'JOLI_COIN';
|
|
5
|
+
rewardValue: number;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare const loginImplement: (params: {
|
|
10
|
+
skipLogin?: boolean;
|
|
11
|
+
triggerFrom?: string;
|
|
12
|
+
}, needExtra?: boolean) => Promise<{
|
|
13
|
+
isLogin: boolean;
|
|
14
|
+
token?: string;
|
|
15
|
+
isFirstLogin?: boolean;
|
|
16
|
+
extra?: LoginExtra;
|
|
17
|
+
}>;
|
|
1
18
|
export declare const login: (...inputs: unknown[]) => Promise<import("@jolibox/types").StandardResponse<{
|
|
2
19
|
isLogin: boolean;
|
|
3
20
|
token?: string;
|
|
21
|
+
isFirstLogin?: boolean;
|
|
22
|
+
extra?: LoginExtra;
|
|
4
23
|
}, unknown>>;
|
|
24
|
+
export {};
|
|
@@ -1,27 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* check can show useModal
|
|
3
|
-
* @param config
|
|
4
|
-
* @returns
|
|
5
|
-
*/
|
|
6
1
|
export declare const checkUseModalFrequency: (config: {
|
|
7
|
-
dailyMaxPopUps
|
|
8
|
-
minInterval
|
|
2
|
+
dailyMaxPopUps?: number;
|
|
3
|
+
minInterval?: number;
|
|
9
4
|
}) => Promise<{
|
|
10
5
|
canShow: boolean;
|
|
11
6
|
isFirst: boolean;
|
|
12
7
|
}>;
|
|
13
|
-
export declare const updateUseModalFrequency: () => Promise<void>;
|
|
14
|
-
/**
|
|
15
|
-
* check can show paymentModal
|
|
16
|
-
*/
|
|
17
8
|
export declare const checkPaymentFrequency: (config: {
|
|
18
|
-
dailyMaxPopUps
|
|
19
|
-
minInterval
|
|
9
|
+
dailyMaxPopUps?: number;
|
|
10
|
+
minInterval?: number;
|
|
11
|
+
}) => Promise<{
|
|
12
|
+
canShow: boolean;
|
|
13
|
+
isFirst: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const checkUnloginModalFrequency: (config: {
|
|
16
|
+
dailyMaxPopUps?: number;
|
|
17
|
+
minInterval?: number;
|
|
20
18
|
}) => Promise<{
|
|
21
19
|
canShow: boolean;
|
|
22
20
|
isFirst: boolean;
|
|
23
21
|
}>;
|
|
24
|
-
|
|
25
|
-
* update paymentFrequency
|
|
26
|
-
*/
|
|
22
|
+
export declare const updateUseModalFrequency: () => Promise<void>;
|
|
27
23
|
export declare const updatePaymentFrequency: () => Promise<void>;
|
|
24
|
+
export declare const updateUnloginModalFrequency: () => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/implement.build.log
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Invoking: npm run clean && npm run build:esm && tsc
|
|
2
2
|
|
|
3
|
-
> @jolibox/implement@1.1.
|
|
3
|
+
> @jolibox/implement@1.1.39 clean
|
|
4
4
|
> rimraf ./dist
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
> @jolibox/implement@1.1.
|
|
7
|
+
> @jolibox/implement@1.1.39 build:esm
|
|
8
8
|
> BUILD_VERSION=$(node -p "require('./package.json').version") node esbuild.config.js --format=esm
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jolibox/implement",
|
|
3
3
|
"description": "This project is Jolibox JS-SDk implement for Native && H5",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.39",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@jolibox/common": "1.1.
|
|
10
|
-
"@jolibox/types": "1.1.
|
|
11
|
-
"@jolibox/native-bridge": "1.1.
|
|
12
|
-
"@jolibox/ads": "1.1.
|
|
9
|
+
"@jolibox/common": "1.1.39",
|
|
10
|
+
"@jolibox/types": "1.1.39",
|
|
11
|
+
"@jolibox/native-bridge": "1.1.39",
|
|
12
|
+
"@jolibox/ads": "1.1.39",
|
|
13
13
|
"localforage": "1.10.0",
|
|
14
14
|
"@jolibox/ui": "1.0.0",
|
|
15
15
|
"web-vitals": "4.2.4"
|
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
UnlockOptionsEventName,
|
|
7
7
|
UseModalFrequencyEventName,
|
|
8
8
|
rewardsEmitter,
|
|
9
|
-
DefaltJoliCoinUseAndCharge
|
|
9
|
+
DefaltJoliCoinUseAndCharge,
|
|
10
|
+
DefaltLoginGuide
|
|
10
11
|
} from './reward-emitter';
|
|
11
12
|
import { StandardResponse } from '@jolibox/types';
|
|
12
13
|
|
|
@@ -59,11 +60,13 @@ export const createRewardFrequencyConfigFetcher = (rewardsHelper: RewardsHelper)
|
|
|
59
60
|
);
|
|
60
61
|
|
|
61
62
|
rewardsEmitter.emit(UseModalFrequencyEventName, {
|
|
62
|
-
joliCoinUseAndCharge: res.data?.joliCoinUseAndCharge || DefaltJoliCoinUseAndCharge
|
|
63
|
+
joliCoinUseAndCharge: res.data?.joliCoinUseAndCharge || DefaltJoliCoinUseAndCharge,
|
|
64
|
+
loginGuide: res.data?.loginGuide || DefaltLoginGuide
|
|
63
65
|
});
|
|
64
66
|
|
|
65
67
|
return {
|
|
66
|
-
joliCoinUseAndCharge: res.data?.joliCoinUseAndCharge || DefaltJoliCoinUseAndCharge
|
|
68
|
+
joliCoinUseAndCharge: res.data?.joliCoinUseAndCharge || DefaltJoliCoinUseAndCharge,
|
|
69
|
+
loginGuide: res.data?.loginGuide || DefaltLoginGuide
|
|
67
70
|
};
|
|
68
71
|
});
|
|
69
72
|
};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { IHttpClient } from '@/common/http';
|
|
2
|
-
import { rewardsEmitter, UnlockOptionsEventName, IUnlockOptionsEvent } from '../reward-emitter';
|
|
3
2
|
import { IAdBreakParams } from '@/common/ads';
|
|
3
|
+
import { createCommonJolicoinRewardHandler } from './utils/coins';
|
|
4
|
+
import { unlockOptionsHandler } from './utils/common';
|
|
4
5
|
import {
|
|
5
|
-
createCommonJolicoinRewardHandler,
|
|
6
6
|
createShowUnlockWithJolicoinModal,
|
|
7
|
-
createInitiateAndAwaitPayment
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { IRewardParams } from '@jolibox/types';
|
|
7
|
+
createInitiateAndAwaitPayment,
|
|
8
|
+
createShowUnloginModal
|
|
9
|
+
} from './utils/coins/commands';
|
|
11
10
|
|
|
12
11
|
export type JolicoinOnlyRewardsHandler = (params: IAdBreakParams) => Promise<boolean>;
|
|
13
12
|
export const createJolicoinOnlyRewardHandler = (
|
|
@@ -20,11 +19,6 @@ export const createJolicoinOnlyRewardHandler = (
|
|
|
20
19
|
onUnlockFailed?: () => void;
|
|
21
20
|
}
|
|
22
21
|
): JolicoinOnlyRewardsHandler => {
|
|
23
|
-
const unlockOptionsHandler = createEventPromiseHandler<IUnlockOptionsEvent, typeof UnlockOptionsEventName>(
|
|
24
|
-
rewardsEmitter,
|
|
25
|
-
UnlockOptionsEventName
|
|
26
|
-
);
|
|
27
|
-
|
|
28
22
|
const handleUnlockFailed = (() => (params: IAdBreakParams) => {
|
|
29
23
|
onUnlockFailed?.();
|
|
30
24
|
params.adBreakDone?.({
|
|
@@ -44,13 +38,19 @@ export const createJolicoinOnlyRewardHandler = (
|
|
|
44
38
|
cancelButtonText: 'jolicoin.noThanks'
|
|
45
39
|
});
|
|
46
40
|
|
|
47
|
-
const
|
|
41
|
+
const showUnloginModal = createShowUnloginModal('JOLI_COIN', {
|
|
42
|
+
confirmButtonText: 'loginGuide.login',
|
|
43
|
+
cancelButtonText: 'loginGuide.noThanks'
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const jolicoinOnlyRewardHandler = createCommonJolicoinRewardHandler('JOLI_COIN', httpClient, {
|
|
48
47
|
handlers: {
|
|
49
48
|
handleUnlockSuccess: onUnlockSuccess,
|
|
50
49
|
handleUnlockFailed,
|
|
51
50
|
unlockOptionsHandler,
|
|
52
51
|
initiateAndAwaitPayment,
|
|
53
|
-
showUnlockWithJolicoinModal
|
|
52
|
+
showUnlockWithJolicoinModal,
|
|
53
|
+
showUnloginModal
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { IHttpClient } from '@/common/http';
|
|
2
|
-
import { rewardsEmitter, UnlockOptionsEventName, IUnlockOptionsEvent } from '../reward-emitter';
|
|
3
2
|
import { IAdBreakParams } from '@/common/ads';
|
|
4
|
-
import {
|
|
3
|
+
import { unlockOptionsHandler } from './utils/common';
|
|
5
4
|
import { createCommonJolicoinRewardHandler } from './utils/coins';
|
|
6
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
createShowUnlockWithJolicoinModal,
|
|
7
|
+
createInitiateAndAwaitPayment,
|
|
8
|
+
createShowUnloginModal
|
|
9
|
+
} from './utils/coins/commands';
|
|
7
10
|
|
|
8
11
|
export type JolicoinRewardsHandler = (params: IAdBreakParams) => Promise<boolean>;
|
|
9
12
|
export const createJolicoinRewardHandler = (
|
|
@@ -16,11 +19,6 @@ export const createJolicoinRewardHandler = (
|
|
|
16
19
|
onUnlockFailed?: () => void;
|
|
17
20
|
}
|
|
18
21
|
): JolicoinRewardsHandler => {
|
|
19
|
-
const unlockOptionsHandler = createEventPromiseHandler<IUnlockOptionsEvent, typeof UnlockOptionsEventName>(
|
|
20
|
-
rewardsEmitter,
|
|
21
|
-
UnlockOptionsEventName
|
|
22
|
-
);
|
|
23
|
-
|
|
24
22
|
const handleUnlockFailed = () => {
|
|
25
23
|
onUnlockFailed?.();
|
|
26
24
|
};
|
|
@@ -35,15 +33,21 @@ export const createJolicoinRewardHandler = (
|
|
|
35
33
|
cancelButtonText: 'jolicoin.noWatchAds'
|
|
36
34
|
});
|
|
37
35
|
|
|
38
|
-
const
|
|
36
|
+
const showUnloginModal = createShowUnloginModal('ADS-JOLI_COIN', {
|
|
37
|
+
confirmButtonText: 'loginGuide.login',
|
|
38
|
+
cancelButtonText: 'loginGuide.noWatchAds'
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const jolicoinRewardHandler = createCommonJolicoinRewardHandler('ADS-JOLI_COIN', httpClient, {
|
|
39
42
|
handlers: {
|
|
40
43
|
handleUnlockSuccess: onUnlockSuccess,
|
|
41
44
|
handleUnlockFailed,
|
|
42
45
|
unlockOptionsHandler,
|
|
43
46
|
initiateAndAwaitPayment,
|
|
44
|
-
showUnlockWithJolicoinModal
|
|
47
|
+
showUnlockWithJolicoinModal,
|
|
48
|
+
showUnloginModal
|
|
45
49
|
}
|
|
46
50
|
});
|
|
47
51
|
|
|
48
|
-
return
|
|
52
|
+
return jolicoinRewardHandler;
|
|
49
53
|
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { IJoliCoin } from '@/common/rewards/type';
|
|
2
|
+
import { rewardsCommands } from '../rewards-command';
|
|
3
|
+
import { unlockOptionsHandler } from '@/common/rewards/registers/utils/common';
|
|
4
|
+
import { createEventPromiseHandler } from '../../event-listener';
|
|
5
|
+
import { IUseModalResultEvent, UseModalResultEventName } from '@/common/rewards/reward-emitter';
|
|
6
|
+
import { rewardsEmitter, UseModalEventName } from '@/common/rewards/reward-emitter';
|
|
7
|
+
|
|
8
|
+
export const registerUseJolicoinCommand = (
|
|
9
|
+
prefix: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
10
|
+
params: {
|
|
11
|
+
showUnlockWithJolicoinModal: (params: {
|
|
12
|
+
enableAutoDeduct: boolean;
|
|
13
|
+
userJoliCoin: IJoliCoin;
|
|
14
|
+
joliCoinQuantity: number;
|
|
15
|
+
}) => Promise<'CONFIRM' | 'CANCEL' | 'FAILED'>;
|
|
16
|
+
}
|
|
17
|
+
) => {
|
|
18
|
+
const { showUnlockWithJolicoinModal } = params;
|
|
19
|
+
rewardsCommands.registerCommand(`Rewards.${prefix}.useJolicoin`, async () => {
|
|
20
|
+
const unlockOptions = await unlockOptionsHandler.getData();
|
|
21
|
+
const enableAutoDeduct = !!unlockOptions?.userJoliCoin?.enableAutoDeduct;
|
|
22
|
+
const joliCoinQuantity =
|
|
23
|
+
unlockOptions?.options?.find((option) => option.type === 'JOLI_COIN')?.joliCoinChoices[0]
|
|
24
|
+
.joliCoinQuantity ?? 0;
|
|
25
|
+
|
|
26
|
+
console.log('-----unlockOptions usemodal-----', unlockOptions, enableAutoDeduct, joliCoinQuantity);
|
|
27
|
+
const shouldUnlock = await showUnlockWithJolicoinModal({
|
|
28
|
+
enableAutoDeduct,
|
|
29
|
+
userJoliCoin: unlockOptions?.userJoliCoin,
|
|
30
|
+
joliCoinQuantity
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (shouldUnlock !== 'CONFIRM') {
|
|
34
|
+
return {
|
|
35
|
+
result: 'FAILED'
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
result: 'SUCCESS'
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// EVENTS
|
|
45
|
+
export const createShowUnlockWithJolicoinModal = (
|
|
46
|
+
type: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
47
|
+
buttons: {
|
|
48
|
+
confirmButtonText: string;
|
|
49
|
+
cancelButtonText: string;
|
|
50
|
+
}
|
|
51
|
+
) => {
|
|
52
|
+
return async (params: { enableAutoDeduct: boolean; userJoliCoin: IJoliCoin; joliCoinQuantity: number }) => {
|
|
53
|
+
const modalHandler = createEventPromiseHandler<IUseModalResultEvent, typeof UseModalResultEventName>(
|
|
54
|
+
rewardsEmitter,
|
|
55
|
+
UseModalResultEventName
|
|
56
|
+
);
|
|
57
|
+
rewardsEmitter.emit(UseModalEventName, type, {
|
|
58
|
+
enableAutoDeduct: params.enableAutoDeduct,
|
|
59
|
+
userJoliCoin: params.userJoliCoin,
|
|
60
|
+
joliCoinQuantity: params.joliCoinQuantity,
|
|
61
|
+
confirmButtonText: buttons.confirmButtonText,
|
|
62
|
+
cancelButtonText: buttons.cancelButtonText
|
|
63
|
+
});
|
|
64
|
+
const modalResult = await modalHandler.getFreshData();
|
|
65
|
+
return modalResult.useModalResult;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { IJoliCoin } from '@/common/rewards/type';
|
|
2
|
+
import { fetchBalance } from '../fetch-balance';
|
|
3
|
+
import { rewardsCommands } from '../rewards-command';
|
|
4
|
+
import { IHttpClient } from '@/common/http';
|
|
5
|
+
import { unlockOptionsHandler } from '../../common';
|
|
6
|
+
import { joliCoinIsEnough } from '../../index';
|
|
7
|
+
import { rewardsEmitter } from '@/common/rewards/reward-emitter';
|
|
8
|
+
import { createEventPromiseHandler } from '../../event-listener';
|
|
9
|
+
import {
|
|
10
|
+
IPaymentEvent,
|
|
11
|
+
PaymentResultEventName,
|
|
12
|
+
InvokePaymentEventName
|
|
13
|
+
} from '@/common/rewards/reward-emitter';
|
|
14
|
+
|
|
15
|
+
export const registerUsePaymentCommand = (
|
|
16
|
+
prefix: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
17
|
+
params: {
|
|
18
|
+
httpClient: IHttpClient;
|
|
19
|
+
initiateAndAwaitPayment: (params: {
|
|
20
|
+
userJoliCoin: IJoliCoin;
|
|
21
|
+
joliCoinQuantity: number;
|
|
22
|
+
}) => Promise<'SUCCESS' | 'FAILED' | 'CANCEL'>;
|
|
23
|
+
}
|
|
24
|
+
) => {
|
|
25
|
+
const { httpClient, initiateAndAwaitPayment } = params;
|
|
26
|
+
rewardsCommands.registerCommand(`Rewards.${prefix}.usePayment`, async () => {
|
|
27
|
+
const unlockOptions = await unlockOptionsHandler.getData();
|
|
28
|
+
const newBalance = await fetchBalance(httpClient);
|
|
29
|
+
const joliCoinQuantity =
|
|
30
|
+
unlockOptions?.options?.find((option) => option.type === 'JOLI_COIN')?.joliCoinChoices[0]
|
|
31
|
+
.joliCoinQuantity ?? 0;
|
|
32
|
+
|
|
33
|
+
const newJoliCoin = {
|
|
34
|
+
balance: newBalance?.balance ?? 0,
|
|
35
|
+
enableAutoDeduct: unlockOptions?.userJoliCoin?.enableAutoDeduct ?? false
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
unlockOptionsHandler.updateData({
|
|
39
|
+
userJoliCoin: newJoliCoin
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
console.log('-----unlockOptions payment-----', unlockOptions, newJoliCoin, joliCoinQuantity);
|
|
43
|
+
if (!joliCoinIsEnough(unlockOptions?.options || [], newJoliCoin)) {
|
|
44
|
+
const paymentResult = await initiateAndAwaitPayment({
|
|
45
|
+
userJoliCoin: newJoliCoin,
|
|
46
|
+
joliCoinQuantity
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
result: paymentResult === 'SUCCESS' ? 'SUCCESS' : 'FAILED'
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
result: 'CONTINUE'
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// events
|
|
60
|
+
export const createInitiateAndAwaitPayment = (
|
|
61
|
+
type: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
62
|
+
buttons: {
|
|
63
|
+
confirmButtonText: string;
|
|
64
|
+
cancelButtonText: string;
|
|
65
|
+
}
|
|
66
|
+
) => {
|
|
67
|
+
return async (params: { userJoliCoin: IJoliCoin; joliCoinQuantity: number }) => {
|
|
68
|
+
const paymentHandler = createEventPromiseHandler<IPaymentEvent, typeof PaymentResultEventName>(
|
|
69
|
+
rewardsEmitter,
|
|
70
|
+
PaymentResultEventName
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
rewardsEmitter.emit(InvokePaymentEventName, type, {
|
|
74
|
+
userJoliCoin: params.userJoliCoin,
|
|
75
|
+
joliCoinQuantity: params.joliCoinQuantity,
|
|
76
|
+
enableAutoDeduct: params.userJoliCoin.enableAutoDeduct,
|
|
77
|
+
confirmButtonText: buttons.confirmButtonText,
|
|
78
|
+
cancelButtonText: buttons.cancelButtonText
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Wait for payment result
|
|
82
|
+
const paymentResult = await paymentHandler.getFreshData();
|
|
83
|
+
return paymentResult.paymentResult;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { context } from '@/common/context';
|
|
2
|
+
import { rewardsCommands } from '../rewards-command';
|
|
3
|
+
import { createEventPromiseHandler } from '../../event-listener';
|
|
4
|
+
import { IUseUnloginModalResultEvent, UseUnloginModalResultEventName } from '@/common/rewards/reward-emitter';
|
|
5
|
+
import { rewardsEmitter, InvokeUnloginModalEventName } from '@/common/rewards/reward-emitter';
|
|
6
|
+
import { createToast } from '@jolibox/ui';
|
|
7
|
+
import { sleep } from '@jolibox/common';
|
|
8
|
+
import { fetchBalance } from '../fetch-balance';
|
|
9
|
+
import { IHttpClient } from '@/common/http';
|
|
10
|
+
import { unlockOptionsHandler } from '../../common';
|
|
11
|
+
|
|
12
|
+
export const registerUseUnloginCommand = (
|
|
13
|
+
prefix: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
14
|
+
params: {
|
|
15
|
+
httpClient: IHttpClient;
|
|
16
|
+
showUnloginModal: () => Promise<{
|
|
17
|
+
result: 'CANCEL' | 'FAILED' | 'SUCCESS' | 'ADS' | 'NOT_SUPPORT';
|
|
18
|
+
rewards?: {
|
|
19
|
+
jolicoin?: {
|
|
20
|
+
isFirstLogin: boolean;
|
|
21
|
+
claimedRewardValue: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
) => {
|
|
27
|
+
const { showUnloginModal, httpClient } = params;
|
|
28
|
+
rewardsCommands.registerCommand(`Rewards.${prefix}.useUnloginModal`, async () => {
|
|
29
|
+
const isLogin = context.hostUserInfo?.isLogin;
|
|
30
|
+
const unlockOptions = await unlockOptionsHandler.getData();
|
|
31
|
+
console.log('-----isLogin-----', !!isLogin);
|
|
32
|
+
if (!isLogin) {
|
|
33
|
+
const unloginModalResult = await showUnloginModal();
|
|
34
|
+
|
|
35
|
+
console.log('-----unloginModalResult-----', unloginModalResult);
|
|
36
|
+
if (unloginModalResult.result == 'FAILED' || unloginModalResult.result == 'CANCEL') {
|
|
37
|
+
return {
|
|
38
|
+
result: 'FAILED'
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const { isFirstLogin, claimedRewardValue } = unloginModalResult.rewards?.jolicoin ?? {};
|
|
43
|
+
if (unloginModalResult.result == 'SUCCESS') {
|
|
44
|
+
if (isFirstLogin && claimedRewardValue) {
|
|
45
|
+
await sleep(3000); // wait for center toast to show
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//check balance
|
|
49
|
+
const newBalance = await fetchBalance(httpClient);
|
|
50
|
+
const joliCoinQuantity =
|
|
51
|
+
unlockOptions?.options?.find((option) => option.type === 'JOLI_COIN')?.joliCoinChoices[0]
|
|
52
|
+
.joliCoinQuantity ?? 0;
|
|
53
|
+
|
|
54
|
+
const newJoliCoin = {
|
|
55
|
+
balance: newBalance?.balance ?? 0,
|
|
56
|
+
enableAutoDeduct: unlockOptions?.userJoliCoin?.enableAutoDeduct ?? false
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
unlockOptionsHandler.updateData({
|
|
60
|
+
userJoliCoin: newJoliCoin
|
|
61
|
+
});
|
|
62
|
+
if (newJoliCoin.balance >= joliCoinQuantity) {
|
|
63
|
+
return {
|
|
64
|
+
result: 'SUCCESS'
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
result: 'CONTINUE'
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
//EVENTS
|
|
76
|
+
|
|
77
|
+
export const createShowUnloginModal = (
|
|
78
|
+
type: 'JOLI_COIN' | 'ADS-JOLI_COIN',
|
|
79
|
+
buttons: {
|
|
80
|
+
confirmButtonText: string;
|
|
81
|
+
cancelButtonText: string;
|
|
82
|
+
}
|
|
83
|
+
) => {
|
|
84
|
+
return async () => {
|
|
85
|
+
const modalHandler = createEventPromiseHandler<
|
|
86
|
+
IUseUnloginModalResultEvent,
|
|
87
|
+
typeof UseUnloginModalResultEventName
|
|
88
|
+
>(rewardsEmitter, UseUnloginModalResultEventName);
|
|
89
|
+
rewardsEmitter.emit(InvokeUnloginModalEventName, type, {
|
|
90
|
+
confirmButtonText: buttons.confirmButtonText,
|
|
91
|
+
cancelButtonText: buttons.cancelButtonText
|
|
92
|
+
});
|
|
93
|
+
const modalResult = await modalHandler.getFreshData();
|
|
94
|
+
return modalResult;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IHttpClient } from '@/common/http';
|
|
2
|
+
import { StandardResponse } from '@jolibox/types';
|
|
3
|
+
|
|
4
|
+
export const fetchBalance = async (httpClient: IHttpClient) => {
|
|
5
|
+
const res = await httpClient.get<
|
|
6
|
+
StandardResponse<{
|
|
7
|
+
balance: number;
|
|
8
|
+
}>
|
|
9
|
+
>('/api/joli-coin/balance', {
|
|
10
|
+
query: {
|
|
11
|
+
type: 'JOLI_COIN'
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return res.data;
|
|
15
|
+
};
|