plutosdk 1.0.2-beta.4 → 1.0.2-beta.6
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/dist/pluto-sdk.js +217 -217
- package/lib/components/Introduction/index.js +1 -1
- package/lib/components/Purchase/index.d.ts +8 -0
- package/lib/components/Purchase/index.js +30 -2
- package/lib/main.js +0 -4
- package/lib/sdk.d.ts +13 -0
- package/lib/sdk.js +57 -1
- package/lib/utils/Platform.js +3 -2
- package/lib/utils/Utils.d.ts +17 -1
- package/lib/utils/Utils.js +42 -1
- package/lib/utils/config.d.ts +2 -1
- package/lib/utils/config.js +35 -5
- package/package.json +2 -1
|
@@ -11,6 +11,6 @@ export default class Introduction extends PureComponent {
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
render() {
|
|
14
|
-
return (_jsx(Fade, Object.assign({ in: true, timeout: { enter: 1000 } }, { children: _jsxs(Box, Object.assign({ sx: { width: 1, top: '6%', '@media (max-height: 570px)': { top: '2%' }, '@media (
|
|
14
|
+
return (_jsx(Fade, Object.assign({ in: true, timeout: { enter: 1000 } }, { children: _jsxs(Box, Object.assign({ sx: { width: 1, top: '6%', '@media (max-height: 570px)': { top: '2%' }, '@media (max-height: 480px)': { display: 'none' }, textAlign: 'center', position: 'absolute' } }, { children: [_jsx(CatAni, {}), _jsx(Box, Object.assign({ sx: { fontSize: 24, fontWeight: 'bold', color: '#764428' } }, { children: "Catizen" })), _jsx(Box, Object.assign({ sx: { m: '0 auto', width: 360, textAlign: 'center', wordWrap: 'break-word', fontSize: 18, fontWeight: 'bold', color: '#bc805e' } }, { children: "Catizen's Games:Play, Earn, Airdrop!" }))] })) })));
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -6,7 +6,7 @@ import Stack from '@mui/material/Stack';
|
|
|
6
6
|
import PubSub from 'pubsub-js';
|
|
7
7
|
import { CHAIN } from '@tonconnect/ui';
|
|
8
8
|
import { CODE, CURRENCY, PS_PURCHASE_COMPLETED, PS_SWITCH_PAGE, PAGE_ID, PAY_TYPE, TOKEN_NAME } from '../../utils/constant';
|
|
9
|
-
import {
|
|
9
|
+
import { onTelegramAndroid, onTelegramApple, onTelegramEnv } from '../../utils/Utils';
|
|
10
10
|
import Config from '../../utils/Config';
|
|
11
11
|
import user from '../../utils/User';
|
|
12
12
|
import platform from '../../utils/Platform';
|
|
@@ -147,7 +147,7 @@ export default class Purchase extends PureComponent {
|
|
|
147
147
|
render() {
|
|
148
148
|
const { ton, tonOld, tonDiscount, usdt, usdtOld, usdtDiscount, cati, catiOld, catiDiscount, star, starOld, starDiscount } = user.purchaseData;
|
|
149
149
|
const { showSlide } = this.state;
|
|
150
|
-
return (_jsxs(Box, Object.assign({ sx: { width: 1, height: 1, position: 'relative' } }, { children: [_jsx(BlurMask, {}), _jsxs(Box, Object.assign({ sx: { width: 1, height: 1, position: 'relative', overflowY: 'auto', scrollbarWidth: 'none !important', '::-webkit-scrollbar': { display: 'none !important' } } }, { children: [_jsx(Box, { sx: { width: 1, height: 1, position: 'fixed' }, onClick: this.onClickClose }), _jsx(Box, Object.assign({ sx: { width: '100%', position: 'absolute', pointerEvents: 'none',
|
|
150
|
+
return (_jsxs(Box, Object.assign({ sx: { width: 1, height: 1, position: 'relative' } }, { children: [_jsx(BlurMask, {}), _jsxs(Box, Object.assign({ sx: { width: 1, height: 1, position: 'relative', overflowY: 'auto', scrollbarWidth: 'none !important', '::-webkit-scrollbar': { display: 'none !important' } } }, { children: [_jsx(Box, { sx: { width: 1, height: 1, position: 'fixed' }, onClick: this.onClickClose }), _jsx(Box, Object.assign({ sx: { width: '100%', position: 'absolute', pointerEvents: 'none', bottom: 20, '@media (max-height: 480px)': { top: 10 } } }, { children: _jsx(Slide, Object.assign({ direction: 'up', in: showSlide, mountOnEnter: true, unmountOnExit: true, timeout: { enter: 600, exit: 600 }, onExited: this.onExited }, { children: _jsxs(Box, Object.assign({ sx: { width: 1, maxWidth: 430, m: '0 auto', position: 'relative', pointerEvents: 'auto' } }, { children: [_jsx(ContentBg, {}), _jsx(ContentTitle, { title: 'Purchase' }), _jsx(PurchaseInfo, {}), _jsxs(Stack, Object.assign({ spacing: 2, sx: { mx: 5, pb: 4 } }, { children: [this.showTokenPay() ? (_jsxs(_Fragment, { children: [_jsx(PayButton, { currency: CURRENCY.cati, price: cati, oldPrice: catiOld, discount: catiDiscount, onClickPay: this.onClickCati }), _jsx(PayButton, { currency: CURRENCY.ton, price: ton, oldPrice: tonOld, discount: tonDiscount, onClickPay: this.onClickTon }), _jsx(PayButton, { currency: CURRENCY.usdt, price: usdt, oldPrice: usdtOld, discount: usdtDiscount, onClickPay: this.onClickUsdt })] })) : null, this.showStarPay() ? (_jsx(PayButton, { currency: CURRENCY.star, price: star, oldPrice: starOld, discount: starDiscount, onClickPay: this.onClickStar })) : null] }))] })) })) }))] }))] })));
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
153
153
|
*
|
|
@@ -188,4 +188,32 @@ export default class Purchase extends PureComponent {
|
|
|
188
188
|
console.log(error.message);
|
|
189
189
|
});
|
|
190
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
*
|
|
193
|
+
*/
|
|
194
|
+
showTokenPay() {
|
|
195
|
+
if (Config.TEST_MODE) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
//
|
|
199
|
+
if (onTelegramApple()) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
//
|
|
203
|
+
if (onTelegramAndroid()) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
//
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
*
|
|
211
|
+
*/
|
|
212
|
+
showStarPay() {
|
|
213
|
+
if (!onTelegramEnv()) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
//
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
191
219
|
}
|
package/lib/main.js
CHANGED
package/lib/sdk.d.ts
CHANGED
|
@@ -71,3 +71,16 @@ export declare const vibrate: (type: number) => void;
|
|
|
71
71
|
* @param handler
|
|
72
72
|
*/
|
|
73
73
|
export declare const onEvent: (type: string, handler: Function) => void;
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
export declare const isDesktopEnabled: () => boolean;
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param customLink
|
|
81
|
+
*/
|
|
82
|
+
export declare const openGameForWeb: (customLink?: string) => void;
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
*/
|
|
86
|
+
export declare const getCpCustomLink: () => string;
|
package/lib/sdk.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import PubSub from 'pubsub-js';
|
|
2
|
+
import { Base64 } from 'base64-string';
|
|
2
3
|
import { CODE, PAGE_ID, PS_APP_DID_MOUNT, PS_GAME_INFO_LOADED, PS_GAME_READY, PS_SWITCH_PAGE, EVENT_PURCHASE_COMPLETED, EVENT_CHECK_IN_COMPLETED } from './utils/constant';
|
|
3
|
-
import { clipboard } from './utils/Utils';
|
|
4
|
+
import { clipboard, onTelegramAndroid, onTelegramApple, onTelegramClient } from './utils/Utils';
|
|
4
5
|
import Config from './utils/Config';
|
|
5
6
|
import eventManager from './utils/EventManager';
|
|
6
7
|
import user from './utils/User';
|
|
@@ -106,6 +107,25 @@ export const vibrate = (type) => {
|
|
|
106
107
|
export const onEvent = (type, handler) => {
|
|
107
108
|
sdk.onEvent(type, handler);
|
|
108
109
|
};
|
|
110
|
+
/**
|
|
111
|
+
*
|
|
112
|
+
*/
|
|
113
|
+
export const isDesktopEnabled = () => {
|
|
114
|
+
return sdk.isDesktopEnabled();
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* @param customLink
|
|
119
|
+
*/
|
|
120
|
+
export const openGameForWeb = (customLink = '') => {
|
|
121
|
+
sdk.openGameForWeb(customLink);
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
*
|
|
125
|
+
*/
|
|
126
|
+
export const getCpCustomLink = () => {
|
|
127
|
+
return sdk.getCpCustomLink();
|
|
128
|
+
};
|
|
109
129
|
/**
|
|
110
130
|
*
|
|
111
131
|
*/
|
|
@@ -426,6 +446,42 @@ class Sdk {
|
|
|
426
446
|
vibrate(type) {
|
|
427
447
|
platform.vibrate(type);
|
|
428
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
*
|
|
451
|
+
*/
|
|
452
|
+
isDesktopEnabled() {
|
|
453
|
+
return onTelegramClient() && onTelegramApple() && onTelegramAndroid();
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
*
|
|
457
|
+
* @param customLink
|
|
458
|
+
*/
|
|
459
|
+
openGameForWeb(customLink) {
|
|
460
|
+
if (!this.isDesktopEnabled()) {
|
|
461
|
+
console.log(`openGameForWeb not support for web.`);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
//
|
|
465
|
+
if (!Config.GAME_URL) {
|
|
466
|
+
console.log('game url is null');
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
//
|
|
470
|
+
const enc = new Base64();
|
|
471
|
+
const base64Data = enc.encode(Config.INIT_DATA);
|
|
472
|
+
const url = new URL(Config.GAME_URL);
|
|
473
|
+
url.searchParams.append('initdata', base64Data);
|
|
474
|
+
if (customLink) {
|
|
475
|
+
url.searchParams.append('pcplink', customLink);
|
|
476
|
+
}
|
|
477
|
+
platform.openLink(url.href);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
*
|
|
481
|
+
*/
|
|
482
|
+
getCpCustomLink() {
|
|
483
|
+
return Config.CP_CUSTOM_LINK;
|
|
484
|
+
}
|
|
429
485
|
/**
|
|
430
486
|
*
|
|
431
487
|
*/
|
package/lib/utils/Platform.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { CODE, SHARE_TEXT } from './constant';
|
|
11
|
-
import { onMobile } from "./Utils";
|
|
11
|
+
import { onMobile, onTelegramClient } from "./Utils";
|
|
12
12
|
import Config from "./Config";
|
|
13
13
|
import Api from "./Api";
|
|
14
14
|
import user from './User';
|
|
@@ -69,6 +69,7 @@ class Platform {
|
|
|
69
69
|
let icon = user.icon = data['icon'];
|
|
70
70
|
let ticket = data['ticket'];
|
|
71
71
|
Config.TOKEN = data['token'];
|
|
72
|
+
Config.GAME_URL = data['gameurl'];
|
|
72
73
|
return { plutoId, firstName, lastName, icon, ticket };
|
|
73
74
|
});
|
|
74
75
|
}
|
|
@@ -282,7 +283,7 @@ class Platform {
|
|
|
282
283
|
let link = `${user.gameInfo.appUrl}?startapp=g_${Config.GAME_ID}_${user.plutoId}`;
|
|
283
284
|
let text = encodeURIComponent(SHARE_TEXT[Config.GAME_ID] || SHARE_TEXT[1000]);
|
|
284
285
|
let url = `https://t.me/share/url?url=${link}&text=${text}`;
|
|
285
|
-
if (onMobile()) {
|
|
286
|
+
if (onTelegramClient() && onMobile()) {
|
|
286
287
|
this.openTelegramLink(url);
|
|
287
288
|
return;
|
|
288
289
|
}
|
package/lib/utils/Utils.d.ts
CHANGED
|
@@ -14,6 +14,22 @@ export declare const randRange: (min: number, max: number) => number;
|
|
|
14
14
|
* @param name
|
|
15
15
|
*/
|
|
16
16
|
export declare const getRes: (name: string) => string;
|
|
17
|
+
/**
|
|
18
|
+
* 是否在Telegram小游戏环境
|
|
19
|
+
*/
|
|
20
|
+
export declare const onTelegramEnv: () => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 是否在Telegram客户端版的小游戏环境
|
|
23
|
+
*/
|
|
24
|
+
export declare const onTelegramClient: () => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 是否在苹果设备Telegram客户端版的小程序(Mac、iOS、padOS)
|
|
27
|
+
*/
|
|
28
|
+
export declare const onTelegramApple: () => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* 是否在安卓设备Telegram客户端版的小程序
|
|
31
|
+
*/
|
|
32
|
+
export declare const onTelegramAndroid: () => boolean;
|
|
17
33
|
/**
|
|
18
34
|
*
|
|
19
35
|
*/
|
|
@@ -21,7 +37,7 @@ export declare const onMobile: () => boolean;
|
|
|
21
37
|
/**
|
|
22
38
|
*
|
|
23
39
|
*/
|
|
24
|
-
export declare const
|
|
40
|
+
export declare const onAppleClient: () => boolean;
|
|
25
41
|
/**
|
|
26
42
|
*
|
|
27
43
|
* @param text
|
package/lib/utils/Utils.js
CHANGED
|
@@ -28,6 +28,47 @@ export const randRange = (min, max) => {
|
|
|
28
28
|
export const getRes = (name) => {
|
|
29
29
|
return `${Config.RES_URL}${name}`;
|
|
30
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* 是否在Telegram小游戏环境
|
|
33
|
+
*/
|
|
34
|
+
export const onTelegramEnv = () => {
|
|
35
|
+
const pf = Telegram.WebApp.platform;
|
|
36
|
+
const ver = Telegram.WebApp.version;
|
|
37
|
+
if (!pf || pf == 'unknown') {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
//
|
|
41
|
+
if (!ver || ver == '6.0') {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
//
|
|
45
|
+
return true;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* 是否在Telegram客户端版的小游戏环境
|
|
49
|
+
*/
|
|
50
|
+
export const onTelegramClient = () => {
|
|
51
|
+
const pf = Telegram.WebApp.platform;
|
|
52
|
+
if (!pf || pf == 'unknown' || pf.includes('web')) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
//
|
|
56
|
+
return true;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* 是否在苹果设备Telegram客户端版的小程序(Mac、iOS、padOS)
|
|
60
|
+
*/
|
|
61
|
+
export const onTelegramApple = () => {
|
|
62
|
+
const pf = Telegram.WebApp.platform || '';
|
|
63
|
+
return pf.includes('macos') || pf.includes('ios') || pf.includes('pados');
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* 是否在安卓设备Telegram客户端版的小程序
|
|
67
|
+
*/
|
|
68
|
+
export const onTelegramAndroid = () => {
|
|
69
|
+
const pf = Telegram.WebApp.platform || '';
|
|
70
|
+
return pf.includes('android');
|
|
71
|
+
};
|
|
31
72
|
/**
|
|
32
73
|
*
|
|
33
74
|
*/
|
|
@@ -39,7 +80,7 @@ export const onMobile = () => {
|
|
|
39
80
|
/**
|
|
40
81
|
*
|
|
41
82
|
*/
|
|
42
|
-
export const
|
|
83
|
+
export const onAppleClient = () => {
|
|
43
84
|
var _a, _b;
|
|
44
85
|
const ua = new UAParser();
|
|
45
86
|
const browserName = (_a = ua.getBrowser().name) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase();
|
package/lib/utils/config.d.ts
CHANGED
package/lib/utils/config.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Base64 } from "base64-string";
|
|
1
2
|
//debug
|
|
2
3
|
const API_URL_DEBUG = 'https://test-sdk1.pluto.vision/';
|
|
3
4
|
const PAYLOAD_URL_DEBUG = 'https://test-bc1.pluto.vision/api/ton/getTokenPayload';
|
|
@@ -22,7 +23,6 @@ const TOKENS_JETTON_ADDRESS_RELEASE = {
|
|
|
22
23
|
export default class Config {
|
|
23
24
|
/**
|
|
24
25
|
*
|
|
25
|
-
* @param initConfig
|
|
26
26
|
*/
|
|
27
27
|
static init() {
|
|
28
28
|
if (process.env.NODE_ENV == 'development') {
|
|
@@ -32,15 +32,41 @@ export default class Config {
|
|
|
32
32
|
Config.INIT_DATA = process.env.REACT_APP_INIT_DATA;
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
|
|
35
|
+
const urlParams = new URLSearchParams(location.search);
|
|
36
36
|
Config.TEST_MODE = urlParams.get('debug') == '1';
|
|
37
37
|
Config.GAME_ID = urlParams.get('gameid');
|
|
38
38
|
Config.BOT_NAME = urlParams.get('botname');
|
|
39
|
-
Config.
|
|
39
|
+
Config.CP_CUSTOM_LINK = urlParams.get('pcplink');
|
|
40
40
|
//
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
let initData = Telegram.WebApp.initData;
|
|
42
|
+
if (!initData) {
|
|
43
|
+
const enc = new Base64();
|
|
44
|
+
//initdata参数是在非Telegram环境时使用(此参数使用后会从url参数列表中删除)
|
|
45
|
+
//1、CP接入SDK时模拟测试账号(10001...10005)
|
|
46
|
+
//2、游戏运行在WEB端(由Telegram环境跳转到浏览器,将Telegram.WebApp.initData base64)
|
|
47
|
+
initData = urlParams.get('initdata');
|
|
48
|
+
//刷新时无法取到此参数,使用缓存
|
|
49
|
+
if (!initData) {
|
|
50
|
+
initData = window.localStorage.getItem('PLUTO_INIT_DATA') || '';
|
|
51
|
+
}
|
|
52
|
+
//非测试账号
|
|
53
|
+
if (!initData.startsWith('10')) {
|
|
54
|
+
initData = enc.decode(initData);
|
|
55
|
+
}
|
|
56
|
+
//刷新时使用
|
|
57
|
+
if (initData) {
|
|
58
|
+
const base64Data = enc.encode(initData);
|
|
59
|
+
window.localStorage.setItem('PLUTO_INIT_DATA', base64Data);
|
|
60
|
+
}
|
|
43
61
|
}
|
|
62
|
+
//
|
|
63
|
+
Config.INIT_DATA = initData;
|
|
64
|
+
//删除url里Telegram hash参数和initdata
|
|
65
|
+
const baseUrl = window.location.origin + window.location.pathname + window.location.search;
|
|
66
|
+
const url = new URL(baseUrl);
|
|
67
|
+
url.searchParams.delete('initdata');
|
|
68
|
+
url.searchParams.delete('pcplink');
|
|
69
|
+
window.history.replaceState(null, null, url.href);
|
|
44
70
|
}
|
|
45
71
|
//
|
|
46
72
|
if (Config.TEST_MODE) {
|
|
@@ -70,3 +96,7 @@ Config.BOT_NAME = '';
|
|
|
70
96
|
Config.INIT_DATA = '';
|
|
71
97
|
//
|
|
72
98
|
Config.TOKEN = '';
|
|
99
|
+
//
|
|
100
|
+
Config.GAME_URL = '';
|
|
101
|
+
//
|
|
102
|
+
Config.CP_CUSTOM_LINK = '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plutosdk",
|
|
3
|
-
"version": "1.0.2-beta.
|
|
3
|
+
"version": "1.0.2-beta.6",
|
|
4
4
|
"author": "pluto",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"@mui/material": "^5.16.4",
|
|
16
16
|
"@tonconnect/ui": "^2.0.9",
|
|
17
17
|
"axios": "^1.7.4",
|
|
18
|
+
"base64-string": "^1.1.3",
|
|
18
19
|
"pubsub-js": "^1.9.4",
|
|
19
20
|
"react": "^18.3.1",
|
|
20
21
|
"react-dom": "^18.3.1",
|