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

develop -> main #956

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const nextConfig = {
'/near/widget/NearOrg.HomePage?utm_source=stack&utm_medium=podcast&utm_campaign=stackoverflow_evergreen_bos_awareness',
permanent: false,
},
{
source: '/stakewars',
destination:
'https://github.com/near/stakewars-iv',
permanent: false,
},
{
source: '/nearcon23.near/widget/Index',
destination: 'https://nearcon.app',
Expand Down
5 changes: 4 additions & 1 deletion src/components/sandbox/Sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
} from './utils/onboarding';
import Welcome from './Welcome';
import MainLoader from './Welcome/MainLoader';
import { recordHandledError } from '@/utils/analytics';

export const Sandbox = ({ onboarding = false }) => {
const near = useVmStore((store) => store.near);
Expand Down Expand Up @@ -319,7 +320,8 @@ export const Sandbox = ({ onboarding = false }) => {
});
changeCode(path, formattedCode);
} catch (e) {
console.log(e);
console.error(e);
recordHandledError({ scope: 'sandbox reformatting', message: e.message || e });
}
};

Expand Down Expand Up @@ -492,6 +494,7 @@ export const Sandbox = ({ onboarding = false }) => {
} catch (e) {
setParsedWidgetProps({});
setPropsError(e.message);
recordHandledError({ scope: 'setting component props within the sandbox editor', message: e.message || e });
}
}, [widgetProps]);

Expand Down
2 changes: 2 additions & 0 deletions src/components/sandbox/TabProps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Editor from '@monaco-editor/react';
import React, { useCallback } from 'react';

import { Tab } from '../utils/const';
import { recordHandledError } from '@/utils/analytics';

const TabProps = ({ tab, widgetProps, setWidgetProps, propsError }) => {
const reformatProps = useCallback(
Expand All @@ -11,6 +12,7 @@ const TabProps = ({ tab, widgetProps, setWidgetProps, propsError }) => {
setWidgetProps(formattedProps);
} catch (e) {
console.log(e);
recordHandledError({ scope: 'sandbox reformatProps', message: e.message || e });
}
},
[setWidgetProps],
Expand Down
3 changes: 2 additions & 1 deletion src/components/vm/VmInitializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { useSignInRedirect } from '@/hooks/useSignInRedirect';
import { useAuthStore } from '@/stores/auth';
import { useIdosStore } from '@/stores/idosStore';
import { useVmStore } from '@/stores/vm';
import { recordWalletConnect, reset as resetAnalytics } from '@/utils/analytics';
import { recordHandledError, recordWalletConnect, reset as resetAnalytics } from '@/utils/analytics';
import {
commitModalBypassAuthorIds,
commitModalBypassSources,
Expand Down Expand Up @@ -173,6 +173,7 @@ export default function VmInitializer() {
} catch (err) {
const errMsg = err instanceof Error ? err.message : 'Something went wrong';
alert(errMsg);
recordHandledError({ scope: 'requestSignMessage', message: errMsg });
}
},
[near],
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useBosLoaderInitializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useCallback, useEffect } from 'react';
import { useBosLoaderStore } from '@/stores/bos-loader';

import { useFlags } from './useFlags';
import { recordHandledError } from '@/utils/analytics';

export function useBosLoaderInitializer() {
const [flags] = useFlags();
Expand Down Expand Up @@ -37,9 +38,9 @@ export function useBosLoaderInitializer() {
hasResolved: true,
redirectMap: data.components,
});
} catch (e) {
} catch (e: any) {
console.error(e);

recordHandledError({ scope: 'requestSignMessage', message: e.message || e });
setStore({
failedToLoad: true,
hasResolved: true,
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/useIdOS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { idOS } from '@idos-network/idos-sdk';
import { useCallback, useEffect } from 'react';

import { useIdosStore } from '@/stores/idosStore';
import { recordHandledError } from '@/utils/analytics';

export function useIdOS() {
const setIdosStore = useIdosStore((state) => state.set);
Expand All @@ -15,7 +16,9 @@ export function useIdOS() {
})) as any;
setIdosStore({ idOS: idos });
} catch (error: any) {
console.error('Failed to initialize IDOS: ', error);
const scope = 'Failed to initialize IDOS:';
console.error(scope, error);
recordHandledError({ scope, message: error.message || error });
}
}, [setIdosStore]);

