Skip to content

Commit 83c5f9e

Browse files
authored
Merge pull request session-foundation#1885 from session-foundation/pro-backend-retry
fix: improve pro backend retry logic
2 parents 7f134e8 + ff7c1de commit 83c5f9e

22 files changed

Lines changed: 543 additions & 286 deletions

File tree

.mocharc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"exit": true,
33
"spec": ["app/ts/test/**/*_test.js"],
4-
"require": ["jsdom-global/register"],
4+
"require": ["jsdom-global/register", "app/ts/test/test-utils/setup.js"],
55
"timeout": 10000,
66
"recursive": true,
77
"reporter": "spec"

build/copySource.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type PackageJson = Record<string, unknown> & {
1616

1717
type MocharcJson = Record<string, unknown> & {
1818
spec: Array<string>;
19+
require: Array<string>;
1920
};
2021

2122
async function copySource(): Promise<void> {
@@ -54,6 +55,12 @@ async function copySource(): Promise<void> {
5455
}
5556
return specPath;
5657
});
58+
mocharcJson.require = mocharcJson.require.map(requirePath => {
59+
if (requirePath.startsWith('app/')) {
60+
return requirePath.slice(4);
61+
}
62+
return requirePath;
63+
});
5764

5865
await fs.writeFile(destMocharcJsonPath, JSON.stringify(mocharcJson, null, 2));
5966
console.log(' ✓ Modified and copied .mocharc.json');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"framer-motion": "^12.5.0",
9797
"fs-extra": "11.3.0",
9898
"image-type": "^4.1.0",
99-
"libsession_util_nodejs": "https://github.com/session-foundation/libsession-util-nodejs/releases/download/v0.6.16/libsession_util_nodejs-v0.6.16.tar.gz",
99+
"libsession_util_nodejs": "https://github.com/session-foundation/libsession-util-nodejs/releases/download/v0.6.17/libsession_util_nodejs-v0.6.17.tar.gz",
100100
"libsodium-wrappers-sumo": "^0.7.15",
101101
"linkify-it": "^5.0.0",
102102
"lodash": "^4.17.21",

pnpm-lock.yaml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ts/components/dialog/debug/DebugMenuModal.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ function MainPage({ setPage }: DebugMenuPageProps) {
129129
}
130130
</DebugMenuSection>
131131
) : null}
132+
<div>
133+
<AboutInfo />
134+
<OtherInfo />
135+
</div>
132136
<FeatureFlags forceUpdate={forceUpdate} />
133137
<ProDebugSection forceUpdate={forceUpdate} setPage={setPage} />
134138
{isDebug ? <FeatureFlagDumper forceUpdate={forceUpdate} /> : null}
@@ -141,10 +145,6 @@ function MainPage({ setPage }: DebugMenuPageProps) {
141145
{isDebug ? <DebugUrlInteractionsSection /> : null}
142146
{isDebug ? <DebugCtaInteractionsSection /> : null}
143147
<ReleaseChannel />
144-
<div>
145-
<AboutInfo />
146-
<OtherInfo />
147-
</div>
148148
</div>
149149
);
150150
}

ts/components/dialog/debug/FeatureFlags.tsx

