Skip to content

Commit

Permalink
cleanup; remove keyShareService from this PR
Browse files Browse the repository at this point in the history
remove unnecessary div
more cleanup (try to reduce diff size)
undo some of above cleanup attempts (no benefit of diff size)
  • Loading branch information
sidvishnoi committed Sep 23, 2024
1 parent ec8ef27 commit ae77a5b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 78 deletions.
1 change: 0 additions & 1 deletion src/background/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { OpenPaymentsService } from './openPayments';
export { KeyShareService } from './keyShare';
export { StorageService } from './storage';
export { MonetizationService } from './monetization';
export { Background } from './background';
Expand Down
19 changes: 0 additions & 19 deletions src/background/services/keyShare.ts

This file was deleted.

15 changes: 3 additions & 12 deletions src/background/services/openPayments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { getExchangeRates, getRateOfPay, toAmount } from '../utils';
import { exportJWK, generateEd25519KeyPair } from '@/shared/crypto';
import { bytesToHex } from '@noble/hashes/utils';
import { getWalletInformation } from '@/shared/helpers';
import { KeyShareService } from './keyShare';
import { AddFundsPayload, ConnectWalletPayload } from '@/shared/messages';
import {
DEFAULT_RATE_OF_PAY,
Expand Down Expand Up @@ -505,17 +504,9 @@ export class OpenPaymentsService {
return grantDetails;
}

private async addPublicKeyToWallet(walletAddress: WalletAddress) {
const keyShare = new KeyShareService({
browser: this.browser,
storage: this.storage,
});
try {
await keyShare.addPublicKeyToWallet(walletAddress);
} catch (err) {
// TODO: add error with code to be used for logic in UI
throw new Error(`ADD_PUBLIC_KEY_TO_WALLET:${err.message}`);
}
private async addPublicKeyToWallet(_walletAddress: WalletAddress) {
const msg = `Automatic key addition is not not implemented for give wallet provider yet`;
throw new Error(`ADD_PUBLIC_KEY_TO_WALLET:${msg}`);
}

private async redirectToWelcomeScreen(
Expand Down
88 changes: 42 additions & 46 deletions src/popup/components/ConnectWalletForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,17 @@ export const ConnectWalletForm = ({

const getWalletCurrency = React.useCallback(
async (walletAddressUrl: string): Promise<void> => {
setErrors((e) => ({ ...e, walletAddressUrl: '' }));
setErrors((_) => ({ ..._, walletAddressUrl: '' }));
if (!walletAddressUrl) return;
try {
setIsValidating((e) => ({ ...e, walletAddressUrl: true }));
setIsValidating((_) => ({ ..._, walletAddressUrl: true }));
const url = new URL(toWalletAddressUrl(walletAddressUrl));
const walletAddress = await getWalletInfo(url.toString());
setWalletAddressInfo(walletAddress);
} catch (error) {
setErrors((e) => ({
...e,
walletAddressUrl: error.message,
}));
setErrors((_) => ({ ..._, walletAddressUrl: error.message }));
} finally {
setIsValidating((e) => ({ ...e, walletAddressUrl: false }));
setIsValidating((_) => ({ ..._, walletAddressUrl: false }));
}
},
[getWalletInfo],
Expand All @@ -97,10 +94,10 @@ export const ConnectWalletForm = ({
amount: validateAmount(amount, currencySymbol.symbol),
};
if (!walletAddressInfo) {
setErrors((e) => ({ ...e, walletAddressUrl: 'Not fetched yet?!' }));
setErrors((_) => ({ ..._, walletAddressUrl: 'Not fetched yet?!' }));
return;
}
setErrors((e) => ({ ...e, ...err }));
setErrors((_) => ({ ..._, ...err }));
if (err.amount || err.walletAddressUrl) {
return;
}
Expand All @@ -112,7 +109,7 @@ export const ConnectWalletForm = ({
skipAutoKeyShare = true;
setAutoKeyShareFailed(true);
}
setErrors((e) => ({ ...e, keyPair: '', connect: '' }));
setErrors((_) => ({ ..._, keyPair: '', connect: '' }));
const res = await connectWallet({
walletAddressUrl: toWalletAddressUrl(walletAddressUrl),
amount,
Expand All @@ -124,17 +121,18 @@ export const ConnectWalletForm = ({
} else {
if (res.message.startsWith('ADD_PUBLIC_KEY_TO_WALLET:')) {
const message = res.message.replace('ADD_PUBLIC_KEY_TO_WALLET:', '');
setErrors((e) => ({ ...e, keyPair: message }));
setErrors((_) => ({ ..._, keyPair: message }));
} else {
throw new Error(res.message);
}
}
} catch (error) {
setErrors((e) => ({ ...e, connect: error.message }));
setErrors((_) => ({ ..._, connect: error.message }));
} finally {
setIsSubmitting(false);
}
};

React.useEffect(() => {
if (!walletAddressInfo) return;
setCurrencySymbol({
Expand Down Expand Up @@ -167,41 +165,39 @@ export const ConnectWalletForm = ({

{errors.connect && <ErrorMessage error={errors.connect} />}

<div className="space-y-2">
<Input
type="text"
label="Wallet address or payment pointer"
id="connectWalletAddressUrl"
placeholder="https://ilp.rafiki.money/johndoe"
errorMessage={errors.walletAddressUrl}
defaultValue={walletAddressUrl}
addOn={
isValidating.walletAddressUrl ? (
<LoadingSpinner color="gray" size="md" />
) : null
}
addOnPosition="right"
required={true}
autoComplete="on"
onBlur={async (ev) => {
const value = ev.currentTarget.value;
if (value === walletAddressUrl) {
if (value || !ev.currentTarget.required) {
return;
}
<Input
type="text"
label="Wallet address or payment pointer"
id="connectWalletAddressUrl"
placeholder="https://ilp.rafiki.money/johndoe"
errorMessage={errors.walletAddressUrl}
defaultValue={walletAddressUrl}
addOn={
isValidating.walletAddressUrl ? (
<LoadingSpinner color="gray" size="md" />
) : null
}
addOnPosition="right"
required={true}
autoComplete="on"
onBlur={async (ev) => {
const value = ev.currentTarget.value;
if (value === walletAddressUrl) {
if (value || !ev.currentTarget.required) {
return;
}
setWalletAddressInfo(null);
setWalletAddressUrl(value);
}
setWalletAddressInfo(null);
setWalletAddressUrl(value);

const error = validateWalletAddressUrl(value);
setErrors((e) => ({ ...e, walletAddressUrl: error }));
if (!error) {
await getWalletCurrency(value);
}
saveValue('walletAddressUrl', value);
}}
/>
</div>
const error = validateWalletAddressUrl(value);
setErrors((_) => ({ ..._, walletAddressUrl: error }));
if (!error) {
await getWalletCurrency(value);
}
saveValue('walletAddressUrl', value);
}}
/>

<fieldset
className={cn(
Expand Down Expand Up @@ -239,7 +235,7 @@ export const ConnectWalletForm = ({
}

const error = validateAmount(value, currencySymbol.symbol);
setErrors((e) => ({ ...e, amount: error }));
setErrors((_) => ({ ..._, amount: error }));

const amountValue = formatNumber(+value, currencySymbol.scale);
if (!error) {
Expand Down

0 comments on commit ae77a5b

Please sign in to comment.