Expand Down
1 change: 0 additions & 1 deletion src/pages/[...arbitrary].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const finiteRoutes: Record<string, string> = {
sailgpsf: 'https://pages.near.org/sailgpsf',
sf: 'https://pages.near.org/sf',
spill: 'https://pages.near.org/spill',
stakewars: 'https://pages.near.org/stakewars',
'use-cases': 'https://pages.near.org/use-cases',
'v3-developers': 'https://pages.near.org/v3-developers',
'v3-use': 'https://pages.near.org/v3-use',
Expand Down
5 changes: 4 additions & 1 deletion src/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useDefaultLayout } from '@/hooks/useLayout';
import { useAuthStore } from '@/stores/auth';
import { useIdosStore } from '@/stores/idosStore';
import type { NextPageWithLayout } from '@/utils/types';
import { recordHandledError } from '@/utils/analytics';

const SettingsPage: NextPageWithLayout = () => {
const components = useBosComponents();
Expand Down Expand Up @@ -49,8 +50,10 @@ const SettingsPage: NextPageWithLayout = () => {
});
}
} catch (error: any) {
console.error('Failed to init wallet + idOS: ', error);
const scope = 'Failed to init wallet + idOS: ';
console.error(scope, error);
const errorMessage = error.message ? error.message : 'unknown';
recordHandledError({ scope, message: errorMessage || error });
setError({
type: 'ERROR',
title: 'Falilure during idOS initialization:',
Expand Down
7 changes: 6 additions & 1 deletion src/pages/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { network } from '@/utils/config';
import type { NextPageWithLayout } from '@/utils/types';

import { accountAddressPatternNoSubaccount, emailPattern, getEmailId, isValidEmail } from '../utils/form-validation';
import { recordHandledError } from '@/utils/analytics';

const ErrorText = styled.p`
color: hsla(8, 100%, 33%, 1);
Expand Down Expand Up @@ -76,8 +77,12 @@ const SignUpPage: NextPageWithLayout = () => {
if (data?.result?.code_hash) {
return setIsAccountAvailable(false);
}
} catch (error) {
} catch (error: any) {
console.log(error);
recordHandledError({
scope: 'sign-up: account availability check',
message: error.message || error,
});
setIsAccountAvailable(false);
}
}, []);
Expand Down
4 changes: 4 additions & 0 deletions src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ export function recordEventWithProps(eventLabel: string, properties: Record<stri
}
}

export function recordHandledError(props: Record<string, string>) {
recordEventWithProps('error-handled', props);
}

export function recordEvent(eventLabel: string) {
if (!rudderAnalytics) return;
try {
Expand Down
30 changes: 21 additions & 9 deletions src/utils/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@ import {
setProcessSuccess,
} from './notificationsLocalStorage';
import type { NotificationSubscriptionData } from './types';
import { recordHandledError } from './analytics';

// min version for iOS to support notifications
export const recommendedIosVersionForNotifications = 16.4;

const handleRequestPermission = () => {
try {
return Notification.requestPermission();
} catch (error) {
console.error('Error while requesting permission.', error);
} catch (error: any) {
const scope = 'Error while requesting Notification permission.';
console.error(scope, error);
recordHandledError({ scope, message: error.message || error });
}
};

const registerServiceWorker = () => {
try {
return navigator.serviceWorker.register('/service-worker.js');
} catch (error) {
console.error('Error while registering service-worker.', error);
} catch (e: any) {
const scope = 'Error while registering the push notification service-worker';
console.error(scope, e);
recordHandledError({ scope, message: e.message || e });
}
};

Expand All @@ -50,8 +55,9 @@ const handlePushManagerSubscribe = async () => {
userVisibleOnly: true,
applicationServerKey: notificationApplicationServerKey,
});
} catch (e) {
console.error('Error while subscribing to service-worker.', e);
} catch (e: any) {
const scope = 'Error while subscribing to the push notification service-worker.';
recordHandledError({ scope, message: e.message || e });
throw e;
}
};
Expand All @@ -65,8 +71,10 @@ export const handlePushManagerUnsubscribe = async (hide: () => void) => {
await pushServerUnsubscribe(subscription);
await unregisterServiceWorker();
await subscription?.unsubscribe();
} catch (error) {
// TODO: handle
} catch (e: any) {
const scope = 'Error while handling push notification unsubscribe';
console.error(scope, e);
recordHandledError({ scope, message: e.message || e });
} finally {
hide();
}
Expand Down Expand Up @@ -129,8 +137,12 @@ export const handleTurnOn = async (accountId: string, hideModal: () => void) =>
});

setProcessSuccess();
} catch (error: unknown) {
} catch (error: any) {
setProcessError(error);
recordHandledError({
scope: 'Error in the attempt to turn on Push Notifications',
message: error.message || error,
});
} finally {
hideModal();
setProcessEnded();
Expand Down
Loading