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: issue OK-23502 OK-23558 OK-23195 OK-23473 OK-23477 OK-23566 OK-12865 #3602

Merged
merged 6 commits into from
Sep 28, 2023
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
34 changes: 32 additions & 2 deletions packages/engine/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,36 @@ class ProviderController extends BaseProviderController {
prices: gasInfo.prices as EIP1559Fee[],
};
} catch {
const result = await this.getClient(networkId).then((client) =>
(client as Geth).rpc.batchCall<[string, { baseFeePerGas: string }]>([
['eth_maxPriorityFeePerGas', []],
['eth_getBlockByNumber', ['pending', true]],
]),
);
// doc https://docs.alchemy.com/docs/maxpriorityfeepergas-vs-maxfeepergas#example-using-maxfeepergas-a-hreflets-see-them-in-action-idlets-see-them-in-actiona
if (result) {
const coefficients: string[] = ['1.13', '1.25', '1.3'];
const [maxPriorityFeePerGas, { baseFeePerGas }] = result;
const baseFee = new BigNumber(baseFeePerGas).shiftedBy(-9);
const maxPriorityFee = new BigNumber(maxPriorityFeePerGas).shiftedBy(
-9,
);

return {
prices: coefficients.map((coefficient) => {
const maxPriorityFeePerGasBN = maxPriorityFee.times(coefficient);
return {
baseFee: baseFee.toFixed(),
maxPriorityFeePerGas: maxPriorityFeePerGasBN.toFixed(),
maxFeePerGas: baseFee
.plus(maxPriorityFeePerGasBN)
// .minus(1)
.toFixed(),
};
}),
};
}

const {
baseFeePerGas,
reward,
Expand Down Expand Up @@ -421,7 +451,7 @@ class ProviderController extends BaseProviderController {
...blockNativeGasInfo,
});
} else {
reject();
reject(new Error('failed to fetch gas info from API'));
}
}
});
Expand All @@ -439,7 +469,7 @@ class ProviderController extends BaseProviderController {
...blockNativeGasInfo,
});
} else {
reject();
reject(new Error('failed to fetch gas info from API'));
}
}
});
Expand Down
7 changes: 6 additions & 1 deletion packages/kit/src/hooks/useShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export const useShortcuts = platformEnv.isDesktop
) {
const { tabs } = getWebTabs();
if (tabs.length > 1) {
webTabsActions.closeWebTab(tabs[tabs.length - 1].id);
const curTab = tabs.find((tab) => tab.isCurrent);
if (curTab && curTab.id) {
webTabsActions.closeWebTab(curTab.id);
} else {
webTabsActions.closeWebTab(tabs[tabs.length - 1].id);
}
} else {
window.desktopApi.quitApp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {

import { webTabsActions } from '../../../../store/observable/webTabs';
import { useWebTabs } from '../Controller/useWebTabs';
import { dismissWebviewKeyboard } from '../explorerUtils';

import type { WebTab } from '../../../../store/observable/webTabs';
import type { LayoutChangeEvent } from 'react-native';
Expand All @@ -27,6 +28,10 @@ const Tab: FC<
}
> = ({ isCurrent, id, title, onLayout, favicon }) => {
const setCurrentTab = useCallback(() => {
if (platformEnv.isNative) {
// hide the keyboard for active tab
dismissWebviewKeyboard();
}
webTabsActions.setCurrentWebTab(id);
}, [id]);
const closeTab = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { makeMutable, runOnJS, withTiming } from 'react-native-reanimated';
import { getCurrentTabId } from '../../../store/observable/webTabs';

import { getWebTabs } from './Controller/useWebTabs';
import { pauseDappInteraction, resumeDappInteraction } from './explorerUtils';
import {
dismissWebviewKeyboard,
pauseDappInteraction,
resumeDappInteraction,
} from './explorerUtils';

import type { View } from 'react-native';
// for mobile tab animations
Expand Down Expand Up @@ -100,6 +104,7 @@ export const minimizeFloatingWindow = ({
after = () => {},
}: ExpandAnimationEvents) => {
pauseDappInteraction();
dismissWebviewKeyboard();
before?.();
setTimeout(() => {
expandAnim.value = withTiming(MIN_OR_HIDE, { duration: 300 }, () =>
Expand Down
36 changes: 36 additions & 0 deletions packages/kit/src/views/Discover/Explorer/explorerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,42 @@ const injectToResumeWebsocket = `
})()
`;

// for hide keyboard
const injectToDismissWebviewKeyboard = `
(function(){
document.activeElement && document.activeElement.blur()
})()
`;

export function dismissWebviewKeyboard(id?: string) {
const ref = getWebviewWrapperRef(id);
if (ref) {
if (platformEnv.isNative) {
try {
(ref.innerRef as WebView)?.injectJavaScript(
injectToDismissWebviewKeyboard,
);
} catch (error) {
// ipad mini orientation changed cause injectJavaScript ERROR, which crash app
console.error(
'blurActiveElement webview.injectJavaScript() ERROR >>>>> ',
error,
);
}
}
if (platformEnv.isDesktop) {
const deskTopRef = ref.innerRef as IElectronWebView;
if (deskTopRef) {
try {
deskTopRef.executeJavaScript(injectToDismissWebviewKeyboard);
} catch (e) {
// if not dom ready, no need to pause websocket
}
}
}
}
}

export function pauseDappInteraction(id?: string) {
const ref = getWebviewWrapperRef(id);
if (ref) {
Expand Down
38 changes: 22 additions & 16 deletions packages/kit/src/views/Discover/Home/DappRenderItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type FC, type ReactElement, useCallback } from 'react';
import { type FC, type ReactElement, cloneElement, useCallback } from 'react';

import { Box, Center, Typography } from '@onekeyhq/components';
import { NetworkIconGroup } from '@onekeyhq/kit/src/components/NetworkIconGroup';
Expand Down Expand Up @@ -109,21 +109,27 @@ export const DappItemPlain: FC<DappItemPlainProps> = (props) => {
justifyContent="space-between"
alignItems="center"
>
<Box flex="1" flexDirection="row">
<Box mr="4">
<DAppIcon url={logoURI} size={48} />
</Box>
<Box flex="1">
<Typography.Body1Strong numberOfLines={1}>
{title}
</Typography.Body1Strong>
<Typography.Body2 color="text-subdued" numberOfLines={2}>
{description}
</Typography.Body2>
<NetworkIconGroup networkIds={networkIds ?? []} />
</Box>
</Box>
<Box>{rightElement}</Box>
{({ isPressed }) => (
<>
<Box flex="1" flexDirection="row">
<Box mr="4">
<DAppIcon url={logoURI} size={48} />
</Box>
<Box flex="1">
<Typography.Body1Strong numberOfLines={1}>
{title}
</Typography.Body1Strong>
<Typography.Body2 color="text-subdued" numberOfLines={2}>
{description}
</Typography.Body2>
<NetworkIconGroup networkIds={networkIds ?? []} />
</Box>
</Box>
<Box>
{rightElement ? cloneElement(rightElement, { isPressed }) : null}
</Box>
</>
)}
</Pressable>
</DappItemPlainLayout>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/views/Discover/Home/Desktop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Desktop = () => {
>
<Box flex="1" w="full" maxW="998px">
<Tabs.Container
headerHeight={114}
headerHeight={252}
stickyTabBar
onIndexChange={onIndexChange}
headerView={<Header />}
Expand Down
12 changes: 10 additions & 2 deletions packages/kit/src/views/Discover/Home/TabFavorites/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ import { EmptySkeleton } from '../EmptySkeleton';

import type { MatchDAppItemType } from '../../Explorer/explorerUtils';

const DappItemPlainFavMenu: FC<{ item: MatchDAppItemType }> = ({ item }) => (
const DappItemPlainFavMenu: FC<{
item: MatchDAppItemType;
isPressed?: boolean;
}> = ({ item, isPressed }) => (
<Box flexDirection="column" justifyContent="center">
<FavListMenu isFav item={item}>
<IconButton type="plain" name="EllipsisVerticalOutline" size="sm" />
<IconButton
isDisabled={isPressed}
type="plain"
name="EllipsisVerticalOutline"
size="sm"
/>
</FavListMenu>
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,10 @@ const Transaction: FC<TransactionProps & { showViewInBrowser?: boolean }> = ({
[intl],
);

const onPress = useCallback(() => {
const onPress = useCallback(async () => {
if (from && to && fromNetwork && toNetwork) {
backgroundApiProxy.serviceSwap.setInputToken(from.token);
backgroundApiProxy.serviceSwap.setOutputToken(to.token);
await backgroundApiProxy.serviceSwap.setInputToken(from.token);
await backgroundApiProxy.serviceSwap.setOutputToken(to.token);

const parent = navigation.getParent() ?? navigation;
parent.goBack();
Expand Down