Skip to content
Open
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
15 changes: 4 additions & 11 deletions Govt-Billing-React/src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as AppGeneral from "../socialcalc/index.js";
import { File, Local } from "../Storage/LocalStorage";
import { isPlatform, IonToast } from "@ionic/react";
import { EmailComposer } from "capacitor-email-composer";
import { Printer } from "@ionic-native/printer";
import { IonActionSheet, IonAlert } from "@ionic/react";
import { saveOutline, save, mail, print } from "ionicons/icons";
import { APP_NAME } from "../../app-data.js";
Expand Down Expand Up @@ -57,16 +56,10 @@ const Menu: React.FC<{
};

const doPrint = () => {
if (isPlatform("hybrid")) {
const printer = Printer;
printer.print(AppGeneral.getCurrentHTMLContent());
} else {
const content = AppGeneral.getCurrentHTMLContent();
// useReactToPrint({ content: () => content });
const printWindow = window.open("/printwindow", "Print Invoice");
printWindow.document.write(content);
printWindow.print();
}
const content = AppGeneral.getCurrentHTMLContent();
const printWindow = window.open("/printwindow", "Print Invoice");
printWindow.document.write(content);
printWindow.print();
};
const doSave = () => {
if (props.file === "default") {
Expand Down
28 changes: 27 additions & 1 deletion Govt-Billing-React/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ import Menu from "../components/Menu/Menu";
import Files from "../components/Files/Files";
import NewFile from "../components/NewFile/NewFile";
import { initFirebase } from "../firebase/index";
import { ethers, BrowserProvider } from "ethers";

declare global {
interface Window {
ethereum?: any;
}
}

const Home: React.FC = () => {
const [showMenu, setShowMenu] = useState(false);
Expand All @@ -32,6 +39,7 @@ const Home: React.FC = () => {
const [selectedFile, updateSelectedFile] = useState("default");
const [billType, updateBillType] = useState(1);
const [device] = useState("default");
const [walletAddress, setWalletAddress] = useState("");

initFirebase();

Expand Down Expand Up @@ -73,6 +81,22 @@ const Home: React.FC = () => {
);
});

const connectWallet = async () => {
if (window.ethereum) {
try {
const provider = new BrowserProvider(window.ethereum);
await provider.send("eth_requestAccounts", []);
const signer = await provider.getSigner();
const address = await signer.getAddress();
setWalletAddress(address);
} catch (err) {
alert("Wallet connection failed");
}
} else {
alert("MetaMask is not installed. Please install it to use this feature.");
}
};

return (
<IonPage>
<IonHeader>
Expand All @@ -83,7 +107,9 @@ const Home: React.FC = () => {
<IonContent fullscreen>
<IonToolbar color="primary">
<Login />

<IonButton slot="end" onClick={connectWallet} color="tertiary">
{walletAddress ? `Connected: ${walletAddress.slice(0, 6)}...${walletAddress.slice(-4)}` : "Connect Wallet"}
</IonButton>
<IonIcon
icon={settings}
slot="end"
Expand Down