diff options
author | Sebastian <sebasjm@gmail.com> | 2022-09-09 12:22:26 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-09-09 12:22:57 -0300 |
commit | dda90b51f6fc6fca48a68bc53088e1ed3f018a21 (patch) | |
tree | 4b94b9496f19f25321923cafe241663b363258c2 /packages/taler-wallet-webextension/src/hooks/useTalerActionURL.ts | |
parent | 9b2d6d766f0192923d337ab8c69a332ebdc20bf1 (diff) | |
download | wallet-core-dda90b51f6fc6fca48a68bc53088e1ed3f018a21.tar.xz |
find taler action in clipboard and withdraw with mobile
Diffstat (limited to 'packages/taler-wallet-webextension/src/hooks/useTalerActionURL.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/hooks/useTalerActionURL.ts | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/packages/taler-wallet-webextension/src/hooks/useTalerActionURL.ts b/packages/taler-wallet-webextension/src/hooks/useTalerActionURL.ts index 449cb698f..74d7cbbd9 100644 --- a/packages/taler-wallet-webextension/src/hooks/useTalerActionURL.ts +++ b/packages/taler-wallet-webextension/src/hooks/useTalerActionURL.ts @@ -17,20 +17,39 @@ import { useEffect, useState } from "preact/hooks"; import { useIocContext } from "../context/iocContext.js"; +export interface UriLocation { + uri: string; + location: "clipboard" | "activeTab" +} + export function useTalerActionURL(): [ - string | undefined, + UriLocation | undefined, (s: boolean) => void, ] { - const [talerActionUrl, setTalerActionUrl] = useState<string | undefined>( + const [talerActionUrl, setTalerActionUrl] = useState<UriLocation | undefined>( undefined, ); const [dismissed, setDismissed] = useState(false); - const { findTalerUriInActiveTab } = useIocContext(); + const { findTalerUriInActiveTab, findTalerUriInClipboard } = useIocContext(); useEffect(() => { async function check(): Promise<void> { - const talerUri = await findTalerUriInActiveTab(); - setTalerActionUrl(talerUri); + const clipUri = await findTalerUriInClipboard(); + if (clipUri) { + setTalerActionUrl({ + location: "clipboard", + uri: clipUri + }); + return; + } + const tabUri = await findTalerUriInActiveTab(); + if (tabUri) { + setTalerActionUrl({ + location: "activeTab", + uri: tabUri + }); + return; + } } check(); }); |