diff --git a/joinmarket/src/App.js b/joinmarket/src/App.js
index a5951daa..8bdab8cf 100644
--- a/joinmarket/src/App.js
+++ b/joinmarket/src/App.js
@@ -1,476 +1,399 @@
-import './App.css';
-import '@ibunker/bitcoin-react/dist/index.css';
+import './App.css'
+import '@ibunker/bitcoin-react/dist/index.css'
import {useState,useEffect} from 'react'
-import Wallets from './components/Wallets';
-import Payment from './components/Payment';
-import CreateWallet from './components/CreateWallet';
-import Homepage from './components/homepage';
-import Maker from './components/Maker';
-import Receive from './components/Receive';
+import Wallets from './components/Wallets'
+import Payment from './components/Payment'
+import CreateWallet from './components/CreateWallet'
+import Homepage from './components/homepage'
+import Maker from './components/Maker'
+import Receive from './components/Receive'
import DisplayWallet from './components/DisplayWallet'
-import * as rb from 'react-bootstrap';
+import * as rb from 'react-bootstrap'
import github_logo from './github.svg'
import twitter_logo from './twitter.svg'
import useInterval from './components/utils'
-import { BrowserRouter as Router, Route ,Switch} from 'react-router-dom';
-import { useGlobal } from 'reactn';
+import { BrowserRouter as Router, Route ,Switch} from 'react-router-dom'
+import { useGlobal } from 'reactn'
function App() {
- const [walletList,setWalletList] = useState([])
- const [makerStarted, setmakerStarted] = useGlobal("makerStarted");
- const [walletName, setWalletName] = useGlobal("walletName");
- const [coinjoinInProcess, setCoinjoinInProcess] = useGlobal("coinjoinInProcess");
- const [, setCurrentStatusMessage] = useGlobal("currentStatusMessage");
+ const [walletList, setWalletList] = useState([])
+ const [makerStarted, setmakerStarted] = useGlobal('makerStarted')
+ const [walletName, setWalletName] = useGlobal('walletName')
+ const [coinjoinInProcess, setCoinjoinInProcess] = useGlobal('coinjoinInProcess')
+ const [, setCurrentStatusMessage] = useGlobal('currentStatusMessage')
const listWallets = async () =>{
- const res = await fetch('/api/v1/wallet/all');
- const data = await res.json();
- const walletList = data.wallets;
- return walletList;
+ const res = await fetch('/api/v1/wallet/all')
+ const data = await res.json()
+ return data.wallets
}
+
const resetWalletSessionStorage = async () =>{
- sessionStorage.clear();
- setWalletName("No wallet loaded");
- setmakerStarted(false);
- setCoinjoinInProcess(false);
+ sessionStorage.clear()
+ setWalletName('No wallet loaded')
+ setmakerStarted(false)
+ setCoinjoinInProcess(false)
}
const getCurrentStatusMessage = () =>
- `Wallet: ${walletName}, YG ${makerStarted ? 'started' : 'not running'}, Coinjoin in process: ${coinjoinInProcess}`;
+ `Wallet: ${walletName}, YG ${makerStarted ? 'started' : 'not running'}, Coinjoin in process: ${coinjoinInProcess}`
useInterval(() => {
- const sessionClear = async () =>{
+ const sessionClear = async () => {
try {
- const res = await fetch('/api/v1/session');
- const { session, maker_running, wallet_name, coinjoin_in_process } = await res.json();
+ const res = await fetch('/api/v1/session')
+ const { session, maker_running, wallet_name, coinjoin_in_process } = await res.json()
if (session === false) {
- console.log("no wallet in backend");
+ console.log('no wallet in backend')
// This status requires us to clear, especially
// the auth state, so we just reset everything:
- return resetWalletSessionStorage();
+ return resetWalletSessionStorage()
}
- setmakerStarted(maker_running);
- setWalletName(wallet_name);
- setCoinjoinInProcess(coinjoin_in_process);
- setCurrentStatusMessage(getCurrentStatusMessage());
+ setmakerStarted(maker_running)
+ setWalletName(wallet_name)
+ setCoinjoinInProcess(coinjoin_in_process)
+ setCurrentStatusMessage(getCurrentStatusMessage())
} catch(e) {
- console.error(e);
- alert("Lost connection to backend! Please restart the backend server.");
- sessionStorage.clear();
+ console.error(e)
+ alert('Lost connection to backend! Please restart the backend server.')
+ sessionStorage.clear()
}
}
- sessionClear();
+ sessionClear()
+ }, 8*1000)
- }, 8*1000);
-
- useEffect(()=>{
-
- const getWallets = async()=>{
- const wallets = await listWallets();
- setWalletList(wallets);
+ useEffect(() => {
+ const getWallets = async () => {
+ const wallets = await listWallets()
+ setWalletList(wallets)
}
-
- getWallets();
-
- },[])
-
+ getWallets()
+ }, [])
const unlockWallet = async (name) => {
- const authData = JSON.parse(sessionStorage.getItem('auth'));
+ const authData = JSON.parse(sessionStorage.getItem('auth'))
if (authData && authData.login) {
return alert(authData.name === name
// unlocking same wallet
? `${name} is already unlocked`
// unlocking another wallet while one is already unlocked
- : `${authData.name} is currently in use, please lock it first`);
+ : `${authData.name} is currently in use, please lock it first`)
} else {
try {
- const password = prompt(`Enter the passphrase for ${name}`);
+ const password = prompt(`Enter the passphrase for ${name}`)
const res = await fetch(`/api/v1/wallet/${name}/unlock`,{
method: 'POST',
headers: { 'Content-type': 'application/json' },
body: JSON.stringify({ password }),
})
- const data = await res.json();
+ const data = await res.json()
console.log(data)
- const token = data.token;
- sessionStorage.setItem('auth', JSON.stringify({ login: true, token, name }));
+ const token = data.token
+ sessionStorage.setItem('auth', JSON.stringify({ login: true, token, name }))
} catch (e) {
- console.error(e);
- alert('Something went wrong, please try again!');
+ console.error(e)
+ alert('Something went wrong, please try again!')
}
}
}
- const lockWallet = async(name)=>{
- let authData =JSON.parse(sessionStorage.getItem('auth'));
- if(!authData || authData.login===false || authData.name!==name){
- alert("Please unlock "+name+" first")
- return;
- }
+ const lockWallet = async (name) => {
+ const authData = JSON.parse(sessionStorage.getItem('auth'))
+ if (!authData || !authData.login || authData.name !== name) {
+ return alert(`Please unlock ${name} first`)
+ }
- try{
- let token = "Bearer "+authData.token
- const res = await fetch(`/api/v1/wallet/${name}/lock`,{
- method:"GET",
- headers:{
- 'Authorization':token
+ try {
+ const res = await fetch(`/api/v1/wallet/${name}/lock`, {
+ headers: {
+ 'Authorization': `Bearer ${authData.token}`
}
- });
- sessionStorage.setItem('auth',JSON.stringify({
- login:false,
- token:'',
- name:''
-
+ })
+ sessionStorage.setItem('auth', JSON.stringify({
+ login: false,
+ token: '',
+ name: ''
}))
- const data = await res.json();
- console.log(data);
- alert("locked wallet succesfully")
- }
- catch(e){
- alert("Error while locking.")
+ const data = await res.json()
+ console.log(data)
+ alert('Wallet locked succesfully')
+ } catch (e) {
+ console.error(e)
+ alert('Error while locking.')
+ }
+ }
+
+ const listWalletInfo = async (name) => {
+ const authData = JSON.parse(sessionStorage.getItem('auth'))
+ const res = await fetch(`/api/v1/wallet/${name}/display`, {
+ headers:{
+ 'Authorization': `Bearer ${authData.token}`
}
+ })
+ const { walletinfo } = await res.json()
+ const balance = walletinfo.total_balance
+ const mix_depths = walletinfo.accounts
+ const wallet_info = { balance }
+ wallet_info[mix_depths[0].account] = mix_depths[0].account_balance
+ wallet_info[mix_depths[1].account] = mix_depths[1].account_balance
+ wallet_info[mix_depths[2].account] = mix_depths[2].account_balance
+ wallet_info[mix_depths[3].account] = mix_depths[3].account_balance
+ wallet_info[mix_depths[4].account] = mix_depths[4].account_balance
+
+ return [walletinfo]
+ }
+
+ const displayWallet = async (name) => {
+ const authData = JSON.parse(sessionStorage.getItem('auth'))
+ if (!authData || !authData.login || authData.name !== name) {
+ return alert(`Please unlock ${name} first`)
}
- const listWalletInfo = async(name)=>{
- let authData =JSON.parse(sessionStorage.getItem('auth'));
- let token = "Bearer "+authData.token
- const res = await fetch(`/api/v1/wallet/${name}/display`,{
- method:"GET",
- headers:{
- 'Authorization':token
- }
- });
- const { walletinfo } = await res.json();
- const balance = walletinfo.total_balance;
- const mix_depths = walletinfo.accounts;
- const wallet_info = { balance }
- wallet_info[mix_depths[0].account] = mix_depths[0].account_balance
- wallet_info[mix_depths[1].account] = mix_depths[1].account_balance
- wallet_info[mix_depths[2].account] = mix_depths[2].account_balance
- wallet_info[mix_depths[3].account] = mix_depths[3].account_balance
- wallet_info[mix_depths[4].account] = mix_depths[4].account_balance
+ const res = await fetch(`/api/v1/wallet/${name}/display`, {
+ headers:{
+ 'Authorization': `Bearer ${authData.token}`
+ }
+ })
- return [walletinfo];
+ const { walletinfo } = await res.json()
+ const balance = walletinfo.total_balance
+ const mix_depths = walletinfo.accounts
+ const wallet_info={}
+ wallet_info['balance'] = balance
+ wallet_info[mix_depths[0].account] = mix_depths[0].account_balance
+ wallet_info[mix_depths[1].account] = mix_depths[1].account_balance
+ wallet_info[mix_depths[2].account] = mix_depths[2].account_balance
+ wallet_info[mix_depths[3].account] = mix_depths[3].account_balance
+ wallet_info[mix_depths[4].account] = mix_depths[4].account_balance
+ console.log(wallet_info)
+ return wallet_info
+ }
+
+ const createWallet = async (walletname, password) => {
+ const authData = JSON.parse(sessionStorage.getItem('auth'))
+ if (!authData || !authData.login) {
+ try {
+ const wallettype = 'sw'
+ const res = await fetch(`/api/v1/wallet/create`, {
+ method: 'POST',
+ headers: { 'Content-type': 'application/json', },
+ body: JSON.stringify({
+ password,
+ walletname,
+ wallettype
+ }),
+ })
+
+ const { seedphrase, token } = await res.json()
+ alert('Wallet created succesfully')
+ // TODO: figure out a safer way to show the seedphrase
+ alert(seedphrase)
+ sessionStorage.setItem('auth', JSON.stringify({ login: true, token, name: walletname }))
+ } catch (e) {
+ console.error(e)
+ //some other error occurs where wallet is not created
+ alert('Unexpected error! Please try again')
+ }
+ } else {
+ alert(`${authData.name} is in use! Please lock it first.`)
}
+ }
- const displayWallet = async(name)=>{
-
- let authData =JSON.parse(sessionStorage.getItem('auth'));
- if(authData.login===false || authData.name!==name){
- alert("Please unlock "+name+" first")
- return;
+ const makePayment = async (name, mixdepth, amount_sats,destination) => {
+ const authData = JSON.parse(sessionStorage.getItem('auth'))
+ if (authData && authData.login === true){
+ try {
+ const res = await fetch(`/api/v1/wallet/${name}/taker/direct-send`, {
+ method:'POST',
+ headers: {
+ 'Content-type': 'application/json',
+ 'Authorization': `Bearer ${authData.token}`
+ },
+ body: JSON.stringify({
+ mixdepth,
+ amount_sats,
+ destination
+ }),
+ })
+ const data = await res.json()
+ console.log(data)
+ alert('Payment Succesful!')
+ } catch(e) {
+ alert('Error while processing payment!')
}
- let token = "Bearer "+authData.token
- const res = await fetch(`/api/v1/wallet/${name}/display`,{
- method:"GET",
- headers:{
- 'Authorization':token
- }
- });
- const { walletinfo } = await res.json();
- const balance = walletinfo.total_balance;
- const mix_depths = walletinfo.accounts;
- const wallet_info={}
- wallet_info['balance'] = balance;
- wallet_info[mix_depths[0].account] = mix_depths[0].account_balance
- wallet_info[mix_depths[1].account] = mix_depths[1].account_balance
- wallet_info[mix_depths[2].account] = mix_depths[2].account_balance
- wallet_info[mix_depths[3].account] = mix_depths[3].account_balance
- wallet_info[mix_depths[4].account] = mix_depths[4].account_balance
- console.log(wallet_info)
- return wallet_info;
+ } else {
+ alert('please unlock wallet first')
}
+ }
- const createWallet = async(name,password)=>{
- const authData = JSON.parse(sessionStorage.getItem('auth'));
- if (!authData || !authData.login) {
- try {
- const res = await fetch(`/api/v1/wallet/create`,{
- method:'POST',
- headers: { 'Content-type': 'application/json', },
- body: JSON.stringify({ password, "walletname": name, "wallettype":"sw" }),
- })
-
- const { seedphrase, token } = await res.json();
- alert("Wallet created succesfully")
-
- //figure out a safer way to show the seedphrase
- alert(seedphrase)
- sessionStorage.setItem('auth', JSON.stringify({ login: true, token, name }))
- } catch (e) {
- console.error(e);
- //some other error occurs where wallet is not created
- alert('Unexpected error! Please try again')
- }
- } else{
- alert(`${authData.name} is in use! Please lock it first.`)
+ //route for frontend
+ const doCoinjoin = async (mixdepth, amount, counterparties, destination) => {
+ try {
+ const authData = JSON.parse(sessionStorage.getItem('auth'))
+ if (!authData || !authData.login || authData.name === '') {
+ return
}
- }
-
- const makePayment = async(name,mixdepth,amountSats,destination)=>{
- let authData =JSON.parse(sessionStorage.getItem('auth'));
- if(authData!=null && authData.login===true){
- try{
- let token = "Bearer "+authData.token
- const res = await fetch(`/api/v1/wallet/${name}/taker/direct-send`,{
- method:'POST',
- headers: {
- 'Content-type': 'application/json',
- 'Authorization':token
- },
- body: JSON.stringify({
- "mixdepth": mixdepth,
- "amount_sats": amountSats,
- "destination": destination
- }
-
- ),
- })
- const data = await res.json();
- console.log(data);
- alert("Payment Succesful!")
- }
- catch(e){
- alert("Error while processing payment!")
- }
-
-
- }
- else{
- alert("please unlock wallet first")
- }
- }
-
- //route for frontend
-
- const doCoinjoin = async(mixdepth,amount,counterparties,destination)=>{
- try{
- console.log("hellooo")
- let authData = JSON.parse(sessionStorage.getItem('auth'));
-
- if(!authData|| authData.login===false || authData.name===''){
- return;
- }
-
- let token = "Bearer "+authData.token;
- let name = authData.name;
- const res = await fetch(`/api/v1/wallet/${name}/taker/coinjoin`,{
- method:'POST',
- headers: {
- 'Content-type': 'application/json',
- 'Authorization':token
- },
- body: JSON.stringify({
-
- "mixdepth": mixdepth,
- "amount": amount,
- "counterparties": counterparties,
- "destination":destination
- }
-
- ),
- })
- const data = await res.json();
- console.log(data);
- alert("Coinjoin in Progress!")
-
- }
- catch(e){
- return;
- }
- }
-
- const startMakerService = async(txfee,cjfee_a,cjfee_r,ordertype,minsize)=>{
- let authData =JSON.parse(sessionStorage.getItem('auth'));
-
- if(!authData|| authData.login===false || authData.name===''){
- alert("Please unlock a wallet first")
- return;
- }
- let name = authData.name
- try{
- let token = "Bearer "+authData.token
- const res = await fetch(`/api/v1/wallet/${name}/maker/start`,{
- method:"POST",
- headers:{
- 'Authorization':token
+ const res = await fetch(`/api/v1/wallet/${authData.name}/taker/coinjoin`, {
+ method:'POST',
+ headers: {
+ 'Content-type': 'application/json',
+ 'Authorization': `Bearer ${authData.token}`
},
body: JSON.stringify({
- "txfee":txfee,
- "cjfee_a":cjfee_a,
- "cjfee_r":cjfee_r,
- "ordertype":ordertype,
- "minsize":minsize
- }
-
- ),
- });
-
- const data = await res.json();
- console.log(data);
- }
-
- catch(e){
- alert("Error while starting service!")
- }
+ mixdepth,
+ amount,
+ counterparties,
+ destination
+ }),
+ })
+ const data = await res.json()
+ console.log(data)
+ alert('Coinjoin in Progress!')
+ } catch (e) {
+ console.error(e)
+ }
+ }
+ const startMakerService = async (txfee, cjfee_a, cjfee_r, ordertype, minsize) => {
+ const authData =JSON.parse(sessionStorage.getItem('auth'))
+ if (!authData || !authData.login || authData.name === ''){
+ return alert('Please unlock a wallet first')
}
- const stopMakerService= async()=>{
- let authData =JSON.parse(sessionStorage.getItem('auth'));
- if(authData===null ||authData.login===false || authData.name===''){
- alert('Wallet needs to be unlocked')
- return;
- }
- try{
- let name = authData.name
- let token = "Bearer "+authData.token
- const res = await fetch(`/api/v1/wallet/${name}/maker/stop`,{
- method:"GET",
- headers:{
- 'Authorization':token
- },
+ try {
+ const res = await fetch(`/api/v1/wallet/${authData.name}/maker/start`, {
+ method: 'POST',
+ headers:{
+ 'Authorization': `Bearer ${authData.token}`
+ },
+ body: JSON.stringify({
+ txfee,
+ cjfee_a,
+ cjfee_r,
+ ordertype,
+ minsize
})
- const data = await res.json();
- console.log(data);
- alert("Maker service stopped")
- }
+ })
- catch(e){
- alert("Error while stopping service!")
- }
+ const data = await res.json()
+ console.log(data)
+ } catch (e) {
+ console.error(e)
+ alert('Error while starting service!')
+ }
+ }
+
+ const stopMakerService = async () => {
+ const authData = JSON.parse(sessionStorage.getItem('auth'))
+ if (!authData || !authData.login || authData.name === '') {
+ return alert('Wallet needs to be unlocked')
}
- const getUTXOs = async()=>{
- try{
- let authData =JSON.parse(sessionStorage.getItem('auth'));
- let token = "Bearer "+authData.token
- if(!authData|| authData.login===false || authData.name===''){
- return;
- }
- let name = authData.name;
- const res = await fetch(`/api/v1/wallet/${name}/utxos`, {
- headers: { 'Authorization':token }
- });
- const { utxos } = await res.json();
- return utxos;
- } catch(e){
- return console.error(e);
- }
+ try {
+ const res = await fetch(`/api/v1/wallet/${authData.name}/maker/stop`, {
+ headers:{
+ 'Authorization': `Bearer ${authData.token}`
+ },
+ })
+ const data = await res.json()
+ console.log(data)
+ alert('Maker service stopped')
+ } catch (e) {
+ console.error(e)
+ alert('Error while stopping service!')
}
+ }
+ const getUTXOs = async () => {
+ try {
+ const authData = JSON.parse(sessionStorage.getItem('auth'))
+ if (!authData || !authData.login || authData.name === '') {
+ return
+ }
+ const res = await fetch(`/api/v1/wallet/${authData.name}/utxos`, {
+ headers: {
+ 'Authorization': `Bearer ${authData.token}`
+ }
+ })
+ const { utxos } = await res.json()
+ return utxos
+ } catch (e) {
+ console.error(e)
+ }
+ }
return (
-
-
+
+