press-plus
Version:
36 lines (27 loc) • 638 B
text/typescript
let defined = false;
export function hookTestNet() {
const STORAGE_KEY = '__NET_ENV_DEBUG';
if (defined) {
return;
}
defined = true;
if (typeof window === 'undefined') {
return;
}
// @ts-ignore
const rawResult = window.isTestNet;
Object.defineProperty(window, 'isTestNet', {
get() {
const storage = wx.getStorageSync(STORAGE_KEY);
const result = storage === 'test';
return result;
},
set(value) {
wx.setStorageSync(STORAGE_KEY, value ? 'test' : 'release');
},
});
if (typeof rawResult === 'boolean') {
// @ts-ignore
window.isTestNet = rawResult;
}
}