Skip to content

Commit

Permalink
Update index.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
huhuanming committed Dec 18, 2024
1 parent 6681280 commit a2dfec8
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ const textStyle = {

const containerId = 'onekey-floating-widget';

const removeApp = () => {
const removeIcon = () => {
document.getElementById(containerId)?.remove();
isInjected = false;
}

const useOutsideClick = (
Expand Down Expand Up @@ -81,7 +82,7 @@ function CloseDialog({ onClose }: { onClose: () => void }) {
}).$onekey.$private.request({
method: 'wallet_disableFloatingButton',
});
removeApp();
removeIcon();
}, [])
const handleHideOnSite = useCallback(() => {
void (globalThis as unknown as {
Expand All @@ -96,7 +97,7 @@ function CloseDialog({ onClose }: { onClose: () => void }) {
method: 'wallet_hideFloatingButtonOnSite',
params: { url: window.location.origin },
});
removeApp();
removeIcon();
}, [])
return (
<div
Expand Down Expand Up @@ -671,7 +672,6 @@ function App() {

return (
<div
id={containerId}
style={{
position: 'fixed',
zIndex: 999_999,
Expand Down Expand Up @@ -746,6 +746,7 @@ async function injectIcon() {
}
isInjected = true;
const div = document.createElement('div');
div.id = containerId
document.body.appendChild(div);
render(<App />, document.body, div);
}
Expand All @@ -760,7 +761,11 @@ export function injectFloatingButton() {
}
}
}).$onekey.$private.onNotifyFloatingIconChanged(({ showFloatingIcon }: { showFloatingIcon: boolean }) => {
console.log(showFloatingIcon);
if (showFloatingIcon) {
void injectIcon();
} else {
removeIcon();
}
});
void injectIcon();
}

0 comments on commit a2dfec8

Please sign in to comment.