Skip to content

Commit 9468a9c

Browse files
(core) + (tauri): cherry picks & version bump (#5005)
* (tauri) Update account summary when account state changes (#5002) * Handle accountState == `offline` (#4996) * (core) Add new `handle_subscription_payment` rpc method (#4998) * Bump version to `1.27.0-rc5`
1 parent 5dfc618 commit 9468a9c

31 files changed

Lines changed: 302 additions & 153 deletions

File tree

nym-vpn-app/src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nym-vpn-app/src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "nym-vpn-app"
3-
version = "1.27.0-rc4"
3+
version = "1.27.0-rc5"
44
description = "NymVPN desktop client"
55
authors = [
66
"Nym Technologies SA <contact@nymtech.net>",

nym-vpn-app/src-tauri/src/commands/account.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,12 @@ pub async fn get_account_summary(
209209
e.into()
210210
})
211211
}
212+
213+
#[instrument(skip_all)]
214+
#[tauri::command]
215+
pub async fn handle_subscription_payment(vpnd: State<'_, VpndClient>) -> Result<(), BackendError> {
216+
vpnd.handle_subscription_payment().await.map_err(|e| {
217+
error!("failed to handle subscription payment: {e}");
218+
e.into()
219+
})
220+
}

nym-vpn-app/src-tauri/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ async fn main() -> Result<()> {
327327
account::store_deeplink_account,
328328
account::get_autologin_deeplink,
329329
account::get_account_summary,
330+
account::handle_subscription_payment,
330331
cmd_daemon::daemon_status,
331332
cmd_daemon::set_network,
332333
cmd_daemon::system_messages,

nym-vpn-app/src-tauri/src/vpnd/client.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,17 @@ impl VpndClient {
985985
Ok(summary.map(Into::into))
986986
}
987987

988+
pub async fn handle_subscription_payment(&self) -> Result<(), VpndError> {
989+
let mut vpnd = self.vpnd().await?;
990+
991+
vpnd.handle_subscription_payment()
992+
.or_else(async |e| {
993+
self.handle_rpc_error("handle_subscription_payment", e)
994+
.await
995+
})
996+
.await
997+
}
998+
988999
/// Run network diagnostics
9891000
#[instrument(skip_all)]
9901001
pub async fn run_diagnostic(

nym-vpn-app/src/components/privy/PrivyButton.tsx

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { openUrl } from '@tauri-apps/plugin-opener';
2-
import { useEffect, useRef, useState } from 'react';
2+
import { useState } from 'react';
33
import { useTranslation } from 'react-i18next';
44
import { invoke } from '@tauri-apps/api/core';
55
import { useNavigate } from 'react-router';
@@ -9,6 +9,7 @@ import { useDeepLink } from '../../hooks';
99
import { routes } from '../../router';
1010
import { CCache } from '../../cache';
1111
import { StateDispatch, TAccountMode } from '../../types';
12+
import { DeeplinkTimeout } from '../../errors';
1213

1314
function PrivyButton() {
1415
const { t, i18n } = useTranslation('login');
@@ -20,16 +21,6 @@ function PrivyButton() {
2021
const dispatch = useMainDispatch() as StateDispatch;
2122

2223
const [loading, setLoading] = useState(false);
23-
const timeoutIdRef = useRef<ReturnType<typeof setTimeout> | null>(null);
24-
25-
useEffect(() => {
26-
return () => {
27-
if (timeoutIdRef.current !== null) {
28-
clearTimeout(timeoutIdRef.current);
29-
timeoutIdRef.current = null;
30-
}
31-
};
32-
}, []);
3324

3425
const refreshAccountMode = async () => {
3526
const accountMode = await invoke<TAccountMode>('get_account_mode');
@@ -46,17 +37,7 @@ function PrivyButton() {
4637
openUrl(loginUrl);
4738

4839
try {
49-
const timeoutPromise = new Promise<never>((_, reject) => {
50-
timeoutIdRef.current = setTimeout(
51-
() => reject(new Error('Login timeout')),
52-
300000,
53-
);
54-
});
55-
56-
const deeplinkurl = await Promise.race([
57-
startListening(),
58-
timeoutPromise,
59-
]);
40+
const deeplinkurl = await startListening(300000);
6041

6142
await invoke('store_deeplink_account', {
6243
callbackUrl: deeplinkurl,
@@ -75,7 +56,7 @@ function PrivyButton() {
7556
dispatch({ type: 'reset-error' });
7657
} catch (error) {
7758
console.error('Privy login error: ', error);
78-
if (error instanceof Error && error.message === 'Login timeout') {
59+
if (error instanceof DeeplinkTimeout) {
7960
push({
8061
message: t('privy.error.timeout'),
8162
type: 'error',
@@ -91,10 +72,6 @@ function PrivyButton() {
9172
});
9273
}
9374
} finally {
94-
if (timeoutIdRef.current !== null) {
95-
clearTimeout(timeoutIdRef.current);
96-
timeoutIdRef.current = null;
97-
}
9875
setLoading(false);
9976
}
10077
};

nym-vpn-app/src/contexts/autologin/context.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ export type AutologinKind = Extract<
88

99
export type AutologinContextType = {
1010
autologin: (kind: AutologinKind) => Promise<void>;
11+
closeDialog: () => void;
1112
};
1213

1314
const initialState: AutologinContextType = {
1415
autologin: async () => Promise.resolve(),
16+
closeDialog: () => {
17+
/* SCARECROW */
18+
},
1519
};
1620

1721
export const AutologinContext =

nym-vpn-app/src/contexts/autologin/provider.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,23 @@ export function AutologinProvider({ children }: { children: React.ReactNode }) {
3232
} catch (error) {
3333
console.error('Failed to get autologin deeplink', error);
3434
push({
35-
message: t('autologin.initialization-error'),
35+
message: t('autologin.initialization-error', { ns: 'errors' }),
3636
type: 'error',
3737
duration: 3000,
3838
});
3939
}
4040
},
41-
[i18n.language, t, push],
41+
[i18n.language, push, t],
4242
);
4343

44-
const ctx = useMemo(() => ({ autologin }), [autologin]);
44+
const closeDialog = useCallback(() => {
45+
setOpen(false);
46+
}, []);
47+
48+
const ctx = useMemo(
49+
() => ({ autologin, closeDialog }),
50+
[autologin, closeDialog],
51+
);
4552

4653
return (
4754
<AutologinContext.Provider value={ctx}>

nym-vpn-app/src/contexts/main/provider.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { useEffect, useReducer } from 'react';
33
import { InitState, SystemMessage } from '../../types';
44
import { initFirstBatch, initSecondBatch } from '../../state/init';
55
import { useTauriEvents } from '../../state/useTauriEvents';
6+
import { useAccountSummaryOnAccountState } from '../../state/useAccountSummaryOnAccountState';
67
import { useInAppNotify } from '../in-app-notification';
78
import { daemonStatusUpdate, networkEnvChanged } from '../../state/helper';
89
import { CCache } from '../../cache';
@@ -38,6 +39,12 @@ function MainStateProvider({ children, init }: Props) {
3839

3940
const { push } = useInAppNotify();
4041
useTauriEvents(dispatch, push);
42+
useAccountSummaryOnAccountState(
43+
state.accountState,
44+
state.accountSyncing,
45+
state.initialized,
46+
dispatch,
47+
);
4148

4249
// initialize app state
4350
useEffect(() => {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** Thrown when `useDeepLink`’s `startListening` exceeds the given timeout. */
2+
export class DeeplinkTimeout extends Error {
3+
constructor(message = 'Deeplink timed out') {
4+
super(message);
5+
this.name = 'DeeplinkTimeout';
6+
Object.setPrototypeOf(this, new.target.prototype);
7+
}
8+
}

0 commit comments

Comments
 (0)