diff --git a/src/components/appstate/AppState.ts b/src/components/appstate/AppState.ts index 808b4a2..f1ee5ab 100644 --- a/src/components/appstate/AppState.ts +++ b/src/components/appstate/AppState.ts @@ -4,7 +4,6 @@ import AddressBookEntry from "./components/AddressbookEntry"; import ValueTransfer from "./components/ValueTransfer"; import SendPageState from "./components/SendPageState"; import ReceivePageState from "./components/ReceivePageState"; -import RPCConfig from "./components/RPCConfig"; import Info from "./components/Info"; import ServerSelectState from "./components/ServerSelectState"; import PasswordState from "./components/PasswordState"; @@ -42,9 +41,6 @@ export default class AppState { // Any state for the receive page receivePageState: ReceivePageState; - // The Current configuration of the RPC params - rpcConfig: RPCConfig; - // getinfo result info: Info; @@ -88,7 +84,6 @@ export default class AppState { this.serverSelectState = new ServerSelectState(); this.sendPageState = new SendPageState(); this.receivePageState = {} as ReceivePageState; - this.rpcConfig = new RPCConfig(); this.info = new Info(); this.verificationProgress = 100; this.rescanning = false; diff --git a/src/components/appstate/components/RPCConfig.ts b/src/components/appstate/components/RPCConfig.ts deleted file mode 100644 index 39194d5..0000000 --- a/src/components/appstate/components/RPCConfig.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ChainNameEnum } from "./ChainNameEnum"; - -export default class RPCConfig { - url: string; - chain_name: ChainNameEnum | ""; - - constructor() { - this.url = ""; - this.chain_name = ""; - } - } - \ No newline at end of file diff --git a/src/components/appstate/index.ts b/src/components/appstate/index.ts index 494fa68..a1120ad 100644 --- a/src/components/appstate/index.ts +++ b/src/components/appstate/index.ts @@ -3,7 +3,6 @@ import AddressBookEntry from "./components/AddressbookEntry"; import ValueTransfer from "./components/ValueTransfer"; import SendPageState from "./components/SendPageState"; import ReceivePageState from "./components/ReceivePageState"; -import RPCConfig from "./components/RPCConfig"; import Info from "./components/Info"; import ServerSelectState from "./components/ServerSelectState"; import PasswordState from "./components/PasswordState"; @@ -27,7 +26,6 @@ export { SendPageState, SendProgress, ReceivePageState, - RPCConfig, Info, ServerSelectState, PasswordState, diff --git a/src/components/loadingscreen/LoadingScreen.tsx b/src/components/loadingscreen/LoadingScreen.tsx index cfb4a38..55cc911 100644 --- a/src/components/loadingscreen/LoadingScreen.tsx +++ b/src/components/loadingscreen/LoadingScreen.tsx @@ -4,7 +4,7 @@ import TextareaAutosize from "react-textarea-autosize"; import request from "request"; import progress from "progress-stream"; import native from "../../native.node"; -import { RPCConfig, Info, Server } from "../appstate"; +import { Info, Server } from "../appstate"; import RPC from "../../rpc/rpc"; import cstyles from "../common/Common.module.css"; import styles from "./LoadingScreen.module.css"; @@ -23,8 +23,6 @@ class LoadingScreenState { loadingDone: boolean; - rpcConfig: RPCConfig | null; - url: string; chain_name: '' | ChainNameEnum; @@ -59,7 +57,6 @@ class LoadingScreenState { this.currentStatus = currentStatus; this.currentStatusIsError = currentStatusIsError; this.loadingDone = false; - this.rpcConfig = null; this.url = ""; this.chain_name = ""; this.selection = ''; @@ -75,7 +72,7 @@ class LoadingScreenState { } type LoadingScreenProps = { - setRPCConfig: (rpcConfig: RPCConfig) => void; + runRPCConfiigure: () => void; setRescanning: (rescan: boolean, prevSyncId: number) => void; setInfo: (info: Info) => void; openServerSelectModal: () => void; @@ -433,8 +430,7 @@ class LoadingScreen extends Component { console.log('start runSyncStatusPoller'); - const { setRPCConfig, setInfo, setRescanning } = this.props; - const { url, chain_name } = this.state; + const { runRPCConfiigure, setInfo, setRescanning } = this.props; const info: Info = await RPC.getInfoObject(); console.log(info); @@ -478,11 +474,7 @@ class LoadingScreen extends Component void; - sendTransaction: (sendJson: SendManyJsonType[], setSendProgress: (p?: SendProgress) => void) => Promise; + sendTransaction: (sendJson: SendManyJsonType[], setSendProgress: (p?: SendProgress) => void) => Promise; setSendPageState: (sendPageState: SendPageState) => void; openErrorModal: (title: string, body: string | JSX.Element) => void; openPasswordAndUnlockIfNeeded: (successCallback: () => void) => void; diff --git a/src/components/send/components/ConfirmModal.tsx b/src/components/send/components/ConfirmModal.tsx index 5ae6472..29245eb 100644 --- a/src/components/send/components/ConfirmModal.tsx +++ b/src/components/send/components/ConfirmModal.tsx @@ -27,7 +27,7 @@ type ConfirmModalProps = { sendPageState: SendPageState; totalBalance: TotalBalance; info: Info; - sendTransaction: (sendJson: SendManyJsonType[], setSendProgress: (p?: SendProgress) => void) => Promise; + sendTransaction: (sendJson: SendManyJsonType[], setSendProgress: (p?: SendProgress) => void) => Promise; clearToAddrs: () => void; closeModal: () => void; modalIsOpen: boolean; @@ -212,21 +212,45 @@ type ConfirmModalProps = { (async () => { try { const sendJson: SendManyJsonType[] = getSendManyJSON(sendPageState); - const txid: string = await sendTransaction(sendJson, setSendProgress); + const txids: string | string[] = await sendTransaction(sendJson, setSendProgress); - openErrorModal( - "Successfully Broadcast Transaction", -
-
-
{'Transaction was successfully broadcast.'}
-
{`TXID: ${txid}`}
-
-
Utils.openTxid(txid, currencyName)}> - View TXID   - + if (typeof txids === "string") { + openErrorModal("Error Sending Transaction", `${txids}`); + } else { + openErrorModal( + "Successfully Broadcast Transaction", +
+
+
{(txids.length === 1 ? 'Transaction was' : 'Transactions were') + ' successfully broadcast.'}
+
{`TXID: ${txids[0]}`}
+ {txids.length > 1 && ( +
{`TXID: ${txids[1]}`}
+ )} + {txids.length > 2 && ( +
{`TXID: ${txids[2]}`}
+ )} +
+
+
Utils.openTxid(txids[0], info.currencyName)}> + View TXID   + +
+ {txids.length > 1 && ( +
Utils.openTxid(txids[1], info.currencyName)}> + View TXID   + +
+ )} + {txids.length > 2 && ( +
Utils.openTxid(txids[2], info.currencyName)}> + View TXID   + +
+ )} +
-
- ); + ); + } clearToAddrs(); diff --git a/src/components/send/components/ToAddrBox.tsx b/src/components/send/components/ToAddrBox.tsx index f81b78d..0a2ecef 100644 --- a/src/components/send/components/ToAddrBox.tsx +++ b/src/components/send/components/ToAddrBox.tsx @@ -241,7 +241,7 @@ const ToAddrBox = ({
updateToField(toaddr.id as number, null, null, e.target.value, null)} @@ -257,8 +257,10 @@ const ToAddrBox = ({ maxRows={5} /> )} - addReplyTo(e.target.checked)} /> - Include Reply to Unified address +
+ addReplyTo(e.target.checked)} /> + Include Reply to Unified address +
)} diff --git a/src/components/zcashd/Zcashd.tsx b/src/components/zcashd/Zcashd.tsx index d850ade..be06aab 100644 --- a/src/components/zcashd/Zcashd.tsx +++ b/src/components/zcashd/Zcashd.tsx @@ -1,12 +1,13 @@ -import React, { useContext } from "react"; +import React, { useContext, useEffect, useState } from "react"; import cstyles from "../common/Common.module.css"; import styles from "./Zcashd.module.css"; import ScrollPaneTop from "../scrollPane/ScrollPane"; import Heart from "../../assets/img/zcashdlogo.gif"; import DetailLine from "./components/DetailLine"; import { ContextApp } from "../../context/ContextAppState"; -import { ChainNameEnum } from "../appstate/components/ChainNameEnum"; import Utils from "../../utils/utils"; +import { ChainNameEnum } from "../appstate/components/ChainNameEnum"; +const { ipcRenderer } = window.require("electron"); type ZcashdProps = { refresh: () => void; @@ -16,14 +17,25 @@ type ZcashdProps = { const chains = { "main": "Mainnet", "test": "Testnet", - "regtest": "Regtest" + "regtest": "Regtest", + "": "" }; const Zcashd: React.FC = ({ refresh, openServerSelectModal }) => { const context = useContext(ContextApp); - const { info, rpcConfig } = context; - const { url, chain_name }: {url: string, chain_name: '' | ChainNameEnum} = rpcConfig; + const { info } = context; + + const [url, setUrl] = useState(""); + const [chain_name, setChain_name] = useState(""); + + useEffect(() => { + ( async () => { + const settings = await ipcRenderer.invoke("loadSettings"); + setUrl(settings?.serveruri || ''); + setChain_name(settings?.serverchain_name || ''); + })(); + }, []); if (!info || !info.latestBlock) { return ( diff --git a/src/context/ContextAppState.tsx b/src/context/ContextAppState.tsx index 1df2c66..79d38f2 100644 --- a/src/context/ContextAppState.tsx +++ b/src/context/ContextAppState.tsx @@ -1,5 +1,5 @@ import React, { ReactNode } from 'react'; -import { Address, AddressBookEntry, AppState, Info, PasswordState, RPCConfig, ReceivePageState, SendPageState, ServerSelectState, TotalBalance, ValueTransfer, WalletSettings, Server, FetchErrorType } from "../components/appstate"; +import { Address, AddressBookEntry, AppState, Info, PasswordState, ReceivePageState, SendPageState, ServerSelectState, TotalBalance, ValueTransfer, WalletSettings, Server, FetchErrorType } from "../components/appstate"; import { ErrorModalData } from '../components/errormodal'; export const defaultAppState: AppState = { @@ -14,7 +14,6 @@ export const defaultAppState: AppState = { serverSelectState: new ServerSelectState(), sendPageState: new SendPageState(), receivePageState: {} as ReceivePageState, - rpcConfig: new RPCConfig(), info: new Info(), verificationProgress: 100, rescanning: false, diff --git a/src/root/Routes.tsx b/src/root/Routes.tsx index 71f71bd..28f4f4a 100644 --- a/src/root/Routes.tsx +++ b/src/root/Routes.tsx @@ -16,7 +16,6 @@ import { ValueTransfer, SendPageState, ToAddr, - RPCConfig, Info, ReceivePageState, AddressBookEntry, @@ -353,11 +352,10 @@ class Routes extends React.Component { this.setState({ sendPageState: newSendPageState }); }; - setRPCConfig = (rpcConfig: RPCConfig) => { - console.log('=============== rpc config', rpcConfig); - this.setState({ rpcConfig }); - - this.rpc.configure(rpcConfig); + runRPCConfiigure = () => { + console.log('=============== rpc configure'); + + this.rpc.configure(); }; setZecPrice = (price?: number) => { @@ -409,11 +407,11 @@ class Routes extends React.Component { } }; - sendTransaction = async (sendJson: SendManyJsonType[], setSendProgress: (p?: SendProgress) => void): Promise => { + sendTransaction = async (sendJson: SendManyJsonType[], setSendProgress: (p?: SendProgress) => void): Promise => { try { - const result: string = await this.rpc.sendTransaction(sendJson, setSendProgress); + const result: string | string[] = await this.rpc.sendTransaction(sendJson, setSendProgress); - if (result.toLowerCase().startsWith("error")) { + if (typeof result === "string" && result.toLowerCase().startsWith("error")) { throw result; } @@ -549,22 +547,24 @@ class Routes extends React.Component {
{`TXID: ${resultJSON.txids[2]}`}
)} -
Utils.openTxid(resultJSON.txids[0], this.state.info.currencyName)}> - View TXID   - -
- {resultJSON.txids.length > 1 && ( -
Utils.openTxid(resultJSON.txids[1], this.state.info.currencyName)}> - View TXID   - -
- )} - {resultJSON.txids.length > 2 && ( -
Utils.openTxid(resultJSON.txids[2], this.state.info.currencyName)}> +
+
Utils.openTxid(resultJSON.txids[0], this.state.info.currencyName)}> View TXID  
- )} + {resultJSON.txids.length > 1 && ( +
Utils.openTxid(resultJSON.txids[1], this.state.info.currencyName)}> + View TXID   + +
+ )} + {resultJSON.txids.length > 2 && ( +
Utils.openTxid(resultJSON.txids[2], this.state.info.currencyName)}> + View TXID   + +
+ )} +
); } @@ -721,7 +721,7 @@ class Routes extends React.Component { path={routes.LOADING} render={() => ( void; fnSetVerificationProgress: (verificationProgress: number) => void; fnSetTotalBalance: (tb: TotalBalance) => void; @@ -67,9 +64,7 @@ export default class RPC { this.fnSetFetchError = fnSetFetchError; } - async configure(rpcConfig: RPCConfig) { - this.rpcConfig = rpcConfig; - + async configure() { if (!this.refreshTimerID) { this.refreshTimerID = setInterval(() => { console.log('refresh - 30 sec'); @@ -1066,12 +1061,12 @@ export default class RPC { } // Send a transaction using the already constructed sendJson structure - async sendTransaction(sendJson: SendManyJsonType[], setSendProgress: (p?: SendProgress) => void): Promise { + async sendTransaction(sendJson: SendManyJsonType[], setSendProgress: (p?: SendProgress) => void): Promise { // First, get the previous send progress id, so we know which ID to track const prevProgressStr: string = await native.zingolib_execute_async("sendprogress", ""); const prevProgressJSON = JSON.parse(prevProgressStr); const prevSendId: number = prevProgressJSON.id; - let sendTxids: string = ''; + let sendTxids: string[] = []; // proposing... try { @@ -1097,7 +1092,7 @@ export default class RPC { console.log(`Error confirming Tx: ${respJSON.error}`); throw Error(respJSON.error); } else if (respJSON.txids) { - sendTxids = respJSON.txids.join(', '); + sendTxids = respJSON.txids as string[]; } else { console.log(`Error confirming: no error, no txids `); throw Error('Error confirming: no error, no txids'); @@ -1111,7 +1106,7 @@ export default class RPC { const startTimeSeconds: number = new Date().getTime() / 1000; // The send command is async, so we need to poll to get the status - const sendTxPromise: Promise = new Promise((resolve, reject) => { + const sendTxPromise: Promise = new Promise((resolve, reject) => { const intervalID = setInterval(async () => { const progressStr: string = await native.zingolib_execute_async("sendprogress", ""); const progressJSON = JSON.parse(progressStr); @@ -1163,8 +1158,8 @@ export default class RPC { // And refresh data (full refresh) this.refresh(true); - const progressTxids = progressJSON.txid.replaceAll('created txid: ', '').split(' & ').join(', '); - resolve(progressTxids as string); + const progressTxids: string[] = progressJSON.txids; + resolve(progressTxids as string[]); } if (progressJSON.error) { @@ -1175,7 +1170,7 @@ export default class RPC { // And refresh data (full refresh) this.refresh(true); - resolve(sendTxids as string); + resolve(sendTxids as string[]); } }, 2 * 1000); // Every 2 seconds });