Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat committed Jun 7, 2024
2 parents 1237b89 + 6642231 commit 173f69c
Show file tree
Hide file tree
Showing 27 changed files with 301 additions and 364 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ It needs to be an import statement because otherwise it doesn't load properly
likely because of typescript.
*/
import '@walletconnect/react-native-compat';
import { initSentry } from '@/logger/sentry';
import { analytics } from './src/analytics';
import { StartTime } from './src/performance/start-time';
import { PerformanceTracking } from './src/performance/tracking';
import { PerformanceMetrics } from './src/performance/tracking/types/PerformanceMetrics';

initSentry();

analytics.track('Started executing JavaScript bundle');
PerformanceTracking.logDirectly(PerformanceMetrics.loadJSBundle, Date.now() - StartTime.START_TIME);
PerformanceTracking.startMeasuring(PerformanceMetrics.loadRootAppComponent);
Expand Down
13 changes: 4 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { InitialRouteContext } from '@/navigation/initialRoute';
import Routes from '@/navigation/routesNames';
import { Portal } from '@/react-native-cool-modals/Portal';
import { NotificationsHandler } from '@/notifications/NotificationsHandler';
import { initSentry, sentryRoutingInstrumentation } from '@/logger/sentry';
import { analyticsV2 } from '@/analytics';
import { getOrCreateDeviceId, securelyHashWalletAddress } from '@/analytics/utils';
import { logger, RainbowError } from '@/logger';
Expand All @@ -53,9 +52,10 @@ import { initializeRemoteConfig } from '@/model/remoteConfig';
import { NavigationContainerRef } from '@react-navigation/native';
import { RootStackParamList } from './navigation/types';
import { Address } from 'viem';
import { IS_DEV } from './env';
import { checkIdentifierOnLaunch } from './model/backup';

