Skip to content

Commit

Permalink
fix(mobile): multiwallet fixes (#701)
Browse files Browse the repository at this point in the history
* fix(mobile): multiwallet fixes

* update locale

* optimization
  • Loading branch information
sorokin0andrey authored Feb 14, 2024
1 parent ef28673 commit 06422f0
Show file tree
Hide file tree
Showing 25 changed files with 215 additions and 165 deletions.
5 changes: 4 additions & 1 deletion packages/mobile/src/blockchain/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ export class TonWallet {
AddressFormatter.compare(jettonBalance.walletAddress, jettonWalletAddress),
);

if (!balance || new BigNumber(balance.balance).lt(new BigNumber(amountNano))) {
if (
!balance ||
new BigNumber(Ton.toNano(balance.balance)).lt(new BigNumber(amountNano))
) {
throw new Error(t('send_insufficient_funds'));
}

Expand Down
24 changes: 19 additions & 5 deletions packages/mobile/src/core/CheckSecretWords/CheckSecretWords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const CheckSecretWords: FC = () => {
const [failed, setFailed] = useState<{ [index: number]: boolean }>({});
const [isConfigInputShown, setConfigInputShown] = useState(false);
const [config, setConfig] = useState('');
const [loading, setLoading] = useState(false);

const unlockVault = useUnlockVault();

Expand Down Expand Up @@ -122,7 +123,7 @@ export const CheckSecretWords: FC = () => {
);

const handleSubmit = useCallback(async () => {
if (!isCanSend) {
if (!isCanSend || loading) {
return;
}

Expand Down Expand Up @@ -150,6 +151,7 @@ export const CheckSecretWords: FC = () => {
}

if (tk.walletForUnlock) {
setLoading(true);
try {
await unlockVault();
const pin = getLastEnteredPasscode();
Expand All @@ -159,15 +161,27 @@ export const CheckSecretWords: FC = () => {
dispatch(
walletActions.createWallet({
pin,
onDone: isNotificationsDenied ? openSetupWalletDone : openSetupNotifications,
onFail: () => {},
onDone: (identifiers) => {
if (isNotificationsDenied) {
openSetupWalletDone(identifiers);
} else {
openSetupNotifications(identifiers);
}
setLoading(false);
},
onFail: () => {
setLoading(false);
},
}),
);
} catch {}
} catch {
setLoading(false);
}
} else {
openCreatePin();
}
}, [
loading,
isCanSend,
failed,
validateInputWord,
Expand Down Expand Up @@ -292,7 +306,7 @@ export const CheckSecretWords: FC = () => {
/>
</S.InputWrap>
</S.Inputs>
<Button disabled={!isCanSend} onPress={handleSubmit}>
<Button disabled={!isCanSend} isLoading={loading} onPress={handleSubmit}>
{t('continue')}
</Button>
</KeyboardAwareScrollView>
Expand Down
64 changes: 54 additions & 10 deletions packages/mobile/src/core/DevMenu/DevComponents/DevDeeplinking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,63 @@ import { AttachScreenButton } from '$navigation/AttachScreen';
import { Button, DevSeparator, Screen, Text } from '$uikit';
import { useDeeplinking } from '$libs/deeplinking';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { getTimeSec } from '$utils/getTimeSec';
import { Base64 } from '$utils';

const getExpiresSec = () => {
return getTimeSec() + 10 * 60;
};

export const DevDeeplinking: React.FC = () => {
const deeplinking = useDeeplinking();
const { bottom: paddingBottom } = useSafeAreaInsets();

const handleTwoTransfers = () => {
const data = Base64.encodeObj({
version: '0',
body: {
type: 'sign-raw-payload',
default: {
source: 'EQD2NmD_lH5f5u1Kj3KfGyTvhZSX0Eg6qp2a5IQUKXxOG21n',
valid_until: getExpiresSec(),
messages: [
{
address: 'EQD2NmD_lH5f5u1Kj3KfGyTvhZSX0Eg6qp2a5IQUKXxOG21n',
amount: '100000000',
},
{
address: 'EQD2NmD_lH5f5u1Kj3KfGyTvhZSX0Eg6qp2a5IQUKXxOG21n',
amount: '10000000',
payload: 'te6ccsEBAQEADgAAABgAAAAAQ29tbWVudCE07Pl9',
},
],
},
params: {
source: 'EQD2NmD_lH5f5u1Kj3KfGyTvhZSX0Eg6qp2a5IQUKXxOG21n',
valid_until: getExpiresSec(),
messages: [
{
address: 'EQD2NmD_lH5f5u1Kj3KfGyTvhZSX0Eg6qp2a5IQUKXxOG21n',
amount: '100000000',
},
{
address: 'EQD2NmD_lH5f5u1Kj3KfGyTvhZSX0Eg6qp2a5IQUKXxOG21n',
amount: '10000000',
payload: 'te6ccsEBAQEADgAAABgAAAAAQ29tbWVudCE07Pl9',
},
],
},
response_options: {
callback_url: 'https://txrequest.testtonlogin.xyz/api/complete',
return_url: 'https://txrequest.testtonlogin.xyz/api/complete',
broadcast: true,
},
expires_sec: getExpiresSec(),
},
});
deeplinking.resolve(`https://app.tonkeeper.com/v1/txrequest-inline/${data}`);
};

return (
<Screen>
<Screen.Header title="Deeplinking" rightContent={<AttachScreenButton />} />
Expand Down Expand Up @@ -37,15 +89,7 @@ export const DevDeeplinking: React.FC = () => {
</Button>

<DevSeparator />
<Button
onPress={() => {
deeplinking.resolve(
'https://app.tonkeeper.com/v1/txrequest-inline/eyJ2ZXJzaW9uIjoiMCIsImJvZHkiOnsidHlwZSI6InNpZ24tcmF3LXBheWxvYWQiLCJkZWZhdWx0Ijp7InNvdXJjZSI6IkVRRDJObURfbEg1ZjV1MUtqM0tmR3lUdmhaU1gwRWc2cXAyYTVJUVVLWHhPRzIxbiIsInZhbGlkX3VudGlsIjoxNjYyMzQ3MzgwLCJtZXNzYWdlcyI6W3siYWRkcmVzcyI6IkVRRDJObURfbEg1ZjV1MUtqM0tmR3lUdmhaU1gwRWc2cXAyYTVJUVVLWHhPRzIxbiIsImFtb3VudCI6IjEwMDAwMDAwMCJ9LHsiYWRkcmVzcyI6IkVRRDJObURfbEg1ZjV1MUtqM0tmR3lUdmhaU1gwRWc2cXAyYTVJUVVLWHhPRzIxbiIsImFtb3VudCI6IjEwMDAwMDAwIiwicGF5bG9hZCI6InRlNmNjc0VCQVFFQURnQUFBQmdBQUFBQVEyOXRiV1Z1ZENFMDdQbDkifV19LCJwYXJhbXMiOnsic291cmNlIjoiRVFEMk5tRF9sSDVmNXUxS2ozS2ZHeVR2aFpTWDBFZzZxcDJhNUlRVUtYeE9HMjFuIiwidmFsaWRfdW50aWwiOjE2NjIzNDczNzksIm1lc3NhZ2VzIjpbeyJhZGRyZXNzIjoiRVFEMk5tRF9sSDVmNXUxS2ozS2ZHeVR2aFpTWDBFZzZxcDJhNUlRVUtYeE9HMjFuIiwiYW1vdW50IjoiMTAwMDAwMDAwIn0seyJhZGRyZXNzIjoiRVFEMk5tRF9sSDVmNXUxS2ozS2ZHeVR2aFpTWDBFZzZxcDJhNUlRVUtYeE9HMjFuIiwiYW1vdW50IjoiMTAwMDAwMDAiLCJwYXlsb2FkIjoidGU2Y2NzRUJBUUVBRGdBQUFCZ0FBQUFBUTI5dGJXVnVkQ0UwN1BsOSJ9XX0sInJlc3BvbnNlX29wdGlvbnMiOnsiY2FsbGJhY2tfdXJsIjoiaHR0cHM6Ly90eHJlcXVlc3QudGVzdHRvbmxvZ2luLnh5ei9hcGkvY29tcGxldGUiLCJyZXR1cm5fdXJsIjoiaHR0cHM6Ly90eHJlcXVlc3QudGVzdHRvbmxvZ2luLnh5ei9hcGkvY29tcGxldGUiLCJicm9hZGNhc3QiOnRydWV9LCJleHBpcmVzX3NlYyI6MTY2MjM0NDY3OX19',
);
}}
>
Two transfers (txrequest-inline)
</Button>
<Button onPress={handleTwoTransfers}>Two transfers (txrequest-inline)</Button>

<DevSeparator />

Expand Down Expand Up @@ -183,7 +227,7 @@ export const DevDeeplinking: React.FC = () => {
<Button
onPress={() => {
deeplinking.resolve(
'https://app.tonkeeper.com/transfer/EQD2NmD_lH5f5u1Kj3KfGyTvhZSX0Eg6qp2a5IQUKXxOG21n?amount=2000000000000000&jetton=EQDlBqGI2r44jpnhYfEiJahU8b7Zoo3no13l6Q9H-AIJbAgo&text=test'
'https://app.tonkeeper.com/transfer/EQD2NmD_lH5f5u1Kj3KfGyTvhZSX0Eg6qp2a5IQUKXxOG21n?amount=2000000000000000&jetton=EQDlBqGI2r44jpnhYfEiJahU8b7Zoo3no13l6Q9H-AIJbAgo&text=test',
);
}}
>
Expand Down
62 changes: 13 additions & 49 deletions packages/mobile/src/core/HideableAmount/HideableAmount.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';
import { Text } from '$uikit/Text/Text';
import { TextProps } from '$uikit/Text/Text';
import Animated, { interpolate, useAnimatedStyle } from 'react-native-reanimated';
import { Steezy } from '@tonkeeper/uikit';
import { useHideableAmount } from '$core/HideableAmount/HideableAmountProvider';
import { usePrivacyStore } from '$store/zustand/privacy/usePrivacyStore';

export enum AnimationDirection {
Left = -1,
Expand All @@ -13,56 +12,21 @@ export enum AnimationDirection {

const HideableAmountComponent: React.FC<
TextProps & { stars?: string; animationDirection?: AnimationDirection }
> = ({
children,
style,
animationDirection = AnimationDirection.Right,
stars = '* * *',
...rest
}) => {
const animationProgress = useHideableAmount();
> = ({ children, style, stars = '* * *', ...rest }) => {
const isHidden = usePrivacyStore((state) => state.hiddenAmounts);

const translateXTo = 10 * animationDirection;

const amountStyle = useAnimatedStyle(() => {
return {
display: animationProgress.value < 0.5 ? 'flex' : 'none',
opacity: interpolate(animationProgress.value, [0, 0.5], [1, 0]),
transform: [
{
translateX: interpolate(animationProgress.value, [0, 0.5], [0, translateXTo]),
},
{
scale: interpolate(animationProgress.value, [0, 0.5], [1, 0.85]),
},
],
};
});

const starsStyle = useAnimatedStyle(() => {
return {
display: animationProgress.value > 0.5 ? 'flex' : 'none',
opacity: interpolate(animationProgress.value, [1, 0.5], [1, 0]),
transform: [
{
translateX: interpolate(animationProgress.value, [1, 0.5], [0, translateXTo]),
},
{
scale: interpolate(animationProgress.value, [1, 0.5], [1, 0.85]),
},
],
};
});

return (
<Animated.View>
<Text style={[amountStyle, style]} {...rest} reanimated>
{children}
</Text>
<Text style={[starsStyle, styles.stars.static, style]} {...rest} reanimated>
if (isHidden) {
return (
<Text style={[styles.stars.static, style]} {...rest}>
{stars}
</Text>
</Animated.View>
);
}

return (
<Text style={style} {...rest}>
{children}
</Text>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, useCallback } from 'react';
import React, { memo, useCallback, useMemo } from 'react';
import { t } from '@tonkeeper/shared/i18n';
import { Modal } from '@tonkeeper/uikit';

Expand All @@ -8,40 +8,54 @@ import { useNavigation, SheetActions } from '@tonkeeper/router';
import { delay } from '$utils';
import { push } from '$navigation/imperative';
import { Address } from '@tonkeeper/shared/Address';
import { useWallets } from '@tonkeeper/shared/hooks';
import { tk } from '$wallet';

export const AddressMismatchModal = memo<{ source: string; onSwitchAddress: () => void }>(
(props) => {
const nav = useNavigation();
const wallets = useWallets();

// MULTIWALLET TODO
const foundVersion = false;
const foundWallet = useMemo(() => {
return wallets.find((wallet) => {
return Address.compare(wallet.address.ton.raw, props.source);
});
}, [props.source, wallets]);

const handleCloseModal = useCallback(() => nav.goBack(), [nav]);
const handleSwitchWallet = useCallback(async () => {
if (!foundVersion) {
if (!foundWallet) {
return;
}
nav.goBack();
// tk.updateWallet({ version: foundVersion });
tk.switchWallet(foundWallet.identifier);
await delay(100);
props.onSwitchAddress();
}, [foundVersion, nav, props]);
}, [foundWallet, nav, props]);

return (
<Modal>
<Modal.Header />
<Modal.Content>
<S.Wrap>
<Icon style={{ marginBottom: 12 }} name={'ic-exclamationmark-circle-84'} />
<Icon
style={{ marginBottom: 12 }}
name={'ic-exclamationmark-circle-84'}
color="iconSecondary"
/>
<Text textAlign="center" variant="h2" style={{ marginBottom: 4 }}>
{foundVersion
? t('txActions.signRaw.addressMismatch.wrongVersion.title')
{foundWallet
? t('txActions.signRaw.addressMismatch.switchWallet.title', {
value: `${
foundWallet.config.emoji
} ${foundWallet.config.name.replaceAll(' ', ' ')}`,
})
: t('txActions.signRaw.addressMismatch.wrongWallet.title')}
</Text>
<Text variant="body1" color="foregroundSecondary" textAlign="center">
{foundVersion
? t('txActions.signRaw.addressMismatch.wrongVersion.description', {
version: foundVersion,
{foundWallet
? t('txActions.signRaw.addressMismatch.switchWallet.description', {
version: foundWallet,
})
: t('txActions.signRaw.addressMismatch.wrongWallet.description', {
address: Address.parse(props.source).toShort(),
Expand All @@ -51,18 +65,18 @@ export const AddressMismatchModal = memo<{ source: string; onSwitchAddress: () =
</Modal.Content>
<Modal.Footer>
<S.FooterWrap>
{foundVersion ? (
{foundWallet ? (
<Button
style={{ marginBottom: 16 }}
mode="primary"
onPress={handleSwitchWallet}
>
{t('txActions.signRaw.addressMismatch.wrongVersion.switch')}
{t('txActions.signRaw.addressMismatch.switchWallet.switch')}
</Button>
) : null}
<Button mode="secondary" onPress={handleCloseModal}>
{foundVersion
? t('txActions.signRaw.addressMismatch.wrongVersion.close')
{foundWallet
? t('txActions.signRaw.addressMismatch.switchWallet.close')
: t('txActions.signRaw.addressMismatch.wrongWallet.close')}
</Button>
</S.FooterWrap>
Expand Down
5 changes: 3 additions & 2 deletions packages/mobile/src/core/NFT/RenewDomainButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { openAddressMismatchModal } from '$core/ModalContainer/AddressMismatch/A
import { Base64 } from '$utils';
import { Address } from '@tonkeeper/core';
import { useWallet } from '@tonkeeper/shared/hooks';
import { tk } from '$wallet';

export type RenewDomainButtonRef = {
renewUpdated: () => void;
Expand Down Expand Up @@ -54,7 +55,7 @@ export const RenewDomainButton = forwardRef<RenewDomainButtonRef, RenewDomainBut

openSignRawModal(
{
source: wallet.address.ton.raw,
source: tk.wallet.address.ton.raw,
valid_until,
messages: [
{
Expand Down Expand Up @@ -82,7 +83,7 @@ export const RenewDomainButton = forwardRef<RenewDomainButtonRef, RenewDomainBut
return;
}

if (!Address.compare(wallet.address.ton.raw, ownerAddress)) {
if (!Address.compare(tk.wallet.address.ton.raw, ownerAddress)) {
return openAddressMismatchModal(openRenew, ownerAddress!);
} else {
openRenew();
Expand Down
11 changes: 2 additions & 9 deletions packages/mobile/src/core/Settings/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, useCallback, useMemo, useRef } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useDispatch } from 'react-redux';
import Rate, { AndroidMarket } from 'react-native-rate';
import { Alert, Linking, View } from 'react-native';
import DeviceInfo from 'react-native-device-info';
Expand Down Expand Up @@ -45,12 +45,7 @@ import { trackEvent } from '$utils/stats';
import { openAppearance } from '$core/ModalContainer/AppearanceModal';
import { config } from '$config';
import { shouldShowNotifications } from '$store/zustand/notifications/selectors';
import {
useNftsState,
useWallet,
useWalletCurrency,
useWallets,
} from '@tonkeeper/shared/hooks';
import { useNftsState, useWallet, useWalletCurrency } from '@tonkeeper/shared/hooks';
import { tk } from '$wallet';
import { mapNewNftToOldNftData } from '$utils/mapNewNftToOldNftData';
import { WalletListItem } from '@tonkeeper/shared/components';
Expand Down Expand Up @@ -242,8 +237,6 @@ export const Settings: FC = () => {
return hasDiamods && !flags.disable_apperance;
}, [hasDiamods, flags.disable_apperance]);

const wallets = useWallets();

return (
<S.Wrap>
<ScrollHandler navBarTitle={t('settings_title')}>
Expand Down
Loading

0 comments on commit 06422f0

Please sign in to comment.