fcm 拉活
This commit is contained in:
@@ -30,7 +30,7 @@ import {
|
||||
PhonePePersonalBind,
|
||||
FreechargePersonalBind,
|
||||
proxyBackgroundService,
|
||||
type TokenAutoRebindDeps,
|
||||
type RebindConfig,
|
||||
PhonePePersonalBindResult,
|
||||
PaytmPersonalBindResult,
|
||||
MobikwikPersonalBind,
|
||||
@@ -55,9 +55,6 @@ import Api, {
|
||||
WalletItem,
|
||||
loadServerDomain,
|
||||
getServerDomain,
|
||||
getTokenAutoRebindEnabled,
|
||||
getTokenAutoRebindOptions,
|
||||
saveTokenAutoRebindEnabled,
|
||||
} from '../services/api';
|
||||
|
||||
function formatWalletTypeLabel(walletType: string) {
|
||||
@@ -125,7 +122,6 @@ interface HomeScreenState {
|
||||
// proxy
|
||||
proxyStatus: 'idle' | 'connecting' | 'connected' | 'disconnected' | 'error';
|
||||
proxyError?: string;
|
||||
tokenAutoRebind: boolean;
|
||||
// server settings
|
||||
showServerSettings: boolean;
|
||||
settingsHost: string;
|
||||
@@ -171,7 +167,6 @@ export default class HomeScreen extends Component<any, HomeScreenState> {
|
||||
freechargePersonalBindType: 'otpMode',
|
||||
showAmazonPayPersonalBind: false,
|
||||
proxyStatus: 'idle',
|
||||
tokenAutoRebind: false,
|
||||
showServerSettings: false,
|
||||
settingsHost: '',
|
||||
settingsPort: '',
|
||||
@@ -219,9 +214,6 @@ export default class HomeScreen extends Component<any, HomeScreenState> {
|
||||
async componentDidMount() {
|
||||
await loadServerDomain();
|
||||
await this.loadAdid();
|
||||
const tokenAutoRebind = getTokenAutoRebindEnabled();
|
||||
this.setState({ tokenAutoRebind });
|
||||
proxyBackgroundService.setTokenAutoRebindEnabled(tokenAutoRebind);
|
||||
|
||||
const doLogin = () => {
|
||||
Api.instance.login('test123', '123456').then(async () => {
|
||||
@@ -245,16 +237,11 @@ export default class HomeScreen extends Component<any, HomeScreenState> {
|
||||
if (nextAppState === 'active') this.fetchWallets();
|
||||
};
|
||||
|
||||
buildTokenAutoRebindDeps = (): TokenAutoRebindDeps => ({
|
||||
listWallets: () => Api.instance.listWallets(),
|
||||
register: (_wallet, walletType: WalletType, params: Record<string, unknown>) =>
|
||||
Api.instance.register(walletType, params),
|
||||
getUserToken: () => Api.instance.getUserToken(),
|
||||
buildRebindConfig = (): RebindConfig => ({
|
||||
baseUrl: Api.BASE_URL,
|
||||
userId: Api.instance.getUserId(),
|
||||
userToken: Api.instance.getUserToken(),
|
||||
onRebound: () => this.fetchWallets(),
|
||||
isActive: async (w) => w.status === 'ACTIVE' || w.otpMode === true,
|
||||
log: this.state.tokenAutoRebind
|
||||
? (...args: unknown[]) => console.log('[TokenAutoRebind]', ...args)
|
||||
: undefined,
|
||||
});
|
||||
|
||||
async startProxyClient() {
|
||||
@@ -262,11 +249,7 @@ export default class HomeScreen extends Component<any, HomeScreenState> {
|
||||
this.clientId = DeviceInfo.getUniqueIdSync();
|
||||
const userId = Api.instance.getUserId();
|
||||
this.setState({ proxyStatus: 'connecting' });
|
||||
proxyBackgroundService.configureTokenAutoRebind(
|
||||
this.buildTokenAutoRebindDeps(),
|
||||
getTokenAutoRebindOptions(),
|
||||
);
|
||||
proxyBackgroundService.setTokenAutoRebindEnabled(this.state.tokenAutoRebind);
|
||||
await proxyBackgroundService.syncRebindConfig(this.buildRebindConfig());
|
||||
await proxyBackgroundService.start({
|
||||
wsUrl: Api.WS_URL,
|
||||
clientId: this.clientId || '',
|
||||
@@ -274,6 +257,7 @@ export default class HomeScreen extends Component<any, HomeScreenState> {
|
||||
heartbeatInterval: 10000,
|
||||
reconnectInterval: 5000,
|
||||
reconnectMaxAttempts: Infinity,
|
||||
registerFcmToken: (clientId, fcmToken) => Api.instance.registerFcmToken(clientId, fcmToken),
|
||||
onConnected: () => this.setState({ proxyStatus: 'connected' }),
|
||||
onDisconnected: () => this.setState({ proxyStatus: 'disconnected' }),
|
||||
onError: (error: string) => this.setState({ proxyStatus: 'error', proxyError: error }),
|
||||
@@ -286,24 +270,13 @@ export default class HomeScreen extends Component<any, HomeScreenState> {
|
||||
|
||||
stopProxyClient() {
|
||||
try {
|
||||
proxyBackgroundService.configureTokenAutoRebind(null);
|
||||
void proxyBackgroundService.syncRebindConfig(null);
|
||||
proxyBackgroundService.stop();
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
toggleTokenAutoRebind = async (enabled: boolean) => {
|
||||
this.setState({ tokenAutoRebind: enabled }, () => {
|
||||
proxyBackgroundService.configureTokenAutoRebind(
|
||||
this.buildTokenAutoRebindDeps(),
|
||||
getTokenAutoRebindOptions(),
|
||||
);
|
||||
});
|
||||
await saveTokenAutoRebindEnabled(enabled);
|
||||
proxyBackgroundService.setTokenAutoRebindEnabled(enabled);
|
||||
};
|
||||
|
||||
/** OTP / bind:API catch → { success:false, message } */
|
||||
private wrapOtpCall = async (fn: () => Promise<any>): Promise<any> => {
|
||||
try {
|
||||
@@ -381,14 +354,21 @@ export default class HomeScreen extends Component<any, HomeScreenState> {
|
||||
/** Token bind: client calls register (do not infer modal key from wallet type alone) */
|
||||
handleBindSuccess = (key: keyof HomeScreenState, walletType: WalletType, msg: string) =>
|
||||
async (result: any) => {
|
||||
try {
|
||||
await Api.instance.register(walletType, result);
|
||||
const finishSuccess = () => {
|
||||
this.setState({ [key]: false } as any);
|
||||
Alert.alert('Bind Success', msg);
|
||||
this.fetchWallets();
|
||||
} catch (error) {
|
||||
};
|
||||
const finishSilent = () => {
|
||||
this.setState({ [key]: false } as any);
|
||||
Alert.alert('Bind Failed', (error as Error).message);
|
||||
};
|
||||
|
||||
try {
|
||||
await Api.instance.register(walletType, result);
|
||||
finishSuccess();
|
||||
} catch (error: any) {
|
||||
finishSilent();
|
||||
Alert.alert('Bind Failed', (error as Error).message || 'Bind failed');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1062,7 +1042,6 @@ export default class HomeScreen extends Component<any, HomeScreenState> {
|
||||
error: { label: 'Error', color: '#e74c3c' },
|
||||
};
|
||||
const { label, color } = proxyCfg[proxyStatus];
|
||||
const { tokenAutoRebind } = this.state;
|
||||
|
||||
return (
|
||||
<View style={s.container}>
|
||||
@@ -1075,15 +1054,6 @@ export default class HomeScreen extends Component<any, HomeScreenState> {
|
||||
Proxy {label}{proxyStatus === 'error' && proxyError ? `: ${proxyError}` : ''}
|
||||
</Text>
|
||||
</View>
|
||||
<View style={s.autoRebindRow}>
|
||||
<Text style={s.autoRebindLabel}>Token 失效自动重绑</Text>
|
||||
<Switch
|
||||
value={tokenAutoRebind}
|
||||
onValueChange={this.toggleTokenAutoRebind}
|
||||
trackColor={{ false: '#ddd', true: '#3498db80' }}
|
||||
thumbColor={tokenAutoRebind ? '#3498db' : '#999'}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 10 }}>
|
||||
<TouchableOpacity
|
||||
|
||||
Reference in New Issue
Block a user