|
41 | 41 | import { CurrencyManager } from "@requestnetwork/currency"; |
42 | 42 | import { onDestroy, onMount, tick } from "svelte"; |
43 | 43 | import { formatUnits } from "viem"; |
44 | | - import { debounce, formatAddress } from "../utils"; |
| 44 | + import { debounce, formatAddress, getEthersSigner } from "../utils"; |
45 | 45 | import { Drawer, InvoiceView } from "./dashboard"; |
46 | 46 | import { getPaymentNetworkExtension } from "@requestnetwork/payment-detection"; |
47 | 47 | import { CipherProviderTypes, CurrencyTypes } from "@requestnetwork/types"; |
48 | | - import { checkStatus } from "@requestnetwork/shared-utils/checkStatus"; |
| 48 | + import { checkStatus } from "@requestnetwork/shared-utils/checkStatus"; |
| 49 | + import { ethers } from "ethers"; |
49 | 50 |
|
50 | 51 | export let config: IConfig; |
51 | 52 | export let wagmiConfig: WagmiConfig; |
52 | 53 | export let requestNetwork: RequestNetwork | null | undefined; |
53 | 54 | export let currencies: CurrencyTypes.CurrencyInput[] = []; |
54 | 55 |
|
55 | | - let cipherProvider: CipherProviderTypes.ICipherProvider | undefined = requestNetwork?.getCipherProvider(); |
| 56 | + let cipherProvider: CipherProviderTypes.ICipherProvider & { |
| 57 | + getSessionSignatures: (signer: ethers.Signer, walletAddress: `0x${string}`) => Promise<any>; |
| 58 | + } | undefined; |
56 | 59 |
|
57 | | - let sliderValueForDecryption = cipherProvider?.isDecryptionEnabled() ? "on" : "off"; |
| 60 | + let sliderValueForDecryption = JSON.parse(localStorage?.getItem('isDecryptionEnabled') ?? "false") ? "on" : "off"; |
58 | 61 |
|
59 | 62 | let signer: `0x${string}` | undefined; |
60 | 63 | let activeConfig = config ? config : defaultConfig; |
|
99 | 102 | $: { |
100 | 103 | if (account?.address) { |
101 | 104 | tick().then(() => { |
| 105 | + enableDecryption(); |
102 | 106 | getRequests(); |
103 | 107 | }); |
104 | 108 | } |
|
128 | 132 | if (typeof unwatchAccount === "function") unwatchAccount(); |
129 | 133 | }); |
130 | 134 |
|
| 135 | + $: cipherProvider = requestNetwork?.getCipherProvider() as CipherProviderTypes.ICipherProvider & { |
| 136 | + getSessionSignatures: ( |
| 137 | + signer: ethers.Signer, |
| 138 | + walletAddress: `0x${string}` |
| 139 | + ) => Promise<any>; |
| 140 | + }; |
| 141 | +
|
131 | 142 | $: { |
132 | 143 | signer = account?.address; |
133 | 144 | } |
|
389 | 400 | const handleRemoveSelectedRequest = () => { |
390 | 401 | activeRequest = undefined; |
391 | 402 | }; |
392 | | -
|
393 | 403 | |
394 | | - $: sliderValueForDecryption, getRequests(); |
395 | | -
|
396 | | - $: { |
| 404 | + const enableDecryption = async () => { |
| 405 | + loading = true; |
397 | 406 | if(sliderValueForDecryption === 'on') { |
398 | | - cipherProvider?.enableDecryption(true); |
| 407 | + try { |
| 408 | + const signer = await getEthersSigner(wagmiConfig); |
| 409 | + if (signer && account?.address) { |
| 410 | + await cipherProvider?.getSessionSignatures(signer, account.address); |
| 411 | + cipherProvider?.enableDecryption(true); |
| 412 | + localStorage?.setItem('isDecryptionEnabled', JSON.stringify(true)); |
| 413 | + } |
| 414 | + } catch (error) { |
| 415 | + console.error("Failed to enable decryption:", error); |
| 416 | + } |
399 | 417 | } else { |
400 | 418 | cipherProvider?.enableDecryption(false); |
| 419 | + localStorage?.setItem('isDecryptionEnabled', JSON.stringify(false)); |
401 | 420 | } |
| 421 | + await getRequests(); |
| 422 | + loading = false; |
402 | 423 | } |
| 424 | + $: sliderValueForDecryption, enableDecryption(); |
403 | 425 |
|
404 | 426 | </script> |
405 | 427 |
|
|
0 commit comments