Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/main/gh_actions-bc…
Browse files Browse the repository at this point in the history
…598c68e3
  • Loading branch information
jakubmkowalski authored Aug 28, 2024
2 parents 5231522 + a59b80a commit 02fa576
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 68 deletions.
4 changes: 2 additions & 2 deletions release/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# build stage
FROM --platform=$TARGETPLATFORM node:18-alpine as build
FROM --platform=$TARGETPLATFORM node:22-alpine as build

WORKDIR /app

Expand All @@ -24,7 +24,7 @@ RUN yarn run build

# App final stage
# serving the production build
FROM --platform=$TARGETPLATFORM nginx:1.25.1-alpine
FROM --platform=$TARGETPLATFORM nginx:1.27.0-alpine

# We need some custom nginx configuration, which we import here
COPY release/nginx.default.conf /etc/nginx/conf.d/default.conf
Expand Down
11 changes: 2 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ErrorBar } from '@/components/ErrorBar';
import { ToastContainer } from 'react-toastify';

import 'react-toastify/dist/ReactToastify.css';
import { errorMessage } from './utils/errorMessage';

const ROUTES = [
{
Expand Down Expand Up @@ -87,22 +88,14 @@ export const App = () => {
}
})
.catch((error) => {
let errorMsg;
if (error.response.status === 401 || error.response.status === 400) {
setAuthorization(null);
navigate('/');
setLoading(false);
return;
}

if (error.response.status === 404) {
errorMsg =
error.response.data + ". If you can't log in again, please contact our support or try again later!";
} else {
errorMsg = error.response.data ? error.response.data : 'Something went wrong... Please, try again later!';
}

setError(errorMsg);
setError(errorMessage(error.response.data));
setLoading(false);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
12 changes: 2 additions & 10 deletions src/components/AccountSummary/AccountSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getUser } from '@/api';
import { Loader } from '@/components/Loader';
import { ErrorBar } from '@/components/ErrorBar';
import { convertSatToBsv } from '@/utils/helpers/convertSatToBsv';
import { errorMessage } from '@/utils/errorMessage';

interface CurrencyRates {
usd?: number;
Expand Down Expand Up @@ -40,16 +41,7 @@ export const AccountSummary = () => {
setDetails(accountDetails);
})
.catch((error) => {
let errorMsg;

if (error.response.status === 404) {
errorMsg =
"User's account details not found. If you can't log in again, please contact our support or try again later!";
} else {
errorMsg = error.response.data ? error.response.data : 'Something went wrong... Please, try again later!';
}

setErrors(errorMsg);
setErrors(errorMessage(error.response.data));
})
.finally(() => {
setLoading(false);
Expand Down
20 changes: 13 additions & 7 deletions src/components/ContactsList/AcceptReject/AcceptReject.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { acceptContact, rejectContact } from '@/api/requests';
import { SmallButton } from '@/components/Button';
import { ConfirmationModal } from '@/components/Modal';
import { errorMessage } from '@/utils/errorMessage';
import { FC, useState } from 'react';

type AcceptRejectProps = {
Expand All @@ -12,7 +13,7 @@ type AcceptRejectProps = {
export const AcceptReject: FC<AcceptRejectProps> = ({ paymail, onAccept, onReject }) => {
const [state, setState] = useState<'none' | 'accept' | 'reject'>('none');
const [loading, setLoading] = useState(false);
const [error, setError] = useState(false);
const [error, setError] = useState('');

const submitAccept = async () => {
await acceptContact(paymail);
Expand All @@ -26,18 +27,23 @@ export const AcceptReject: FC<AcceptRejectProps> = ({ paymail, onAccept, onRejec

const onConfirm = async () => {
const submit = state === 'accept' ? submitAccept : submitReject;
setError(false);
setError('');
setLoading(true);
try {
await submit();
} catch {
setError(true);
setState('none');
} catch (error: unknown) {
setError(errorMessage(error));
} finally {
setLoading(false);
setState('none');
}
};

const onCancel = () => {
setState('none');
setError('');
};

return (
<>
<SmallButton variant="accept" onClick={() => setState('accept')}>
Expand All @@ -51,9 +57,9 @@ export const AcceptReject: FC<AcceptRejectProps> = ({ paymail, onAccept, onRejec
subtitle={`Are you sure you want to ${state === 'accept' ? 'accept' : 'reject'} this contact invitation?`}
open={state !== 'none'}
loading={loading}
error={error ? 'Error during performing the action' : undefined}
error={error || undefined}
onConfirm={onConfirm}
onCancel={() => setState('none')}
onCancel={onCancel}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const ContactsTable: FC = () => {
const sortedContacts = useSortedContacts(contacts);

if (error) {
return <ErrorBar errorMsg="Failed to load contacts" />;
return <ErrorBar errorMsg={error} />;
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const ContactAddModal: FC<ContactAddModalProps> = ({ onSubmitted, onCance
onCancel={onCancel}
onSubmitted={onSubmitted}
successMsg="Contact added successfully!"
errorMsg="Error occurred while adding a contact."
modalTitle="Add contact"
modalSubtitle="Please double check the paymail address on which the invitation will be sent"
fields={fields}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const ContactEditModal: FC<ContactEditModalProps> = ({ onSubmitted, onCan
onCancel={onCancel}
onSubmitted={onSubmitted}
successMsg="Contact edited successfully!"
errorMsg="Error occurred while editing a contact."
modalTitle="Edit contact"
modalSubtitle=""
fields={fields}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { ErrorBar } from '@/components/ErrorBar';
import { isValidPhone } from '@/utils/helpers/validatePhone';
import { ContactFields } from './useContactFields';
import { EMAIL_REGEX } from '@/utils/constants';
import { errorMessage } from '@/utils/errorMessage';

type ContactUpsertModal = {
onSubmitted: () => void;
onCancel: () => void;
successMsg: string;
errorMsg: string;
modalTitle: string;
modalSubtitle: string;
fields: ContactFields;
Expand All @@ -26,7 +26,6 @@ export const ContactUpsertModal: FC<ContactUpsertModal> = ({
onSubmitted,
onCancel,
fields,
errorMsg,
successMsg,
modalTitle,
modalSubtitle,
Expand Down Expand Up @@ -62,8 +61,7 @@ export const ContactUpsertModal: FC<ContactUpsertModal> = ({
await upsertContact(paymail, name, phone ? { phoneNumber: phone } : undefined);
onSuccess();
} catch (error) {
console.error('error', error);
setError(errorMsg);
setError(errorMessage(error));
} finally {
setLoading(false);
}
Expand Down
11 changes: 6 additions & 5 deletions src/components/ContactsList/_modals/VerifyModal/PeerTOTP.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { Contact, confirmContactWithTOTP } from '@/api';
import { ErrorBar } from '@/components/ErrorBar';
import { Input } from '@/components/Input';
import { errorMessage } from '@/utils/errorMessage';
import { FC, useMemo, useState } from 'react';

const TOTP_VALID_REGEX = /^\d{2}$/;

export const usePeerTOTP = (peer: Contact, onConfirmed: () => void) => {
const [value, setValue] = useState('');
const [loading, setLoading] = useState(false);
const [error, setError] = useState(false);
const [error, setError] = useState('');

const valid = useMemo(() => {
return TOTP_VALID_REGEX.test(value);
}, [value]);

const onConfirm = async () => {
setLoading(true);
setError(false);
setError('');
try {
await confirmContactWithTOTP(peer, value);
} catch {
setError(true);
} catch (error: unknown) {
setError(errorMessage(error));
} finally {
setLoading(false);
onConfirmed();
Expand All @@ -38,7 +39,7 @@ export const PeerTOTP: FC<PeerTOTPProps> = ({ value, setValue, valid, peerName,
return (
<div>
<hr />
{error && <ErrorBar errorMsg="An error occurred" />}
{error && <ErrorBar errorMsg={error} />}
<Input
inputOnLightBackground
labelText={`Enter code from: ${peerName}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const ConfirmationModal: FC<ConfirmationModalProps> = ({
secondaryButton={{ text: 'Yes', variant: 'accept', onClick: onConfirm, loading: loading, disabled: loading }}
onCloseByEsc={onCancel}
>
{error && <ErrorBar errorMsg={error} withReloadButton />}
{error && <ErrorBar errorMsg={error} />}
</Modal>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useAutoupdate } from '@/providers/autoupdate';
import { convertSatToBsv } from '@/utils/helpers/convertSatToBsv';
import { PasswordInput } from '@/components/Input/PasswordInput';
import { modalCloseTimeout } from '../../modalCloseTimeout';
import { errorMessage } from '@/utils/errorMessage';

export interface TransactionData {
paymail: string;
Expand Down Expand Up @@ -82,17 +83,11 @@ export const TransactionConfirmModal: FC<TransactionConfirmModalProps> = ({
return;
}

if (error.response.status === 400) {
setErrors(
'Transfer was not sent. Probably you filled the form with incorrect data. Please try once again!',
);
return;
}

setErrors(
error.response.data
? error.response.data
: 'Transfer was not sent. Please verify transfer data and try once again. If problem will happen again, contact with our support.',
errorMessage(
error.response.data,
'Transfer was not sent. Please verify transfer data and try once again. If problem will happen again, contact with our support.',
),
);
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Loader } from '@/components/Loader';
import { ErrorBar } from '@/components/ErrorBar';
import { convertSatToBsv } from '@/utils/helpers/convertSatToBsv';
import { SetPaymailButton } from '@/components/TransferForm/SetPaymailButton';
import { errorMessage } from '@/utils/errorMessage';

type TransactionDetailsProps = {
open: boolean;
Expand All @@ -33,8 +34,7 @@ export const TransactionDetailsModal: FC<TransactionDetailsProps> = ({ open, onC
setTransactionData(response);
})
.catch((error) => {
const errorMsg = error.response.data ? error.response.data : 'Something went wrong... Please try again later';
errorMsg && setErrors(errorMsg);
setErrors(errorMessage(error.response.data));
})
.finally(() => {
setLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { useAutoupdate } from '@/providers/autoupdate';
import _ from 'lodash';
import { convertSatToBsv } from '@/utils/helpers/convertSatToBsv';
import { PaginationParams } from '@/api/types/pagination';
import { errorMessage } from '@/utils/errorMessage';

const KEY_NAME_ENTER = 'Enter';
const KEY_NAME_SPACE = 'Space';
Expand Down Expand Up @@ -91,8 +92,7 @@ export const TransactionTable = () => {
setTransactionsList(transactions.transactions);
})
.catch((error) => {
const errorMsg = error.response.data ? error.response.data : 'Something went wrong... Please try again later';
setErrors(errorMsg);
setErrors(errorMessage(error.response.data));
})
.finally(() => {
setLoading(false);
Expand Down
4 changes: 2 additions & 2 deletions src/components/UserMenu/UserMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useNavigate } from 'react-router-dom';
import { useAuthorization } from '@/providers';
import { logoutUser } from '@/api/requests';
import { BsvLogo } from '@/components/BsvLogo';
import { errorMessage } from '@/utils/errorMessage';

interface MenuProps {
userEmail?: string;
Expand Down Expand Up @@ -54,8 +55,7 @@ export const UserMenu: FC<MenuProps> = ({ userEmail }) => {
Navigate('/');
})
.catch((error) => {
const errorMsg = error.response.data ? error.response.data : 'Something went wrong... Please try again!';
errorMsg && setErrors(errorMsg);
setErrors(errorMessage(error.response.data));
})
.finally(() => {
setLoading(false);
Expand Down
15 changes: 8 additions & 7 deletions src/providers/contacts/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ import { PaginationParams } from '@/api/types';
import { usePikeContactsEnabled } from '@/hooks/useFeatureFlags';
import { FC, PropsWithChildren, createContext, useCallback, useEffect, useMemo, useState } from 'react';
import { useAuthorization } from '../authorization';
import { errorMessage } from '@/utils/errorMessage';

type ContactsContextValue = {
contacts: Contact[] | null;
refresh: () => void;
loading: boolean;
error: boolean;
error: string;
};

export const ContactsContext = createContext<ContactsContextValue>(null as never);

export const ContactsProvider: FC<PropsWithChildren> = ({ children }) => {
const [loading, setLoading] = useState(false);
const [error, setError] = useState(false);
const [error, setError] = useState('');
const [contacts, setContacts] = useState<Contact[] | null>(null);
const pikeContactsEnabled = usePikeContactsEnabled()
const pikeContactsEnabled = usePikeContactsEnabled();
const { authorization } = useAuthorization();

const load = useCallback(async () => {
Expand All @@ -27,17 +28,17 @@ export const ContactsProvider: FC<PropsWithChildren> = ({ children }) => {
}
setLoading(true);
try {
const paginationParams : PaginationParams = {
const paginationParams: PaginationParams = {
page: 1,
page_size: 1000,
order: 'paymail',
sort: 'asc',
}
};
const contactsResponse = await searchContacts(paginationParams);
setContacts(contactsResponse.content);
} catch {
} catch (e: unknown) {
setContacts(null);
setError(true);
setError(errorMessage(e));
} finally {
setLoading(false);
}
Expand Down
19 changes: 19 additions & 0 deletions src/utils/errorMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { AxiosError } from 'axios';

type SPVError = {
message: string;
code: string;
};

const isSPVError = (error: unknown): error is SPVError => {
return (error as SPVError).code !== undefined && (error as SPVError).message !== undefined;
};

const DEFAULT_ERROR_MESSAGE = 'Something went wrong... Please, try again later!';

export const errorMessage = (error: SPVError | AxiosError | unknown, fallbackMessage = DEFAULT_ERROR_MESSAGE) => {
if (error instanceof AxiosError) {
error = error.response?.data ?? error.message;
}
return isSPVError(error) ? error.message : fallbackMessage;
};
Loading

0 comments on commit 02fa576

Please sign in to comment.