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

feat(HW-582): Hide bech32 if disabled through remote config #2029

Merged
merged 1 commit into from
Aug 15, 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
193 changes: 100 additions & 93 deletions src/components/account-detail.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useCallback, useMemo, useRef, useState} from 'react';

import Clipboard from '@react-native-clipboard/clipboard';
import {observer} from 'mobx-react';
import {Share, View, useWindowDimensions} from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
import QRCode from 'react-native-qrcode-svg';
Expand All @@ -22,6 +23,7 @@ import {
} from '@app/components/ui';
import {createTheme} from '@app/helpers';
import {I18N} from '@app/i18n';
import {RemoteProviderConfig} from '@app/models/provider';
import {Wallet} from '@app/models/wallet';
import {sendNotification} from '@app/services';
import {GRADIENT_END, GRADIENT_START} from '@app/variables/common';
Expand All @@ -36,107 +38,112 @@ export interface DetailsQrModalProps {
onClose: () => void;
}

export const AccountDetail = ({wallet, onClose}: DetailsQrModalProps) => {
const svg = useRef();
const {width} = useWindowDimensions();
export const AccountDetail = observer(
({wallet, onClose}: DetailsQrModalProps) => {
const svg = useRef();
const {width} = useWindowDimensions();

const [activeTab, setActiveTab] = useState(TabNames.evm);
const address = useMemo(
() => (activeTab === TabNames.evm ? wallet.address : wallet.cosmosAddress),
[activeTab, wallet.address],
);
const [activeTab, setActiveTab] = useState(TabNames.evm);
const address = useMemo(
() =>
activeTab === TabNames.evm ? wallet.address : wallet.cosmosAddress,
[activeTab, wallet.address],
);

const onCopy = useCallback(() => {
Clipboard.setString(address);
sendNotification(I18N.notificationCopied);
}, [address]);
const onCopy = useCallback(() => {
Clipboard.setString(address);
sendNotification(I18N.notificationCopied);
}, [address]);

const onShare = useCallback(() => {
Share.share({message: address});
}, [address]);
const onShare = useCallback(() => {
Share.share({message: address});
}, [address]);

const onTabChange = useCallback((tabName: TabNames) => {
setActiveTab(tabName);
}, []);
const onTabChange = useCallback((tabName: TabNames) => {
setActiveTab(tabName);
}, []);

return (
<BottomSheet onClose={onClose} i18nTitle={I18N.modalDetailsQRReceive}>
<View style={styles.tabs}>
<TopTabNavigator
contentContainerStyle={styles.tabsContentContainerStyle}
tabHeaderStyle={styles.tabHeaderStyle}
variant={TopTabNavigatorVariant.large}
onTabChange={onTabChange}>
<TopTabNavigator.Tab
name={TabNames.evm}
title={I18N.evmTitle}
component={null}
/>
<TopTabNavigator.Tab
name={TabNames.bech32}
title={I18N.bech32Title}
component={null}
/>
</TopTabNavigator>
</View>
<InfoBlock
warning
style={styles.info}
i18n={I18N.modalDetailsQRWarning}
icon={<Icon name="warning" color={Color.textYellow1} />}
/>
<LinearGradient
colors={[wallet?.colorFrom, wallet?.colorTo]}
style={styles.qrContainer}
start={GRADIENT_START}
end={GRADIENT_END}>
<View style={styles.card}>
<Card
transparent
width={width - 113}
pattern={wallet?.pattern}
colorFrom={wallet?.colorFrom}
colorTo={wallet?.colorTo}
colorPattern={wallet?.colorPattern}
/>
return (
<BottomSheet onClose={onClose} i18nTitle={I18N.modalDetailsQRReceive}>
<View style={styles.tabs}>
<TopTabNavigator
contentContainerStyle={styles.tabsContentContainerStyle}
tabHeaderStyle={styles.tabHeaderStyle}
variant={TopTabNavigatorVariant.large}
onTabChange={onTabChange}>
<TopTabNavigator.Tab
name={TabNames.evm}
title={I18N.evmTitle}
component={null}
/>
{RemoteProviderConfig.isBech32Enabled && (
<TopTabNavigator.Tab
name={TabNames.bech32}
title={I18N.bech32Title}
component={null}
/>
)}
</TopTabNavigator>
</View>
<View style={styles.qrStyle}>
<QRCode
ecl={'H'}
logo={require('@assets/images/qr-logo.png')}
value={`haqq:${address}`}
size={width - 169}
getRef={c => (svg.current = c)}
logoSize={width / 5.86}
logoBorderRadius={8}
<InfoBlock
warning
style={styles.info}
i18n={I18N.modalDetailsQRWarning}
icon={<Icon name="warning" color={Color.textYellow1} />}
/>
<LinearGradient
colors={[wallet?.colorFrom, wallet?.colorTo]}
style={styles.qrContainer}
start={GRADIENT_START}
end={GRADIENT_END}>
<View style={styles.card}>
<Card
transparent
width={width - 113}
pattern={wallet?.pattern}
colorFrom={wallet?.colorFrom}
colorTo={wallet?.colorTo}
colorPattern={wallet?.colorPattern}
/>
</View>
<View style={styles.qrStyle}>
<QRCode
ecl={'H'}
logo={require('@assets/images/qr-logo.png')}
value={`haqq:${address}`}
size={width - 169}
getRef={c => (svg.current = c)}
logoSize={width / 5.86}
logoBorderRadius={8}
/>
</View>
<Text t14 style={styles.title}>
{wallet?.name}
</Text>
<Text t10 style={styles.address}>
{address}
</Text>
</LinearGradient>

<View style={styles.buttons}>
<Button
i18n={I18N.share}
size={ButtonSize.middle}
onPress={onShare}
style={styles.button}
/>
<Button
size={ButtonSize.middle}
style={styles.button}
variant={ButtonVariant.second}
i18n={I18N.copy}
onPress={onCopy}
/>
</View>
<Text t14 style={styles.title}>
{wallet?.name}
</Text>
<Text t10 style={styles.address}>
{address}
</Text>
</LinearGradient>

<View style={styles.buttons}>
<Button
i18n={I18N.share}
size={ButtonSize.middle}
onPress={onShare}
style={styles.button}
/>
<Button
size={ButtonSize.middle}
style={styles.button}
variant={ButtonVariant.second}
i18n={I18N.copy}
onPress={onCopy}
/>
</View>
</BottomSheet>
);
};
</BottomSheet>
);
},
);

const styles = createTheme({
qrContainer: {
Expand Down
4 changes: 4 additions & 0 deletions src/models/provider/provider-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class ProviderConfigStore {
return Boolean(this.config?.nft_exists);
}

get isBech32Enabled() {
return Boolean(this.config?.bech32_exists);
}

get swapEnabled() {
return Boolean(this.config?.swap_enabled);
}
Expand Down
1 change: 1 addition & 0 deletions src/services/indexer/indexer.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type SushiPoolEstimateRequest = {

export type ProviderConfig = {
nft_exists?: boolean;
bech32_exists?: boolean;
swap_enabled: boolean;
swap_router_v3: string;
weth_address: string;
Expand Down
Loading