Lines changed: 68 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { isBoolean, isNil } from 'lodash';
22
import { Dispatch, useCallback, useEffect, useMemo, useState } from 'react';
33
import { clipboard } from 'electron';
44
import useAsync from 'react-use/lib/useAsync';
5-
import { ProConfig, ProProof } from 'libsession_util_nodejs';
5+
import { ProConfig, type ProProof } from 'libsession_util_nodejs';
66
import { getAppDispatch } from '../../../state/dispatch';
77
import {
88
getDataFeatureFlag,
@@ -44,6 +44,8 @@ import {
4444
useProBackendProDetails,
4545
useProBackendRefetch,
4646
} from '../../../state/selectors/proBackendData';
47+
import ProBackendAPI from '../../../session/apis/pro_backend_api/ProBackendAPI';
48+
import { getProMasterKeyHex } from '../../../session/utils/User';
4749

4850
type FeatureFlagToggleType = {
4951
forceUpdate: () => void;
@@ -728,13 +730,10 @@ function ProConfigForm({
728730
forceUpdate: () => Promise<void>;
729731
}) {
730732
const hasProConfig = !proConfig || typeof proConfig === 'object';
731-
const [error, setError] = useState<Error | null>();
732733
const [rotatingPrivKeyInput, setRotatingPrivKeyInput] = useState<string>(
733734
proConfig?.rotatingPrivKeyHex ?? ''
734735
);
735-
const [rotatingPubKeyInput, setRotatingPubKeyInput] = useState<string>(
736-
proConfig?.proProof.rotatingPubkeyHex ?? ''
737-
);
736+
738737
const [expiryInput, setExpiryInput] = useState<string>(
739738
proConfig?.proProof.expiryMs.toString() ?? ''
740739
);
@@ -746,105 +745,18 @@ function ProConfigForm({
746745
proConfig?.proProof.version.toString() ?? ''
747746
);
748747

749-
const [configDumpValue, setConfigDumpValue] = useState<string>(
750-
hasProConfig ? JSON.stringify(proConfig) : ''
751-
);
752-
753-
const setProProof = useCallback(
754-
async (config: Parameters<typeof UserConfigWrapperActions.setProConfig>[0]) => {
755-
try {
756-
await UserConfigWrapperActions.setProConfig(config);
757-
} catch (e) {
758-
window?.log?.error(e);
759-
setError(e);
760-
}
761-
},
762-
[]
763-
);
764-
765-
const save = useCallback(async () => {
766-
const proProof = {
767-
rotatingPubkeyHex: rotatingPubKeyInput,
768-
expiryMs: Number(expiryInput),
769-
signatureHex: sigInput,
770-
genIndexHashB64: genHashInput,
771-
version: Number(versionInput),
772-
} satisfies ProProof;
773-
const rotatingSeedHex = await UserUtils.getProRotatingSeedHex();
774-
await setProProof({
775-
proProof,
776-
rotatingSeedHex,
777-
});
778-
}, [setProProof, rotatingPubKeyInput, expiryInput, sigInput, genHashInput, versionInput]);
779-
780-
const copy = useCallback(() => {
781-
const json = JSON.stringify(proConfig);
782-
clipboard.writeText(json);
783-
ToastUtils.pushToastSuccess('flag-dumper-toast-copy', 'Copied to clipboard');
784-
}, [proConfig]);
785-
786-
const setConfig = useCallback(async () => {
787-
try {
788-
const parsed = JSON.parse(configDumpValue) as ProConfig;
789-
790-
// Update all the input fields with the pasted config
791-
setRotatingPrivKeyInput(parsed.rotatingPrivKeyHex ?? '');
792-
setRotatingPubKeyInput(parsed.proProof.rotatingPubkeyHex ?? '');
793-
setExpiryInput(parsed.proProof.expiryMs.toString() ?? '');
794-
setSigInput(parsed.proProof.signatureHex ?? '');
795-
setGenHashInput(parsed.proProof.genIndexHashB64 ?? '');
796-
setVersionInput(parsed.proProof.version.toString() ?? '');
797-
798-
ToastUtils.pushToastSuccess('flag-dumper-toast-paste', 'Pasted from clipboard');
799-
await forceUpdate();
800-
} catch (e) {
801-
window?.log?.error(e);
802-
ToastUtils.pushToastError('flag-dumper-toast-paste-error', `Failed to paste: ${e?.message}`);
803-
}
804-
}, [configDumpValue, forceUpdate]);
805-
806748
const removeConfig = useCallback(async () => {
807749
await UserConfigWrapperActions.removeProConfig();
808750
setRotatingPrivKeyInput('');
809-
setRotatingPubKeyInput('');
810751
setExpiryInput('');
811752
setSigInput('');
812753
setGenHashInput('');
813754
setVersionInput('');
814-
setConfigDumpValue('');
815755
await forceUpdate();
816756
}, [forceUpdate]);
817757

818758
return (
819759
<div style={{ width: '100%' }}>
820-
<h2>Pro Config Dumper</h2>
821-
<DebugButton onClick={copy} disabled={!hasProConfig}>
822-
Copy Config Dump
823-
</DebugButton>
824-
<DebugButton onClick={setConfig} disabled={!configDumpValue?.length}>
825-
Set Config Dump
826-
</DebugButton>
827-
<label
828-
style={{
829-
display: 'block',
830-
color: 'var(--text-primary-color)',
831-
}}
832-
>
833-
Config Dump
834-
</label>
835-
<textarea
836-
style={{
837-
width: '100%',
838-
minWidth: '100px',
839-
padding: 'var(--margins-xs) var(--margins-sm)',
840-
backgroundColor: 'var(--background-primary-color)',
841-
color: 'var(--text-primary-color)',
842-
border: 'var(--default-borders)',
843-
borderRadius: 'var(--border-radius)',
844-
}}
845-
onChange={e => setConfigDumpValue(e.target.value)}
846-
defaultValue={configDumpValue}
847-
/>
848760
<h2>Pro Config</h2>
849761
<DebugButton
850762
onClick={removeConfig}
@@ -858,17 +770,10 @@ function ProConfigForm({
858770
value={rotatingPrivKeyInput}
859771
setValue={setRotatingPrivKeyInput}
860772
/>
861-
<DebugInput
862-
label="Rotating Public Key"
863-
value={rotatingPubKeyInput}
864-
setValue={setRotatingPubKeyInput}
865-
/>
866773
<DebugInput label="Expiry Timestamp (ms)" value={expiryInput} setValue={setExpiryInput} />
867774
<DebugInput label="Signature" value={sigInput} setValue={setSigInput} />
868775
<DebugInput label="Gen Hash" value={genHashInput} setValue={setGenHashInput} />
869776
<DebugInput label="Version" value={versionInput} setValue={setVersionInput} />
870-
<DebugButton onClick={save}>Set Pro Config</DebugButton>
871-
{error?.message ? error.message : null}
872777
</div>
873778
);
874779
}
@@ -991,25 +896,70 @@ export const ProDebugSection = ({
991896
<DebugMenuSection title="Session Pro">
992897
<FlagToggle forceUpdate={forceUpdate} flag="proAvailable" label="Pro Beta Released" />
993898
{proAvailable ? (
994-
<DebugButton buttonColor={SessionButtonColor.Danger} onClick={resetPro}>
995-
Reset All Pro State
996-
</DebugButton>
997-
) : null}
998-
{proAvailable ? (
999-
<DebugButton onClick={() => setPage(DEBUG_MENU_PAGE.Pro)}>Pro Playground</DebugButton>
1000-
) : null}
1001-
{proAvailable ? (
1002-
<DebugButton
1003-
onClick={() => {
1004-
if (!proAvailable) {
1005-
return;
1006-
}
1007-
dispatch(proBackendDataActions.refreshGetProDetailsFromProBackend({}) as any);
1008-
}}
1009-
>
1010-
Refresh Pro Details
1011-
</DebugButton>
899+
<>
900+
<DebugButton buttonColor={SessionButtonColor.Danger} onClick={resetPro}>
901+
Reset All Pro State
902+
</DebugButton>
903+
<DebugButton onClick={() => setPage(DEBUG_MENU_PAGE.Pro)}>Pro Playground</DebugButton>
904+
<DebugButton
905+
onClick={() => {
906+
if (!proAvailable) {
907+
return;
908+
}
909+
dispatch(proBackendDataActions.refreshGetProDetailsFromProBackend({}) as any);
910+
}}
911+
>
912+
Refresh Pro Details
913+
</DebugButton>
914+
<DebugButton
915+
onClick={async () => {
916+
const masterPrivKeyHex = await getProMasterKeyHex();
917+
const rotatingPrivKeyHex = await UserUtils.getProRotatingPrivateKeyHex();
918+
const rotatingSeedHex = await UserUtils.getProRotatingSeedHex();
919+
const response = await ProBackendAPI.generateProProof({
920+
masterPrivKeyHex,
921+
rotatingPrivKeyHex,
922+
});
923+
if (getFeatureFlag('debugServerRequests')) {
924+
window?.log?.debug('getProProof response: ', response);
925+
}
926+
if (response?.status_code === 200) {
927+
const proProof: ProProof = {
928+
expiryMs: response.result.expiry_unix_ts_ms,
929+
genIndexHashB64: response.result.gen_index_hash_b64,
930+
rotatingPubkeyHex: response.result.rotating_pkey_hex,
931+
version: response.result.version,
932+
signatureHex: response.result.sig_hex,
933+
};
934+
await UserConfigWrapperActions.setProConfig({ proProof, rotatingSeedHex });
935+
}
936+
}}
937+
>
938+
Get Pro Proof
939+
</DebugButton>
940+
<DebugButton
941+
onClick={async () => {
942+
const masterPrivKeyHex = await getProMasterKeyHex();
943+
const response = await ProBackendAPI.getProDetails({ masterPrivKeyHex });
944+
if (getFeatureFlag('debugServerRequests')) {
945+
window?.log?.debug('Pro Details: ', response);
946+
}
947+
}}
948+
>
949+
Get Pro Details
950+
</DebugButton>
951+
<DebugButton
952+
hide={!proAvailable}
953+
onClick={async () => {
954+
const response = await ProBackendAPI.getRevocationList({ ticket: 0 });
955+
window?.log?.debug('Pro Revocation List: ', response);
956+
}}
957+
>
958+
Get Pro Revocation List (from ticket 0)
959+
</DebugButton>
960+
</>
1012961
) : null}
962+
1013963
<FlagToggle
1014964
forceUpdate={forceUpdate}
1015965
flag="useTestProBackend"
@@ -1049,6 +999,7 @@ export const ProDebugSection = ({
1049999
options={[
10501000
{ label: 'Google Play', value: ProPaymentProvider.GooglePlayStore },
10511001
{ label: 'iOS App Store', value: ProPaymentProvider.iOSAppStore },
1002+
{ label: 'Rangeproof', value: ProPaymentProvider.Rangeproof },
10521003
]}
10531004
forceUpdate={forceUpdate}
10541005
unsetOption={{ label: 'Select originating platform', value: null }}

0 commit comments

Comments
 (0)