Skip to content

Commit

Permalink
fix(mobile): Fix Holders TonConnect
Browse files Browse the repository at this point in the history
  • Loading branch information
voloshinskii committed Feb 26, 2024
1 parent 5b8ebfb commit 9efd24c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ export const CardsList = memo<CardsListProps>((props) => {
}, [nav]);
const getTokenPrice = useGetTokenPrice();

const getPrice = useCallback((amount) => {
return getTokenPrice(CryptoCurrencies.Ton, amount);
}, []);
const getPrice = useCallback(
(amount) => {
return getTokenPrice(CryptoCurrencies.Ton, amount);
},
[getTokenPrice],
);

return (
<List indent={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type MainStackParamList = {
[MainStackRouteNames.ManageTokens]: {};
[MainStackRouteNames.AddressUpdateInfo]: {};
[MainStackRouteNames.AddWatchOnlyStack]: {};
[MainStackRouteNames.HoldersWebView]: {};
[MainStackRouteNames.HoldersWebView]: { path?: string };
[MainStackRouteNames.ChangePin]: {};
[MainStackRouteNames.ResetPin]: {};
[MainStackRouteNames.ChangePinBiometry]: {};
Expand Down
28 changes: 19 additions & 9 deletions packages/mobile/src/screens/HoldersWebView/HoldersWebView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ import { useDAppBridge } from '$core/DAppBrowser/hooks/useDAppBridge';
import { i18n } from '@tonkeeper/shared/i18n';
import { config } from '$config';
import { useWalletCurrency } from '@tonkeeper/shared/hooks';
import { Address } from '@tonkeeper/core';
import { RouteProp } from '@react-navigation/native';
import { MainStackRouteNames } from '$navigation';
import { MainStackParamList } from '$navigation/MainStack';

export interface HoldersWebViewProps {
path?: string;
route: RouteProp<MainStackParamList, MainStackRouteNames.HoldersWebView>;
}

export const HoldersWebView = memo<HoldersWebViewProps>((props) => {
Expand All @@ -64,19 +69,22 @@ export const HoldersWebView = memo<HoldersWebViewProps>((props) => {
'theme-style': 'dark',
});

const url = `${endpoint}${props.path ?? ''}?${queryParams.toString()}`;
const url = `${endpoint}${props.route.params?.path ?? ''}?${queryParams.toString()}`;

const [holdersParams, setHoldersParams] = useState({
backPolicy: 'back',
showKeyboardAccessoryView: false,
lockScroll: true,
lockScroll: false,
});

const injectionEngine = useInjectEngine(getDomainFromURL(url), 'Title', true);

const { injectedJavaScriptBeforeContentLoaded, ref, onMessage } = useDAppBridge(
tk.wallet.address.ton.raw,
url,
Address.parse(tk.wallet.address.ton.raw).toString({
testOnly: tk.wallet.isTestnet,
bounceable: true,
}),
config.get('holdersAppEndpoint', false),
);

const handleWebViewMessage = useCallback((event: WebViewMessageEvent) => {
Expand Down Expand Up @@ -165,7 +173,7 @@ export const HoldersWebView = memo<HoldersWebViewProps>((props) => {
return newValue;
});
},
[setHoldersParams],
[onCloseApp],
);

const onHardwareBackPress = useCallback(() => {
Expand All @@ -183,7 +191,7 @@ export const HoldersWebView = memo<HoldersWebViewProps>((props) => {
return true;
}
return false;
}, [holdersParams.backPolicy]);
}, [holdersParams.backPolicy, navigation, ref]);

useEffect(() => {
BackHandler.addEventListener('hardwareBackPress', onHardwareBackPress);
Expand All @@ -199,16 +207,18 @@ export const HoldersWebView = memo<HoldersWebViewProps>((props) => {
platform: Platform.OS,
platformVersion: Platform.Version,
network: tk.wallet.isTestnet ? 'testnet' : 'mainnet',
address: tk.wallet.address.ton.raw,
address: Address.parse(tk.wallet.address.ton.raw).toString({
bounceable: true,
testOnly: tk.wallet.isTestnet,
}),
publicKey: Buffer.from(tk.wallet.pubkey, 'hex').toString('base64'),
},
safeArea: safeAreaInsets,
additionalInjections: injectedJavaScriptBeforeContentLoaded,
useMainButtonAPI: true,
useStatusBarAPI: true,
});
}, [injectedJavaScriptBeforeContentLoaded]);

}, [injectedJavaScriptBeforeContentLoaded, safeAreaInsets]);
return (
<Animated.View style={styles.container.static} entering={FadeIn}>
<WebView
Expand Down

0 comments on commit 9efd24c

Please sign in to comment.