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

fix(mobile): Fix Holders TonConnect #748

Merged
merged 1 commit into from
Mar 4, 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
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
Loading