Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/rainbow-me/rainbow into …
Browse files Browse the repository at this point in the history
…@benisgold/user-assets-migration-v2
  • Loading branch information
benisgold committed Sep 19, 2024
2 parents 57b4479 + b836ad8 commit c59c39a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
26 changes: 12 additions & 14 deletions src/hooks/useColorForAsset.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useMemo } from 'react';
import { lightModeThemeColors } from '../styles/colors';
import { ParsedAddressAsset } from '@/entities';
import { useTheme } from '@/theme';
import { ethereumUtils, isETH, pseudoRandomArrayItemFromString } from '@/utils';
import { usePersistentDominantColorFromImage } from './usePersistentDominantColorFromImage';

Expand All @@ -11,28 +10,27 @@ export default function useColorForAsset(
forceLightMode = false,
forceETHColor = false
) {
// @ts-expect-error ts-migrate(2304) FIXME: Cannot find name 'useTheme'.
const { isDarkMode: isDarkModeTheme, colors } = useTheme();
const accountAsset = ethereumUtils.getAssetFromAllAssets(asset.uniqueId || asset.mainnet_address || asset.address);
const resolvedAddress = asset.mainnet_address || asset.address || accountAsset.address;
const accountAsset = ethereumUtils.getAssetFromAllAssets(asset?.uniqueId || asset?.mainnet_address || asset?.address);
const resolvedAddress = asset?.mainnet_address || asset?.address || accountAsset?.address;

const derivedColor = usePersistentDominantColorFromImage(accountAsset?.icon_url || asset?.icon_url);
const isDarkMode = forceLightMode || isDarkModeTheme;

const colorDerivedFromAddress = useMemo(() => {
if (!isETH(resolvedAddress)) {
return pseudoRandomArrayItemFromString(resolvedAddress, colors.avatarBackgrounds);
}

if (isDarkMode) {
if (forceETHColor) return colors.appleBlue;
return colors.brighten(lightModeThemeColors.dark);
}

return colors.dark;
const color = isETH(resolvedAddress)
? isDarkMode
? forceETHColor
? colors.appleBlue
: colors.brighten(lightModeThemeColors.dark)
: colors.dark
: pseudoRandomArrayItemFromString(resolvedAddress, colors.avatarBackgrounds);
return color;
}, [colors, forceETHColor, isDarkMode, resolvedAddress]);

return useMemo(() => {
let color2Return: string;
let color2Return;

// we have special handling for eth color
if (isETH(resolvedAddress)) {
Expand Down
31 changes: 17 additions & 14 deletions src/react-native-cool-modals/ios/RNCMScreen.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// lib
#import "Rainbow-Swift.h"


@interface RNCMScreenView () <UIAdaptivePresentationControllerDelegate, RCTInvalidating>
@end

Expand Down Expand Up @@ -66,7 +65,6 @@ - (void)willDismiss {
- (void) setIsShortFormEnabled:(BOOL)isShortFormEnabled {
_isShortFormEnabled = isShortFormEnabled;
[(PanModalViewController*) [_controller parentVC] panModalSetNeedsLayoutUpdateWrapper];

}

- (void) layout {
Expand All @@ -83,7 +81,6 @@ - (void) setHidden:(BOOL)hidden {
}
[(PanModalViewController*) [_controller parentVC] hide];
});

}
}

Expand Down Expand Up @@ -131,7 +128,6 @@ - (void)updateBounds
[_bridge.uiManager setSize:self.bounds.size forView:self];
}


- (void)setPointerEvents:(RCTPointerEvents)pointerEvents
{
// pointer events settings are managed by the parent screen container, we ignore
Expand Down Expand Up @@ -335,11 +331,14 @@ - (instancetype)initWithView:(UIView *)view

- (void)presentModally:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion slackStack:(BOOL)slackStack {
return [_parentVC presentModally:viewControllerToPresent animated:flag completion:completion slackStack:slackStack];

}

- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion {
return [_parentVC dismissViewControllerAnimated:flag completion:completion];
if (self.parentViewController) {
[self.parentViewController dismissViewControllerAnimated:flag completion:completion];
} else {
[super dismissViewControllerAnimated:flag completion:completion];
}
}

- (UIViewController *)presentedViewController {
Expand All @@ -361,6 +360,16 @@ - (void)viewDidLayoutSubviews
}
}

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
BOOL isContextMenu = [viewControllerToPresent isKindOfClass:NSClassFromString(@"_UIContextMenuActionsOnlyViewController")];

if (isContextMenu) {
[_parentVC presentViewController:viewControllerToPresent animated:flag completion:completion];
} else {
[super presentViewController:viewControllerToPresent animated:flag completion:completion];
}
}

- (id)findFirstResponder:(UIView*)parent
{
if (parent.isFirstResponder) {
Expand Down Expand Up @@ -426,7 +435,6 @@ @implementation RNCMScreenManager
}
[(RNCMScreenView *) view jumpTo:point];
}];

}

RCT_EXPORT_METHOD(layout:(nonnull NSNumber*) reactTag) {
Expand All @@ -438,10 +446,8 @@ @implementation RNCMScreenManager
}
[(RNCMScreenView *) view layout];
}];

}


RCT_EXPORT_MODULE()

RCT_EXPORT_VIEW_PROPERTY(gestureEnabled, BOOL)
Expand Down Expand Up @@ -476,7 +482,6 @@ @implementation RNCMScreenManager
RCT_EXPORT_VIEW_PROPERTY(ignoreBottomOffset, BOOL)
RCT_EXPORT_VIEW_PROPERTY(hidden, BOOL)


- (UIView *)view
{
return [[RNCMScreenView alloc] initWithBridge:self.bridge];
Expand All @@ -494,15 +499,13 @@ @implementation RCTConvert (RNSScreen)
@"containedModal": @(RNSScreenStackPresentationContainedModal),
@"transparentModal": @(RNSScreenStackPresentationTransparentModal),
@"containedTransparentModal": @(RNSScreenStackPresentationContainedTransparentModal)
}), RNSScreenStackPresentationPush, integerValue)
}), RNSScreenStackPresentationPush, integerValue)

RCT_ENUM_CONVERTER(RNSScreenStackAnimation, (@{
@"default": @(RNSScreenStackAnimationDefault),
@"none": @(RNSScreenStackAnimationNone),
@"fade": @(RNSScreenStackAnimationFade),
@"flip": @(RNSScreenStackAnimationFlip),
}), RNSScreenStackAnimationDefault, integerValue)

}), RNSScreenStackAnimationDefault, integerValue)

@end

4 changes: 3 additions & 1 deletion src/utils/pseudoRandomArrayItemFromString.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const cache: { [key: string]: number } = {};

// For a given string, will always return same item from an array.
export default function pseudoRandomArrayItemFromString<T>(string: string, array: T[]): T {
export default function pseudoRandomArrayItemFromString<T>(string: string, array: T[]): T | null {
if (!string) return null;

if (!cache[string]) {
cache[string] = [...string].map(char => char.toLowerCase().charCodeAt(0)).reduce((acc, v) => acc + v, 0);
}
Expand Down

0 comments on commit c59c39a

Please sign in to comment.