Skip to content

Commit

Permalink
Merge branch 'fix/20240730' into tmp/20240730
Browse files Browse the repository at this point in the history
  • Loading branch information
cs1707 committed Aug 2, 2024
2 parents f3fee30 + 707bb3a commit f5f9fee
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,17 @@ const TokenDetailHeader = React.memo(
token,
style,
logoStyle,
isAdded,
setIsAdded,
}: // onSmallTokenPress,
// onTokenPress,
{
token: AbstractPortfolioToken;
style?: ViewStyle;
logoStyle?: ViewStyle;
showHistory?: boolean;
isAdded: boolean;
setIsAdded: (isAdded: boolean) => void;
// onSmallTokenPress?(token: AbstractPortfolioToken): void;
// onTokenPress?(token: AbstractPortfolioToken): void;
}) => {
Expand Down Expand Up @@ -118,38 +122,6 @@ const TokenDetailHeader = React.memo(

const copyAddressIconRef = React.useRef<CopyAddressIconType>(null);

const [isAdded, setIsAdded] = React.useState(false);

const checkIsAdded = useMemoizedFn(async () => {
if (!token) return;

if (chainItem?.isTestnet) {
const isAdded = await apiCustomTestnet.isAddedCustomTestnetToken({
chainId: chainItem.id,
id: token._tokenId,
});
setIsAdded(isAdded);
} else {
let list: Token[] = [];
if (token.is_core) {
list = await preferenceService.getBlockedToken();
} else {
list = await preferenceService.getCustomizedToken();
}

const isAdded = list.some(
item =>
isSameAddress(item.address, token._tokenId) &&
item.chain === token.chain,
);
setIsAdded(isAdded);
}
});

React.useEffect(() => {
checkIsAdded();
}, [checkIsAdded]);

const {
addCustomToken,
addBlockedToken,
Expand Down Expand Up @@ -451,7 +423,6 @@ export const BottomSheetModalTokenDetail = React.forwardRef<
BottomSheetModalMethods,
{
token?: AbstractPortfolioToken | null;
isAdded?: boolean;
canClickToken?: boolean;
isTestnet?: boolean;
onDismiss?: () => void;
Expand All @@ -465,7 +436,6 @@ export const BottomSheetModalTokenDetail = React.forwardRef<
(
{
token,
isAdded,
canClickToken,
onDismiss,
onTriggerDismissFromInternal,
Expand Down Expand Up @@ -536,6 +506,40 @@ export const BottomSheetModalTokenDetail = React.forwardRef<
}
}, []);

const [isAdded, setIsAdded] = React.useState(false);

const chainItem = findChain({ serverId: token?.chain });

const checkIsAdded = useMemoizedFn(async () => {
if (!token) return;

if (chainItem?.isTestnet) {
const isAdded = await apiCustomTestnet.isAddedCustomTestnetToken({
chainId: chainItem.id,
id: token._tokenId,
});
setIsAdded(isAdded);
} else {
let list: Token[] = [];
if (token.is_core) {
list = await preferenceService.getBlockedToken();
} else {
list = await preferenceService.getCustomizedToken();
}

const isAdded = list.some(
item =>
isSameAddress(item.address, token._tokenId) &&
item.chain === token.chain,
);
setIsAdded(isAdded);
}
});

React.useEffect(() => {
checkIsAdded();
}, [checkIsAdded, token]);

// Customized and not added
const isHiddenButton = isTestnet ? false : !token?.is_core && !isAdded;

Expand Down Expand Up @@ -871,7 +875,13 @@ export const BottomSheetModalTokenDetail = React.forwardRef<
{tokenLoad?.isLoading ? (
<SkeletonTokenDetailHeader />
) : (
!!tokenWithAmount && <TokenDetailHeader token={tokenWithAmount} />
!!tokenWithAmount && (
<TokenDetailHeader
token={tokenWithAmount}
isAdded={isAdded}
setIsAdded={setIsAdded}
/>
)
)}
</BottomSheetHandlableView>
<BottomSheetFlatList
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/core/services/preference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ export class PreferenceService {
...(this.store.customizedToken || []),
token,
];
return token;
}
return null;
};
removeCustomizedToken = (token: Token) => {
this.store.customizedToken = this.store.customizedToken?.filter(
Expand Down
139 changes: 74 additions & 65 deletions apps/mobile/src/screens/CustomTestnet/components/EditTestnetPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { AddFromChainList } from './AddFromChainList';
import { CustomTestnetForm } from './CustomTestnetForm';
import { ModalLayouts } from '@/constant/layout';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import AutoLockView from '@/components/AutoLockView';

export const EditCustomTestnetPopup = ({
data,
Expand Down Expand Up @@ -141,76 +142,84 @@ export const EditCustomTestnetPopup = ({
snapPoints={['80%']}
ref={modalRef}
onDismiss={onCancel}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<View style={styles.container}>
<AppBottomSheetModalTitle
style={{ paddingTop: ModalLayouts.titleTopOffset }}
title={t('page.customRpc.EditCustomTestnetModal.title')}
/>
<KeyboardAwareScrollView
style={styles.container}
enableOnAndroid
scrollEnabled
keyboardOpeningTime={0}
keyboardShouldPersistTaps="handled">
<View style={styles.main}>
<TouchableOpacity
onPress={() => {
setIsShowAddFromChainList(true);
<AutoLockView style={{ height: '100%' }}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<View style={styles.container}>
<AppBottomSheetModalTitle
style={{ paddingTop: ModalLayouts.titleTopOffset }}
title={t('page.customRpc.EditCustomTestnetModal.title')}
/>
<KeyboardAwareScrollView
style={styles.container}
enableOnAndroid
scrollEnabled
keyboardOpeningTime={0}
keyboardShouldPersistTaps="handled">
<View style={styles.main}>
<TouchableOpacity
onPress={() => {
setIsShowAddFromChainList(true);
}}
style={styles.quickAdd}>
<RcIconFlash color={colors['neutral-body']} />
<Text style={styles.quickAddText}>
{t('page.customRpc.EditCustomTestnetModal.quickAdd')}
</Text>
<RcIconRight color={colors['neutral-body']} />
</TouchableOpacity>
<CustomTestnetForm formik={formik} isEdit={isEdit} />
</View>
</KeyboardAwareScrollView>
<View style={styles.footer}>
<Button
onPress={onCancel}
title={'Cancel'}
buttonStyle={[styles.buttonStyle]}
titleStyle={styles.btnCancelTitle}
type="white"
containerStyle={[
styles.btnContainer,
styles.btnCancelContainer,
]}
/>
<Button
title={'Confirm'}
buttonStyle={[
styles.buttonStyle,
{ backgroundColor: colors['blue-default'] },
]}
style={{
width: '100%',
}}
style={styles.quickAdd}>
<RcIconFlash color={colors['neutral-body']} />
<Text style={styles.quickAddText}>
{t('page.customRpc.EditCustomTestnetModal.quickAdd')}
</Text>
<RcIconRight color={colors['neutral-body']} />
</TouchableOpacity>
<CustomTestnetForm formik={formik} isEdit={isEdit} />
titleStyle={styles.btnConfirmTitle}
onPress={handleSubmit}
loading={loading}
containerStyle={[
styles.btnContainer,
styles.btnConfirmContainer,
]}
/>
</View>
</KeyboardAwareScrollView>
<View style={styles.footer}>
<Button
onPress={onCancel}
title={'Cancel'}
buttonStyle={[styles.buttonStyle]}
titleStyle={styles.btnCancelTitle}
type="white"
containerStyle={[styles.btnContainer, styles.btnCancelContainer]}
/>
<Button
title={'Confirm'}
buttonStyle={[
styles.buttonStyle,
{ backgroundColor: colors['blue-default'] },
]}
style={{
width: '100%',
<AddFromChainList
visible={isShowAddFromChainList}
onClose={() => {
setIsShowAddFromChainList(false);
}}
onSelect={item => {
formik.resetForm();
formik.setValues(item);
setIsShowAddFromChainList(false);
const source = ctx?.ga?.source || 'setting';
matomoRequestEvent({
category: 'Custom Network',
action: 'Choose ChainList Network',
label: `${source}_${String(item.id)}`,
});
}}
titleStyle={styles.btnConfirmTitle}
onPress={handleSubmit}
loading={loading}
containerStyle={[styles.btnContainer, styles.btnConfirmContainer]}
/>
</View>
<AddFromChainList
visible={isShowAddFromChainList}
onClose={() => {
setIsShowAddFromChainList(false);
}}
onSelect={item => {
formik.resetForm();
formik.setValues(item);
setIsShowAddFromChainList(false);
const source = ctx?.ga?.source || 'setting';
matomoRequestEvent({
category: 'Custom Network',
action: 'Choose ChainList Network',
label: `${source}_${String(item.id)}`,
});
}}
/>
</View>
</TouchableWithoutFeedback>
</TouchableWithoutFeedback>
</AutoLockView>
</AppBottomSheetModal>
);
};
Expand Down
Loading

0 comments on commit f5f9fee

Please sign in to comment.