Skip to content
Open
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
26 changes: 1 addition & 25 deletions app/onboard/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,11 @@ import * as Crypto from 'expo-crypto';
import { store } from 'helper/redux/store';
import { HDKey } from '@scure/bip32';
import { relays } from 'components/ndk';
import { runWithAnimationFrame } from 'helper';

// eslint-disable-next-line @typescript-eslint/no-require-imports
global.Buffer = require('buffer').Buffer;

/**
* Executes an async function within a requestAnimationFrame to improve UI responsiveness
*/
export const runWithAnimationFrame = <T extends any[]>(
callback: Function,
setIsSubmitting?: React.Dispatch<React.SetStateAction<boolean>>
) => {
return async (...args: T) => {
if (setIsSubmitting) {
setIsSubmitting(true);
}

requestAnimationFrame(async () => {
try {
await callback(...args);
} catch {
} finally {
if (setIsSubmitting) {
setIsSubmitting(false);
}
}
});
};
};

export function generateMnemonic(): string {
const mnemonic = store.getState()?.nostr?.profiles?.[0]?.mnemonic;
if (mnemonic) return mnemonic;
Expand Down
2 changes: 1 addition & 1 deletion app/settings/restoreCounter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { Text } from 'components/common/Text';
import Container from 'components/layout/Container';
import { restoreCounter } from 'helper/cashuClient';
import { increaseCounterV2 } from 'helper/redux/cashu';
import { runWithAnimationFrame } from '../onboard/new';
import { ScrollView } from 'react-native';
import { RootState } from 'helper/redux/store/reducer';
import { MintKeyset } from '@cashu/cashu-ts';
import { runWithAnimationFrame } from 'helper';

export default function ModalScreen() {
const [isLoading, setIsLoading] = useState(false);
Expand Down
2 changes: 1 addition & 1 deletion components/common/ButtonHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useSelector } from 'react-redux';
import { memoizedGetTheme } from 'helper/redux/settings';
import { LinearGradient } from 'expo-linear-gradient';
import opacity from 'hex-color-opacity';
import { runWithAnimationFrame } from 'app/onboard/new';
import { runWithAnimationFrame } from 'helper';

export interface ButtonHandlerButton {
testID?: string | undefined;
Expand Down
32 changes: 32 additions & 0 deletions components/common/Card.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Card } from './Card';
import { persistStore } from 'redux-persist';
import { Provider } from 'react-redux';
import { store } from 'helper/redux/store';

export const persistor = persistStore(store);

const meta = {
title: 'Card',
component: Card,
args: {
title: 'Hello world',
message: 'Hello world',
variant: 'info',
},
decorators: [
(Story) => (
<Provider store={store}>
<Story />
</Provider>
),
],
} satisfies Meta<typeof Card>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {
args: {},
};
1 change: 0 additions & 1 deletion components/common/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const Card = ({ title, message, variant, icon, onPress }: CardProps) => {
);

const currentStyle = useMemo(() => variantStyles[variant], [variantStyles, variant]);

return (
<TouchableOpacity onPress={onPress}>
<View
Expand Down
31 changes: 31 additions & 0 deletions components/common/Text.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Text } from './Text';
import { persistStore } from 'redux-persist';
import { Provider } from 'react-redux';
import { store } from 'helper/redux/store';

export const persistor = persistStore(store);

const meta = {
title: 'Text',
component: Text,
args: {
color: 'black',
children: 'Hello world',
},
decorators: [
(Story) => (
<Provider store={store}>
<Story />
</Provider>
),
],
} satisfies Meta<typeof Text>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {
args: {},
};
2 changes: 1 addition & 1 deletion components/common/TouchableOpacity.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { runWithAnimationFrame } from 'app/onboard/new';
import { runWithAnimationFrame } from 'helper';
import React, { useRef, FC } from 'react';
import {
TouchableOpacity as RNTouchableOpacity,
Expand Down
13 changes: 12 additions & 1 deletion components/common/View.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import type { Meta, StoryObj } from '@storybook/react';
import { View } from './View';
import { persistStore } from 'redux-persist';
import { Provider } from 'react-redux';
import { store } from 'helper/redux/store';

export const persistor = persistStore(store);

const meta = {
title: 'View',
component: View,
args: {},
decorators: [(Story) => <Story />],
decorators: [
(Story) => (
<Provider store={store}>
<Story />
</Provider>
),
],
} satisfies Meta<typeof View>;

export default meta;
Expand Down
43 changes: 24 additions & 19 deletions helper/colors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,26 @@ export const blues: Shades = {
export type GreyKey = 0 | 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
export type Greys = Record<GreyKey, string>;

export const DARK_GREYS: Greys = {
0: '#FFFFFF',
50: '#E8EAED',
100: '#C7C7C7',
200: '#A8A8A8',
300: '#787878',
400: '#525252',
500: '#2C2C2C',
600: '#202020',
700: '#1C1C1C',
800: '#181818',
900: '#121212',
950: '#080808',
};

export const greys = (t: string | Theme): Greys => {
const name = typeof t === 'string' ? t : t.id;
if (BACKGROUND_IMAGE_ATTRIBUTES?.[name]) {
return BACKGROUND_IMAGE_ATTRIBUTES[name].greys;

if (name === 'dark') {
return DARK_GREYS;
}

switch (name) {
Expand Down Expand Up @@ -574,24 +590,13 @@ export const greys = (t: string | Theme): Greys => {
};
}

case 'dark':
default: {
return {
0: '#FFFFFF',
50: '#E8EAED', // 50
100: '#C7C7C7', // 100
200: '#A8A8A8', // 200
300: '#787878', // 300
400: '#525252', // 400
500: '#2C2C2C', // 500
600: '#202020', // 600
700: '#1C1C1C', // 700
800: '#181818', // 800
900: '#121212', // 900
950: '#080808', // 950
};
}
}

if (BACKGROUND_IMAGE_ATTRIBUTES?.[name]) {
return BACKGROUND_IMAGE_ATTRIBUTES[name].greys;
}

return DARK_GREYS;
};

export const background = '#FFFFFF';
Expand Down
24 changes: 24 additions & 0 deletions helper/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Executes an async function within a requestAnimationFrame to improve UI responsiveness
*/
export const runWithAnimationFrame = <T extends any[]>(
callback: Function,
setIsSubmitting?: React.Dispatch<React.SetStateAction<boolean>>
) => {
return async (...args: T) => {
if (setIsSubmitting) {
setIsSubmitting(true);
}

requestAnimationFrame(async () => {
try {
await callback(...args);
} catch {
} finally {
if (setIsSubmitting) {
setIsSubmitting(false);
}
}
});
};
};