Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ErrorKeyRevoked): reconnect with automatic key addition #714

Merged
merged 19 commits into from
Dec 9, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/background/services/openPayments.ts
Original file line number Diff line number Diff line change
@@ -112,13 +112,15 @@ const enum ErrorCode {
KEY_ADD_FAILED = 'key_add_failed',
}

const enum GrantResult {
SUCCESS = 'grant_success',
ERROR = 'grant_error',
const enum Result {
DarianM marked this conversation as resolved.
Show resolved Hide resolved
GRANT_SUCCESS = 'grant_success',
GRANT_ERROR = 'grant_error',
KEY_ADDED = 'key_added',
}

const enum InteractionIntent {
DarianM marked this conversation as resolved.
Show resolved Hide resolved
CONNECT = 'connect',
RECONNECT = 'reconnect',
FUNDS = 'funds',
BUDGET_UPDATE = 'budget_update',
}
@@ -544,7 +546,7 @@ export class OpenPaymentsService {
}).catch(async (e) => {
await this.redirectToWelcomeScreen(
tabId,
GrantResult.ERROR,
Result.GRANT_ERROR,
intent,
ErrorCode.HASH_FAILED,
);
@@ -562,7 +564,7 @@ export class OpenPaymentsService {
).catch(async (e) => {
await this.redirectToWelcomeScreen(
tabId,
GrantResult.ERROR,
Result.GRANT_ERROR,
intent,
ErrorCode.CONTINUATION_FAILED,
);
@@ -603,7 +605,7 @@ export class OpenPaymentsService {
}

this.grant = grantDetails;
await this.redirectToWelcomeScreen(tabId, GrantResult.SUCCESS, intent);
await this.redirectToWelcomeScreen(tabId, Result.GRANT_SUCCESS, intent);
return grantDetails;
}

@@ -631,7 +633,7 @@ export class OpenPaymentsService {
if (tabId && !isTabClosed) {
await this.redirectToWelcomeScreen(
tabId,
GrantResult.ERROR,
Result.GRANT_ERROR,
InteractionIntent.CONNECT,
ErrorCode.KEY_ADD_FAILED,
);
@@ -663,7 +665,7 @@ export class OpenPaymentsService {

private async redirectToWelcomeScreen(
tabId: NonNullable<Tabs.Tab['id']>,
result: GrantResult,
result: Result,
intent: InteractionIntent,
errorCode?: ErrorCode,
) {
@@ -906,7 +908,16 @@ export class OpenPaymentsService {

async reconnectWallet() {
try {
const { walletAddress } = await this.storage.get(['walletAddress']);
const tabId = await this.addPublicKeyToWallet(walletAddress!);
DarianM marked this conversation as resolved.
Show resolved Hide resolved
this.setConnectState('connecting');
await this.rotateToken();
await this.redirectToWelcomeScreen(
tabId!,
DarianM marked this conversation as resolved.
Show resolved Hide resolved
Result.KEY_ADDED,
InteractionIntent.RECONNECT,
);
this.setConnectState(null);
} catch (error) {
if (isInvalidClientError(error)) {
const msg = this.t('connectWallet_error_invalidClient');
9 changes: 4 additions & 5 deletions src/popup/components/ErrorKeyRevoked.tsx
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ import React from 'react';
import { AnimatePresence, m } from 'framer-motion';
import { WarningSign } from '@/popup/components/Icons';
import { Button } from '@/popup/components/ui/Button';
import { Code } from '@/popup/components/ui/Code';
import { useTranslation } from '@/popup/lib/context';
import { useLocalStorage } from '@/popup/lib/hooks';
import type { PopupStore } from '@/shared/types';
@@ -50,6 +49,7 @@ export const ErrorKeyRevoked = ({
onReconnect={() => {
clearScreen();
onReconnect?.();
window.close();
DarianM marked this conversation as resolved.
Show resolved Hide resolved
}}
/>
</AnimatePresence>
@@ -164,16 +164,15 @@ const ReconnectScreen = ({
requestReconnect();
}}
>
<div className="space-y-1 text-sm">
<div className="space-y-2 text-sm">
<p className="px-2">
Reconnecting to wallet:{' '}
<span className="underline">{info.walletAddress?.id}</span>
</p>
<p className="px-2">
<strong>Before</strong> you reconnect, copy the public key below and
add it to your wallet.
<strong>Reconnect</strong> to automatically add the key to your
wallet.
DarianM marked this conversation as resolved.
Show resolved Hide resolved
</p>
<Code className="text-xs" value={info.publicKey} />
</div>

{errors?.root?.message && (