Skip to content
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
6 changes: 6 additions & 0 deletions packages/create-invoice-form/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @requestnetwork/create-invoice-form

## 0.11.12

### Patch Changes

- Fix Lit Encryption and Wallet Connections

## 0.11.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/create-invoice-form/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@requestnetwork/create-invoice-form",
"version": "0.11.11",
"version": "0.11.12",
"main": "./dist/web-component.umd.cjs",
"scripts": {
"dev": "vite dev",
Expand Down
41 changes: 34 additions & 7 deletions packages/create-invoice-form/src/lib/create-invoice-form.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<svelte:options customElement="create-invoice-form" />

<script lang="ts">
import { getAccount } from "@wagmi/core";
import { getAccount, watchAccount, WatchAccountReturnType } from "@wagmi/core";
import { Config as WagmiConfig } from "wagmi";
// Types
import { type GetAccountReturnType } from "@wagmi/core";
Expand All @@ -24,6 +24,7 @@
import Status from "@requestnetwork/shared-components/status.svelte";
import Modal from "@requestnetwork/shared-components/modal.svelte";
import { EncryptionTypes, CipherProviderTypes } from "@requestnetwork/types";
import { onDestroy, onMount, tick } from "svelte";

interface CipherProvider extends CipherProviderTypes.ICipherProvider {
disconnectWallet: () => void;
Expand All @@ -35,7 +36,7 @@
export let currencies: CurrencyTypes.CurrencyInput[] = [];
let cipherProvider: CipherProvider | undefined;

let account: GetAccountReturnType;
let account: GetAccountReturnType | undefined = wagmiConfig && getAccount(wagmiConfig);
let isTimeout = false;
let activeConfig = config ? config : defaultConfig;
let mainColor = activeConfig.colors.main;
Expand Down Expand Up @@ -121,12 +122,38 @@

$: cipherProvider = requestNetwork?.getCipherProvider() as CipherProvider;

$: {
if (wagmiConfig) {
account = getAccount(wagmiConfig);
cipherProvider?.disconnectWallet();
const handleWalletConnection = async () => {
account = getAccount(wagmiConfig);
};

const handleWalletDisconnection = () => {
cipherProvider?.disconnectWallet();
};

const handleWalletChange = (data: any) => {
if (data?.address) {
handleWalletConnection();
} else {
handleWalletDisconnection();
}
}
};

onMount(() => {
unwatchAccount = watchAccount(wagmiConfig, {
onChange(data) {
tick().then(() => {
console.log("Wallet changed");
handleWalletChange(data);
});
},
});
});

let unwatchAccount: WatchAccountReturnType | undefined;

onDestroy(() => {
if (typeof unwatchAccount === "function") unwatchAccount();
});

$: {
formData.creatorId = (account?.address ?? "") as string;
Expand Down
6 changes: 6 additions & 0 deletions packages/invoice-dashboard/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @requestnetwork/invoice-dashboard

## 0.11.10

### Patch Changes

- Fix Lit Encryption and Wallet Connections

## 0.11.9

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/invoice-dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@requestnetwork/invoice-dashboard",
"version": "0.11.9",
"version": "0.11.10",
"main": "./dist/web-component.umd.cjs",
"scripts": {
"dev": "vite dev",
Expand Down
6 changes: 3 additions & 3 deletions packages/invoice-dashboard/src/lib/view-requests.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@
};

const handleWalletDisconnection = () => {
cipherProvider?.disconnectWallet();
account = undefined;
requests = [];
activeRequest = undefined;
cipherProvider?.disconnectWallet();
cipherProvider = undefined;
account = undefined;
};

const handleWalletChange = (data: any) => {
Expand Down Expand Up @@ -384,7 +384,7 @@
};

const loadRequests = async (sliderValue: string, currentAccount: GetAccountReturnType, currentRequestNetwork: RequestNetwork | undefined | null) => {
if (!currentAccount?.address || !currentRequestNetwork && !cipherProvider) return;
if (!currentAccount?.address || !currentRequestNetwork || !cipherProvider) return;

loading = true;
if (sliderValue === "on") {
Expand Down
Loading