Skip to content

Commit a24e463

Browse files
fix: lit and wallet issues (#265)
1 parent 9afd990 commit a24e463

File tree

6 files changed

+51
-12
lines changed

6 files changed

+51
-12
lines changed

packages/create-invoice-form/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @requestnetwork/create-invoice-form
22

3+
## 0.11.12
4+
5+
### Patch Changes
6+
7+
- Fix Lit Encryption and Wallet Connections
8+
39
## 0.11.11
410

511
### Patch Changes

packages/create-invoice-form/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@requestnetwork/create-invoice-form",
3-
"version": "0.11.11",
3+
"version": "0.11.12",
44
"main": "./dist/web-component.umd.cjs",
55
"scripts": {
66
"dev": "vite dev",

packages/create-invoice-form/src/lib/create-invoice-form.svelte

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<svelte:options customElement="create-invoice-form" />
22

33
<script lang="ts">
4-
import { getAccount } from "@wagmi/core";
4+
import { getAccount, watchAccount, WatchAccountReturnType } from "@wagmi/core";
55
import { Config as WagmiConfig } from "wagmi";
66
// Types
77
import { type GetAccountReturnType } from "@wagmi/core";
@@ -24,6 +24,7 @@
2424
import Status from "@requestnetwork/shared-components/status.svelte";
2525
import Modal from "@requestnetwork/shared-components/modal.svelte";
2626
import { EncryptionTypes, CipherProviderTypes } from "@requestnetwork/types";
27+
import { onDestroy, onMount, tick } from "svelte";
2728
2829
interface CipherProvider extends CipherProviderTypes.ICipherProvider {
2930
disconnectWallet: () => void;
@@ -35,7 +36,7 @@
3536
export let currencies: CurrencyTypes.CurrencyInput[] = [];
3637
let cipherProvider: CipherProvider | undefined;
3738
38-
let account: GetAccountReturnType;
39+
let account: GetAccountReturnType | undefined = wagmiConfig && getAccount(wagmiConfig);
3940
let isTimeout = false;
4041
let activeConfig = config ? config : defaultConfig;
4142
let mainColor = activeConfig.colors.main;
@@ -121,12 +122,38 @@
121122
122123
$: cipherProvider = requestNetwork?.getCipherProvider() as CipherProvider;
123124
124-
$: {
125-
if (wagmiConfig) {
126-
account = getAccount(wagmiConfig);
127-
cipherProvider?.disconnectWallet();
125+
const handleWalletConnection = async () => {
126+
account = getAccount(wagmiConfig);
127+
};
128+
129+
const handleWalletDisconnection = () => {
130+
cipherProvider?.disconnectWallet();
131+
};
132+
133+
const handleWalletChange = (data: any) => {
134+
if (data?.address) {
135+
handleWalletConnection();
136+
} else {
137+
handleWalletDisconnection();
128138
}
129-
}
139+
};
140+
141+
onMount(() => {
142+
unwatchAccount = watchAccount(wagmiConfig, {
143+
onChange(data) {
144+
tick().then(() => {
145+
console.log("Wallet changed");
146+
handleWalletChange(data);
147+
});
148+
},
149+
});
150+
});
151+
152+
let unwatchAccount: WatchAccountReturnType | undefined;
153+
154+
onDestroy(() => {
155+
if (typeof unwatchAccount === "function") unwatchAccount();
156+
});
130157
131158
$: {
132159
formData.creatorId = (account?.address ?? "") as string;

packages/invoice-dashboard/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @requestnetwork/invoice-dashboard
22

3+
## 0.11.10
4+
5+
### Patch Changes
6+
7+
- Fix Lit Encryption and Wallet Connections
8+
39
## 0.11.9
410

511
### Patch Changes

packages/invoice-dashboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@requestnetwork/invoice-dashboard",
3-
"version": "0.11.9",
3+
"version": "0.11.10",
44
"main": "./dist/web-component.umd.cjs",
55
"scripts": {
66
"dev": "vite dev",

packages/invoice-dashboard/src/lib/view-requests.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@
109109
};
110110
111111
const handleWalletDisconnection = () => {
112-
cipherProvider?.disconnectWallet();
112+
account = undefined;
113113
requests = [];
114114
activeRequest = undefined;
115+
cipherProvider?.disconnectWallet();
115116
cipherProvider = undefined;
116-
account = undefined;
117117
};
118118
119119
const handleWalletChange = (data: any) => {
@@ -384,7 +384,7 @@
384384
};
385385
386386
const loadRequests = async (sliderValue: string, currentAccount: GetAccountReturnType, currentRequestNetwork: RequestNetwork | undefined | null) => {
387-
if (!currentAccount?.address || !currentRequestNetwork && !cipherProvider) return;
387+
if (!currentAccount?.address || !currentRequestNetwork || !cipherProvider) return;
388388
389389
loading = true;
390390
if (sliderValue === "on") {

0 commit comments

Comments
 (0)