if (__DEV__) {
if (IS_DEV) {
reactNativeDisableYellowBox && LogBox.ignoreAllLogs();
(showNetworkRequests || showNetworkResponses) && monitorNetwork(showNetworkRequests, showNetworkResponses);
}
Expand Down Expand Up @@ -163,18 +163,14 @@ function App({ walletReady }: AppProps) {
Navigation.setTopLevelNavigator(ref);
};

const handleSentryNavigationIntegration = () => {
sentryRoutingInstrumentation?.registerNavigationContainer(navigatorRef.current);
};

return (
<Portal>
<View style={containerStyle}>
{initialRoute && (
<RemotePromoSheetProvider isWalletReady={walletReady}>
<RemoteCardProvider>
<InitialRouteContext.Provider value={initialRoute}>
<RoutesComponent onReady={handleSentryNavigationIntegration} ref={handleNavigatorRef} />
<RoutesComponent ref={handleNavigatorRef} />
<PortalConsumer />
</InitialRouteContext.Provider>
</RemoteCardProvider>
Expand All @@ -200,9 +196,7 @@ function Root() {

React.useEffect(() => {
async function initializeApplication() {
await initSentry(); // must be set up immediately
await initializeRemoteConfig();
// must happen immediately, but after Sentry
await migrate();

const isReturningUser = ls.device.get(['isReturningUser']);
Expand Down Expand Up @@ -313,6 +307,7 @@ function Root() {
);
}

/** Wrapping Root allows Sentry to accurately track startup times */
const RootWithSentry = Sentry.wrap(Root);

const PlaygroundWithReduxStore = () => (
Expand Down
34 changes: 29 additions & 5 deletions src/__swaps__/safe-math/SafeMath.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
// Utility function to remove the decimal point and keep track of the number of decimal places
const removeDecimalWorklet = (num: string): [bigint, number] => {
'worklet';
const parts = num.split('.');
const decimalPlaces = parts.length === 2 ? parts[1].length : 0;
const bigIntNum = BigInt(parts.join(''));
let decimalPlaces = 0;
let bigIntNum: bigint;

if (/[eE]/.test(num)) {
const [base, exponent] = num.split(/[eE]/);
const exp = Number(exponent);
const parts = base.split('.');
const baseDecimalPlaces = parts.length === 2 ? parts[1].length : 0;
const bigIntBase = BigInt(parts.join(''));

if (exp >= 0) {
decimalPlaces = baseDecimalPlaces - exp;
bigIntNum = bigIntBase * BigInt(10) ** BigInt(exp);
} else {
decimalPlaces = baseDecimalPlaces - exp;
bigIntNum = bigIntBase;
}
} else {
const parts = num.split('.');
decimalPlaces = parts.length === 2 ? parts[1].length : 0;
bigIntNum = BigInt(parts.join(''));
}

return [bigIntNum, decimalPlaces];
};

const isNumberStringWorklet = (value: string): boolean => {
'worklet';
return /^-?\d+(\.\d+)?$/.test(value);
return /^-?\d+(\.\d+)?([eE][-+]?\d+)?$/.test(value);
};

const isZeroWorklet = (value: string): boolean => {
Expand Down Expand Up @@ -43,7 +63,11 @@ const formatResultWorklet = (result: bigint): string => {
// Helper function to handle string and number input types
const toStringWorklet = (value: string | number): string => {
'worklet';
return typeof value === 'number' ? value.toString() : value;
const ret = typeof value === 'number' ? value.toString() : value;
if (/^\d+\.$/.test(ret)) {
return ret.slice(0, -1);
}
return ret;
};

// Converts a numeric string to a scaled integer string, preserving the specified decimal places
Expand Down
5 changes: 4 additions & 1 deletion src/__swaps__/safe-math/__tests__/SafeMath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ const RESULTS = {
floor: '1243425',
toScaledInteger: '57464009350560633',
negativePow: '0.001',
negativeExp: '6.0895415516156',
};

const VALUE_A = '1243425.345';
const VALUE_B = '3819.24';
const VALUE_C = '2';
const VALUE_D = '1243425.745';
const VALUE_E = '0.057464009350560633';
const VALUE_F = '0.001';
const VALUE_F = '147887324';
const VALUE_G = '4.11769e-8';
const NEGATIVE_VALUE = '-2412.12';
const ZERO = '0';
const ONE = '1';
Expand Down Expand Up @@ -80,6 +82,7 @@ describe('SafeMath', () => {
expect(mulWorklet(VALUE_A, VALUE_B)).toBe(RESULTS.mul);
expect(mulWorklet(Number(VALUE_A), VALUE_B)).toBe(RESULTS.mul);
expect(mulWorklet(VALUE_A, Number(VALUE_B))).toBe(RESULTS.mul);
expect(mulWorklet(VALUE_F, VALUE_G)).toBe(RESULTS.negativeExp);
});

test('divWorklet', () => {
Expand Down
10 changes: 6 additions & 4 deletions src/__swaps__/screens/Swap/components/AnimatedSwapCoinIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-nested-ternary */
import React from 'react';
import { StyleSheet, View, ViewStyle } from 'react-native';
import { PixelRatio, StyleSheet, View, ViewStyle } from 'react-native';
import { borders } from '@/styles';
import { useTheme } from '@/theme';
import Animated, { SharedValue, useAnimatedProps, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
Expand All @@ -11,7 +11,9 @@ import { AnimatedChainImage } from './AnimatedChainImage';
import { fadeConfig } from '../constants';
import { SwapCoinIconTextFallback } from './SwapCoinIconTextFallback';
import { Box } from '@/design-system';
import { IS_ANDROID } from '@/env';
import { IS_ANDROID, IS_IOS } from '@/env';

const PIXEL_RATIO = PixelRatio.get();

const fallbackIconStyle = {
...borders.buildCircleAsObject(32),
Expand Down Expand Up @@ -49,7 +51,7 @@ export const AnimatedSwapCoinIcon = React.memo(function FeedCoinIcon({
return {
source: {
...DEFAULT_FASTER_IMAGE_CONFIG,
borderRadius: IS_ANDROID ? size / 2 : undefined,
borderRadius: IS_ANDROID ? (size / 2) * PIXEL_RATIO : undefined,
transitionDuration: 0,
url: asset.value?.icon_url ?? '',
},
Expand Down Expand Up @@ -118,7 +120,7 @@ export const AnimatedSwapCoinIcon = React.memo(function FeedCoinIcon({
style={[
sx.coinIcon,
{
borderRadius: size / 2,
borderRadius: IS_IOS ? size / 2 : undefined,
height: size,
width: size,
},
Expand Down
6 changes: 5 additions & 1 deletion src/__swaps__/screens/Swap/components/AnimatedSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ type AnimatedSwitchProps = {
value: SharedValue<boolean>;
activeLabel?: string;
inactiveLabel?: string;
disabled?: boolean;
} & Omit<GestureHandlerButtonProps, 'children'>;

export function AnimatedSwitch({ value, onToggle, activeLabel, inactiveLabel, ...props }: AnimatedSwitchProps) {
export function AnimatedSwitch({ value, onToggle, activeLabel, inactiveLabel, disabled = false, ...props }: AnimatedSwitchProps) {
const { isDarkMode } = useColorMode();

const inactiveBg = useForegroundColor('fillSecondary');
Expand All @@ -27,6 +28,7 @@ export function AnimatedSwitch({ value, onToggle, activeLabel, inactiveLabel, ..
? withTiming(opacityWorklet(inactiveBg, 0.12), TIMING_CONFIGS.fadeConfig)
: withTiming(opacityWorklet(activeBg, 0.64), TIMING_CONFIGS.fadeConfig),
borderColor: opacityWorklet(border, 0.06),
opacity: disabled ? 0.4 : 1,
};
});

Expand All @@ -41,6 +43,8 @@ export function AnimatedSwitch({ value, onToggle, activeLabel, inactiveLabel, ..
});

const labelItem = useDerivedValue(() => {
if (disabled) return;

if (!activeLabel && !inactiveLabel) {
return;
}
Expand Down
28 changes: 21 additions & 7 deletions src/__swaps__/screens/Swap/components/ReviewPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { useNavigation } from '@/navigation';
import Routes from '@/navigation/routesNames';
import { ethereumUtils } from '@/utils';
import { getNativeAssetForNetwork } from '@/utils/ethereumUtils';
import { getNetworkObj } from '@/networks';
import { chainNameFromChainId } from '@/__swaps__/utils/chains';

const UNKNOWN_LABEL = i18n.t(i18n.l.swap.unknown);
Expand Down Expand Up @@ -119,14 +120,32 @@ function EstimatedArrivalTime() {
);
}

function FlashbotsToggle() {
const { SwapSettings } = useSwapContext();

const inputAssetChainId = swapsStore(state => state.inputAsset?.chainId) ?? ChainId.mainnet;
const isFlashbotsEnabledForNetwork = getNetworkObj(ethereumUtils.getNetworkFromChainId(inputAssetChainId)).features.flashbots;
const flashbotsToggleValue = useDerivedValue(() => isFlashbotsEnabledForNetwork && SwapSettings.flashbots.value);

return (
<AnimatedSwitch
onToggle={SwapSettings.onToggleFlashbots}
disabled={!isFlashbotsEnabledForNetwork}
value={flashbotsToggleValue}
activeLabel={i18n.t(i18n.l.expanded_state.swap.on)}
inactiveLabel={i18n.t(i18n.l.expanded_state.swap.off)}
/>
);
}

export function ReviewPanel() {
const { navigate } = useNavigation();
const { isDarkMode } = useColorMode();
const { configProgress, SwapSettings, SwapInputController, internalSelectedInputAsset, internalSelectedOutputAsset } = useSwapContext();

const unknown = i18n.t(i18n.l.swap.unknown);

const chainName = useDerivedValue(() => ChainNameDisplay[internalSelectedOutputAsset.value?.chainId ?? ChainId.mainnet]);
const chainName = useDerivedValue(() => ChainNameDisplay[internalSelectedInputAsset.value?.chainId ?? ChainId.mainnet]);

const minimumReceived = useDerivedValue(() => {
if (!SwapInputController.formattedOutputAmount.value || !internalSelectedOutputAsset.value?.symbol) {
Expand Down Expand Up @@ -266,12 +285,7 @@ export function ReviewPanel() {
</ButtonPressAnimation>
</Inline>

<AnimatedSwitch
onToggle={SwapSettings.onToggleFlashbots}
value={SwapSettings.flashbots}
activeLabel={i18n.t(i18n.l.expanded_state.swap.on)}
inactiveLabel={i18n.t(i18n.l.expanded_state.swap.off)}
/>
<FlashbotsToggle />
</Inline>

<Inline wrap={false} horizontalSpace="10px" alignVertical="center" alignHorizontal="justify">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ export function useSwapInputsController({
if (inputMethod.value === 'outputAmount' || typeof inputValues.value.outputAmount === 'string') {
return addCommasToNumber(inputValues.value.outputAmount, '0');
}

return valueBasedDecimalFormatter({
amount: inputValues.value.outputAmount,
usdTokenPrice: outputNativePrice.value,
Expand Down
3 changes: 2 additions & 1 deletion src/__swaps__/types/search.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address } from 'viem';

import { AddressOrEth, ParsedAsset, UniqueId } from '@/__swaps__/types/assets';
import { AddressOrEth, AssetType, ParsedAsset, UniqueId } from '@/__swaps__/types/assets';
import { ChainId } from '@/__swaps__/types/chains';

export type TokenSearchAssetKey = keyof ParsedAsset;
Expand Down Expand Up @@ -29,5 +29,6 @@ export type SearchAsset = {
};
rainbowMetadataId?: number;
symbol: string;
type?: AssetType;
uniqueId: UniqueId;
};
2 changes: 1 addition & 1 deletion src/__swaps__/utils/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export const parseSearchAsset = ({
balance: userAsset?.balance || { amount: '0', display: '0.00' },
icon_url: userAsset?.icon_url || assetWithPrice?.icon_url || searchAsset?.icon_url,
colors: userAsset?.colors || assetWithPrice?.colors || searchAsset?.colors,
type: userAsset?.type || assetWithPrice?.type,
type: userAsset?.type || assetWithPrice?.type || searchAsset?.type,
});

export function filterAsset(asset: ZerionAsset) {
Expand Down
5 changes: 1 addition & 4 deletions src/components/DappBrowser/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { useBrowserWorkletsContext } from '../BrowserWorkletsContext';
import { SearchResults } from './results/SearchResults';
import { useSearchContext } from './SearchContext';
import { useSyncSharedValue } from '@/hooks/reanimated/useSyncSharedValue';
import { DappsContextProvider } from '@/resources/metadata/dapps';
import { useSharedValueState } from '@/hooks/reanimated/useSharedValueState';

export const Search = () => {
Expand Down Expand Up @@ -125,9 +124,7 @@ export const Search = () => {
<>
<KeyboardHeightSetter isFocused={isFocusedValue} />
<Animated.View style={[backgroundStyle, styles.searchBackground, { backgroundColor: isDarkMode ? globalColors.grey100 : '#FBFCFD' }]}>
<DappsContextProvider>
<SearchResults goToUrl={handleUrlSubmit} isFocused={isFocusedValue} />
</DappsContextProvider>
<SearchResults goToUrl={handleUrlSubmit} isFocused={isFocusedValue} />
</Animated.View>
<Animated.View style={[bottomBarStyle, styles.bottomBarStyle]}>
<Animated.View style={[styles.barStyle, barStyle, expensiveBarStyles]}>
Expand Down
Loading

0 comments on commit 173f69c

Please sign in to comment.