github.com/piotrnar/gocoin@v0.0.0-20240512203912-faa0448c5e96/client/www/templates/wallet.html (about)

     1  <script type="text/javascript" src="webui/jquery.min.js"></script>
     2  <script type="text/javascript" src="webui/qrcode.min.js"></script>
     3  <script type="text/javascript" src="webui/crypto.js"></script>
     4  <script type="text/javascript" src="webui/bech32.js"></script>
     5  <div id="light" class="white_content" style="height:auto;left:20%;width:60%">
     6  <table width="100%">
     7  <tr><td align="right"><img title="Close this popup" src="webui/close.png" class="hand" onclick="closepopup()">
     8  <tr><td align="center"><span class="qr_addr_label" id="qr_label"></span>
     9  <tr><td align="center"><input type="text" class="qr_addr_addr" id="qr_address" onclick="this.select()" readonly="readonly">
    10  <img src="webui/copy.png" title="Copy to clipboard" class="hand" onclick="qr_address.select();document.execCommand('copy')">
    11  <tr><td align="center">
    12  <div id="qrcode"></div>
    13  <tr><td align="right">&nbsp;
    14  </table>
    15  </div><div id="fade" class="black_overlay"></div>
    16  
    17  <script>
    18  /*WALLET_JS_VARS*/
    19  var qrcode = new QRCode(document.getElementById("qrcode"), {width:300, height:300})
    20  var address_type // initited from localStorage's wallet_address_type: 0 = pubkey, 1 - P2KH, 2 - P2TAP
    21  var p2sh_sw_mode // when set to true, use old (base58) address type
    22  
    23  function showqrcode(label, addr) {
    24  	qr_label.innerText = label
    25  	qr_address.value = addr
    26  	qr_address.style.width = (addr.length+1) + 'ch'
    27  	qrcode.makeCode(addr)
    28  
    29  	if (prvpos==null) {
    30  		fade.addEventListener('click', closepopup)
    31  		fade.style.cursor = 'pointer'
    32  		fade.title = 'Click here to close the popup'
    33  	}
    34  
    35  	prvpos = document.body.scrollTop
    36  	window.scrollTo(0,0)
    37  
    38  	light.style.display='block'
    39  	fade.style.display='block'
    40  	document.addEventListener("scroll", noscroll)
    41  }
    42  function showtheqr(img) {
    43  	console.log('jade', img, "lab:", img["qr_label"], "  ad:", img["qr_addr"])
    44  	showqrcode(img.qr_label, img.qr_addr)
    45  }
    46  </script>
    47  
    48  <style>
    49  td.addr_long {
    50  	font-size:9px;
    51  	font-weight:bold;
    52  	white-space: nowrap;
    53  }
    54  td.addr_pubkey {
    55  	font-size:8px;
    56  	font-weight:bold;
    57  	white-space:nowrap;
    58  	font-family: monospace;
    59  }
    60  td.addr_norm {
    61  	font-weight:bold;
    62  	white-space: nowrap;
    63  }
    64  td.addr_label {
    65  	//white-space: nowrap;
    66  }
    67  td.balbtc {
    68  	text-align: right;
    69  	font-family: monospace;
    70  	font-size: 110%;
    71  	width: 150px;
    72  }
    73  .p2sh {
    74  	color:brown;
    75  }
    76  .native {
    77  	color:darkgreen;
    78  }
    79  .p2tap {
    80  	color:blue;
    81  }
    82  .segwitaddr {
    83  	font-style:italic;
    84  	font-size: 90%;
    85  }
    86  .pubkey {
    87  	color:darkblue;
    88  }
    89  td.segwitaddr {
    90  	text-align: left;
    91  	white-space: nowrap;
    92  }
    93  td.outcnt {
    94  	text-align: right;
    95  	white-space: nowrap;
    96  }
    97  </style>
    98  <script>
    99  var edit_in_progress = false
   100  var wallet;
   101  var fetching_balance_in_progress = null
   102  function switchwallet_button_click_browser() {
   103  	if (edit_in_progress) {
   104  		close_editor()
   105  	}
   106  	cur_wallet_name.innerText = this.value
   107  	switch_to_webwallet(this.value)
   108  }
   109  
   110  function remove_comment_from_label(lab) {
   111  	var i = lab.indexOf('#')
   112  	if (i==-1)  return lab
   113  	return lab.substr(0, i)
   114  }
   115  
   116  function add_address_and_icons(td, adr, lab) {
   117  	var qrc = document.createElement("img")
   118  	qrc.src = "webui/qrcode.png"
   119  	qrc.className = 'hand'
   120  	qrc["qr_addr"] = adr
   121  	qrc["qr_label"] = lab
   122  	qrc.onclick = function(){showtheqr(this)}
   123  	td.appendChild(qrc)
   124  	td.appendChild(document.createTextNode('\u00A0' + adr + '\u00A0'))
   125  
   126  	// add copy icon
   127  	img = document.createElement("img")
   128  	img["text2copy"] = adr
   129  	img.style.verticalAlign = "bottom"
   130  	img.src = 'webui/copy.png'
   131  	img.className = "hand"
   132  	img.title = "Copy to clipboard"
   133  	img.addEventListener("click", function(e) {
   134  		autocopy.style.display = 'inline'
   135  		autocopy.value = e.srcElement["text2copy"]
   136  		autocopy.select()
   137  		document.execCommand('copy')
   138  		autocopy.style.display = 'none'
   139  	})
   140  	td.appendChild(img)
   141  }
   142  
   143  function fetch_wallet_balance(name) {
   144  	if (fetching_balance_in_progress!=null) {
   145  		fetching_balance_in_progress.abort()
   146  		fetching_balance_in_progress = null
   147  	}
   148  	if (name==null) {
   149  		name = localStorage.getItem("gocoinWalletSelected")
   150  	}
   151  
   152  	wallet = parse_wallet(localStorage.getItem("gocoinWal_"+name))
   153  	var wallet_addr = new Array()
   154  
   155  	for (var i=0; i<wallet.length; i++) {
   156  		wallet_addr.push(wallet[i].addr)
   157  	}
   158  
   159  	while (walltab.rows.length>1) {
   160  		walltab.deleteRow(1)
   161  	}
   162  
   163  	var aj = ajax()
   164  
   165  	var mempool = show_mempol.checked
   166  
   167  	aj.onerror=function() {
   168  		loading_icon.style.display = 'none'
   169  		fetching_balance_in_progress = null
   170  		console.log("onerror")
   171  	}
   172  
   173  	aj.onload=function() {
   174  		loading_icon.style.display = 'none'
   175  		fetching_balance_in_progress = null
   176  		try {
   177  			var totbtc = 0,  totvalin = 0,  totvalout = 0
   178  			var totouts = 0,  totcntin = 0,  totcntout = 0
   179  			bal = JSON.parse(aj.responseText)
   180  			var idxx = 0
   181  			for (var i in wallet_addr) {
   182  				var rec = bal[wallet_addr[i]]
   183  				var rec_error = false
   184  
   185  				try {
   186  					if (typeof(rec)==undefined || rec==null || (rec.OutCnt+rec.PendingCnt)==0 && wallet[i].virgin) {
   187  						rec_error = true
   188  					}
   189  				} catch(e) {
   190  					console.log(e)
   191  					rec_error = true
   192  				}
   193  				if (rec_error) {
   194  					continue
   195  				}
   196  
   197  				var td, row = walltab.insertRow(-1)
   198  				row.className = "hov"
   199  				row.id = 'walrow'+idxx
   200  
   201  				row["btc_addr"] = wallet_addr[i]
   202  				row["addr_label"] = wallet[i].label
   203  
   204  				td = row.insertCell(-1)
   205  				var adr_string = wallet_addr[i] 
   206  				var pubkey_mode = valid_pubkey(adr_string);
   207  				if (pubkey_mode && address_type!=0) {
   208  					var pkb = hex2array(adr_string)
   209  					if (address_type==1) {
   210  						adr_string = pubkey_to_p2kh(pkb)
   211  					} else { // address_type==2
   212  						adr_string = sw_encode(testnet?"tb":"bc", 1, pkb.slice(1, 33))
   213  					}
   214  				}
   215  				if (pubkey_mode && address_type==0) {
   216  					td.className = "addr_pubkey pubkey"
   217  				} else {
   218  					td.className = (adr_string.length>45) ? "addr_long" : "addr_norm"
   219  					if (pubkey_mode)  td.classList.add('pubkey')
   220  				}
   221  
   222  				add_address_and_icons(td, adr_string, wallet[i].label)
   223  				td = row.insertCell(-1)
   224  				td.className = "hand addr_label"
   225  				td.innerText = remove_comment_from_label(wallet[i].label)
   226  				if (wallet[i].virgin) {
   227  					td.classList.add("i")
   228  				}
   229  				//? ' ***' : '' )
   230  				td["row_idx"] = idxx
   231  				td.addEventListener('click', edit_label)
   232  
   233  				td = row.insertCell(-1)
   234  				td.className = "balbtc"
   235  				if (rec.OutCnt>0) {
   236  					td.innerText = val2str_pad(rec.Value,true)
   237  				}
   238  				if (mempool) {
   239  					if (rec.PendingValue>0) {
   240  						td.innerHTML += '<br><span class="unspent_plus">+' + val2str_pad(rec.PendingValue,true) + '</span>'
   241  					}
   242  					if (rec.SpendingValue>0) {
   243  						td.innerHTML += '<br><span class="unspent_minus">-' + val2str_pad(rec.SpendingValue,true) + '</span>'
   244  					}
   245  				}
   246  
   247  				if (mempool) {
   248  					if (rec.PendingCnt>0) {
   249  						td.innerHTML += '<br><span class="unspent_plus">+' + rec.PendingCnt + '</span>'
   250  					}
   251  					if (rec.SpendingCnt>0) {
   252  						td.innerHTML += '<br><span class="unspent_minus">-' + rec.SpendingCnt + '</span>'
   253  					}
   254  				}
   255  
   256  				// empty column,  for space
   257  				row.insertCell(-1)
   258  
   259  				td = row.insertCell(-1)
   260  
   261  				td.className = 'segwitaddr'
   262  				if (p2sh_sw_mode) {
   263  					td.classList.add('p2sh')
   264  					if (segwit_active && rec.SegWitAddr!='') {
   265  						add_address_and_icons(td, rec.SegWitAddr, wallet[i].label)
   266  					}
   267  				} else {
   268  					td.classList.add('native')
   269  					if (segwit_active && rec.SegWitNativeAddr!='') {
   270  						add_address_and_icons(td, rec.SegWitNativeAddr, wallet[i].label)
   271  					}
   272  				}
   273  
   274  				td = row.insertCell(-1)
   275  				td.className = 'outcnt'
   276  				if (rec.OutCnt>0) {
   277  					td.innerText = rec.OutCnt
   278  					if (rec.SegWitCnt>0)
   279  						td.innerHTML += ' <span class="segwitaddr p2sh">+' + rec.SegWitCnt + '</span>'
   280  
   281  					if (rec.SegWitNativeCnt>0) {
   282  						td.innerHTML += ' <span class="segwitaddr native">+' + rec.SegWitNativeCnt + '</span>'
   283  					}
   284  					
   285  					if (rec.SegWitTapCnt>0) {
   286  						td.innerHTML += ' <span class="segwitaddr p2tap">+' + rec.SegWitTapCnt + '</span>'
   287  					}
   288  					totouts += rec.OutCnt
   289  				} else {
   290  					td.innerHTML = '<a href="javascript:setunused('+idxx+')"><img src="webui/del.png"></a>'
   291  				}
   292  
   293  				totvalin += rec.PendingValue
   294  				totvalout += rec.SpendingValue
   295  				totcntin += rec.PendingCnt
   296  				totcntout += rec.SpendingCnt
   297  
   298  				totbtc += rec.Value
   299  				idxx++
   300  			}
   301  			total_btc.innerText = val2str(totbtc)
   302  			unspent_outs.innerText = totouts
   303  
   304  			if (mempool && totcntin>0) {
   305  				arriving_btc.innerText = val2str(totvalin)
   306  				arriving_cnt.innerText = totcntin
   307  				arriving_info_id.style.display = 'table-cell'
   308  			} else {
   309  				arriving_info_id.style.display = 'none'
   310  			}
   311  
   312  			if (mempool && totcntout>0) {
   313  				spending_btc.innerText = val2str(totvalout)
   314  				spending_cnt.innerText = totcntout
   315  				spending_info_id.style.display = 'table-cell'
   316  			} else {
   317  				spending_info_id.style.display = 'none'
   318  			}
   319  		} catch (e) {
   320  			console.log(e)
   321  		}
   322  	}
   323  
   324  	loading_icon.style.display = 'inline'
   325  	fetching_balance_in_progress = aj
   326  	aj.open("POST", "balance.json?summary" + (mempool ? "&mempool" : ""), true)
   327  	aj.send(JSON.stringify(wallet_addr))
   328  }
   329  
   330  function switch_to_webwallet(name) {
   331  	localStorage.setItem("gocoinWalletSelected", name)
   332  	for (var i in qswal.options) {
   333  		if (qswal.options[i].text==name) {
   334  			qswal.selectedIndex = i
   335  			enable_move_buttons()
   336  			break
   337  		}
   338  	}
   339  	fetch_wallet_balance(name)
   340  }
   341  
   342  function enable_move_buttons() {
   343  	if (qswal.options.length>=2) {
   344  		move_left.disabled = qswal.selectedIndex < 1
   345  		move_right.disabled = qswal.selectedIndex > qswal.options.length-2
   346  	} else {
   347  		move_left.disabled = move_right.disabled = true
   348  	}
   349  }
   350  
   351  function move_wallet_left() {
   352  	if (qswal.options.length<2) {
   353  		return
   354  	}
   355  	if (qswal.selectedIndex<1) {
   356  		return
   357  	}
   358  	var i, names = ''
   359  	for (i=0; i<qswal.selectedIndex-1; i++) {
   360  		names += '|' + qswal.options[i].text
   361  	}
   362  	names += '|' + qswal.options[qswal.selectedIndex].text
   363  	names += '|' + qswal.options[qswal.selectedIndex-1].text
   364  	for (i=qswal.selectedIndex+1; i<qswal.options.length; i++) {
   365  		names += '|' + qswal.options[i].text
   366  	}
   367  	localStorage.setItem("gocoinWallets", names.substr(1))
   368  	location.reload()
   369  }
   370  
   371  function move_wallet_right() {
   372  	if (qswal.options.length<2) {
   373  		return
   374  	}
   375  	if (qswal.selectedIndex > qswal.options.length-2) {
   376  		return
   377  	}
   378  	var i, names = ''
   379  	for (i=0; i<qswal.selectedIndex; i++) {
   380  		names += '|' + qswal.options[i].text
   381  	}
   382  	names += '|' + qswal.options[qswal.selectedIndex+1].text
   383  	names += '|' + qswal.options[qswal.selectedIndex].text
   384  	for (i=qswal.selectedIndex+2; i<qswal.options.length; i++) {
   385  		names += '|' + qswal.options[i].text
   386  	}
   387  	localStorage.setItem("gocoinWallets", names.substr(1))
   388  	location.reload()
   389  }
   390  
   391  function edit_wallet() {
   392  	try {
   393  		var name = qswal.options[qswal.selectedIndex].text
   394  		walletfname.value = name
   395  		walletdata.value = localStorage.getItem("gocoinWal_"+name)
   396  	} catch (e) {
   397  		walletfname.value = "DEFAULT"
   398  		walletdata.value = "# New empty wallet"
   399  	}
   400  	showwal.style.display='none'
   401  	formwal.style.display='block'
   402  	edit_in_progress = true
   403  }
   404  function setunused(idx) {
   405  	var tr = document.getElementById('walrow'+idx)
   406  	var adr = tr["btc_addr"] //tr.cells[0].innerText
   407  
   408  	var name = qswal.options[qswal.selectedIndex].text
   409  	if (confirm("Remove " + adr + " from the current browser wallet?")) {
   410  		lines = localStorage.getItem("gocoinWal_"+name).split('\n')
   411  		var s = ''
   412  		for (var i=0; i<lines.length; i++) {
   413  			if (lines[i].indexOf(adr)==-1) {
   414  				s += lines[i]
   415  				if (i+1<lines.length)  s += '\n'
   416  			}
   417  		}
   418  		localStorage.setItem("gocoinWal_"+name, s)
   419  		switch_to_webwallet(name)
   420  	}
   421  }
   422  function edit_label() {
   423  	var idx = this.row_idx
   424  	var tr = document.getElementById('walrow'+idx)
   425  	var adr = tr["btc_addr"] //tr.cells[0].innerText
   426  	var lab = tr["addr_label"]
   427  
   428  	var newlab = prompt("Edit label in the current browser wallet for:\n" + adr, lab)
   429  	if (newlab) {
   430  		var name = qswal.options[qswal.selectedIndex].text
   431  		lines = localStorage.getItem("gocoinWal_"+name).split('\n')
   432  		var s = ''
   433  		for (var i=0; ; ) {
   434  			var found = lines[i].indexOf(adr)
   435  
   436  			if (found==-1) {
   437  				s += lines[i]
   438  			} else {
   439  				s += lines[i].substr(found, adr.length) + ' ' + newlab
   440  			}
   441  			if (++i>=lines.length) break;
   442  			s += '\n'
   443  		}
   444  		localStorage.setItem("gocoinWal_"+name, s)
   445  		switch_to_webwallet(name)
   446  	}
   447  }
   448  function close_editor() {
   449  	showwal.style.display='block'
   450  	formwal.style.display='none'
   451  	edit_in_progress = false
   452  }
   453  function save_web_wallet() {
   454  	var name = walletfname.value
   455  	var curr_wallets = localStorage.getItem("gocoinWallets")
   456  	var names = curr_wallets.split('|')
   457  	var i;
   458  	console.log("saving", name)
   459  	for (i=0; i<names.length; i++) {
   460  		if (names[i]==name) {
   461  			console.log("foud at", i)
   462  			break
   463  		}
   464  	}
   465  	if (i==names.length) {
   466  		console.log("not found")
   467  		localStorage.setItem("gocoinWallets", curr_wallets+"|"+name)
   468  	}
   469  
   470  	localStorage.setItem("gocoinWal_"+name, walletdata.value)
   471  	close_editor()
   472  
   473  	localStorage.setItem("gocoinWalletSelected", name)
   474  	location.reload()
   475  }
   476  
   477  function delete_wallet() {
   478  	var name = qswal.options[qswal.selectedIndex].text
   479  	if (confirm("Delete wallet "+name+" from the browser?")) {
   480  		localStorage.removeItem("gocoinWal_"+name)
   481  		location.reload()
   482  	}
   483  }
   484  
   485  function create_switch_buttons() {
   486  	try {
   487  		var wal_name = qswal.options[qswal.selectedIndex].text
   488  		cur_wallet_name.innerText = wal_name
   489  
   490  		for (var i=0; i<qswal.options.length; i++) {
   491  			var na = qswal.options[i].value
   492  			var but = document.createElement("input")
   493  			but.type = "button"
   494  			but.value = na
   495  			but.style.margin = 5
   496  			but.onclick = switchwallet_button_click_browser
   497  			browser_wallets.appendChild(but)
   498  		}
   499  	} catch (e) {
   500  		cur_wallet_name.innerText = 'none (edit to create)'
   501  		delwal_button.disabled = true
   502  	}
   503  }
   504  document.addEventListener('DOMContentLoaded', function() {
   505  	create_switch_buttons()
   506  	enable_move_buttons()
   507  })
   508  
   509  
   510  function allow_name_change_clicked() {
   511  	walletfname.disabled = !allow_name_change.checked
   512  	if (allow_name_change.checked) {
   513  		walletfname.select()
   514  		walletfname.focus()
   515  	}
   516  }
   517  
   518  function get_balance_zip() {
   519  	var form = document.createElement("form")
   520  	form.setAttribute("method", "post")
   521  	form.setAttribute("action", "balance.zip")
   522  
   523  	var inp = document.createElement("input")
   524  	inp.type = "hidden"
   525  	inp.name = "addrcnt"
   526  	inp.value = wallet.length
   527  	form.appendChild(inp)
   528  
   529  	for (var i in wallet) {
   530  		inp = document.createElement("input")
   531  		inp.type = "hidden"
   532  		inp.name = "addr"+i
   533  		inp.value = wallet[i].addr
   534  		form.appendChild(inp)
   535  
   536  		inp = document.createElement("input")
   537  		inp.type = "hidden"
   538  		inp.name = "label"+i
   539  		inp.value = wallet[i].label
   540  		form.appendChild(inp)
   541  	}
   542  
   543  	document.body.appendChild(form)
   544  	form.submit()
   545  }
   546  
   547  function p2sh_sw_mode_changed() {
   548  	p2sh_sw_mode_str.innerText = p2sh_sw_mode ? "P2SH-P2WPKH" : "P2WPKH"
   549  }
   550  
   551  function switch_segwit_p2sh() {
   552  	p2sh_sw_mode = !p2sh_sw_mode
   553  	p2sh_sw_mode_changed()
   554  	localStorage.setItem("wallet_segwit_p2sh", p2sh_sw_mode)
   555  	fetch_wallet_balance(null)
   556  }
   557  
   558  function update_address_type() {
   559  	var tx2set = 'WTF'
   560  	switch (address_type) {
   561  		case 0: tx2set='Public Key'; break
   562  		case 1: tx2set='Old / P2KH'; break
   563  		case 2: tx2set='New / P2TAP'; break
   564  	}
   565  	at_type_str.innerText = tx2set
   566  }
   567  
   568  function at_click() {
   569  	if (++address_type==3) {
   570  		address_type = 0
   571  	}
   572  	localStorage.setItem("wallet_address_type", address_type)
   573  	update_address_type()
   574  	fetch_wallet_balance(null)
   575  }
   576  
   577  </script>
   578  <select id="qswal" style="display:none"></select>
   579  
   580  <h2>Your wallets
   581  <span style="float:right" >
   582  <input id="move_left" type="button" value="Move left" onclick="move_wallet_left()">
   583  <input id="move_right" type="button" value="Move right"  onclick="move_wallet_right()">
   584  <input type="button" id="delwal_button" value="Delete This Wallet" onclick="delete_wallet()">
   585  </span>
   586  </h2>
   587  <div id="browser_wallets">Available wallets: </div>
   588  <hr>
   589  
   590  <div id="showwal">
   591  <h2>Current wallet: <span id="cur_wallet_name"></span> <img title="Loading balance" id="loading_icon" src="webui/loading.gif" style="display:none">
   592  
   593  <span style="float:right">
   594  <input type="button" value="Edit" onclick="edit_wallet()">
   595  </span>
   596  </h2>
   597  
   598  <input type="text" id="autocopy" style="display:none;font-size:1px;float:right;width:10px;height:4px">
   599  Balance: <b id="total_btc"></b> BTC in <b id="unspent_outs"></b> outputs (<a href="javascript:get_balance_zip()">balance.zip</a>)
   600  &nbsp;&bull;&nbsp;
   601  <span class="hand" onclick="show_mempol.click()">
   602  	<input type="checkbox" id="show_mempol" onchange="show_mempool_clicked()" onclick="event.stopPropagation()"> Show unconfirmed
   603  </span>
   604  <i id="wallet_min_warning" style="color:purple;float:right;display:none" title="Modify MinValue in gocoin.conf to change it">
   605  <img src="webui/warning.png" style="vertical-align:middle">
   606  Only accounting outputs with at least <b id="min_val_btc"></b> BTC</i>
   607  <br><br>
   608  
   609  <table class="wal bord" id="walltab">
   610  <tr>
   611  <th width="360" align="left" class="hand" onclick="at_click()" style="padding-left:23px"
   612  	title="Click to change address type displayed in this column (needs raw-pubkey wallet)">
   613  	Base Address (<span id="at_type_str"></span>)
   614  <th align="left" width="100">Label
   615  <th align="right">Balance&nbsp;BTC
   616  <th width="50">
   617  <th align="left" width="330" class="hand" onclick="switch_segwit_p2sh()" style="padding-left:23px"
   618  	title="Click to change address type displayed in this column (for segwit version 0)">
   619  	Version 0 Segwit Address (<span id="p2sh_sw_mode_str"></span>)
   620  <th width="40">Outs
   621  </table>
   622  <table width="100%"><tr>
   623  <td width="50%" id="arriving_info_id" style="display:none" class="unspent_plus">Unconfirmed arriving: <b id="arriving_btc"></b> BTC in <b id="arriving_cnt"></b> outputs</td>
   624  <td width="50%" id="spending_info_id" style="display:none" class="unspent_minus">Unconfirmed spending: <b id="spending_btc"></b> BTC from <b id="spending_cnt"></b> outputs</td>
   625  </tr></table>
   626  
   627  <br>
   628  </div>
   629  
   630  <div id="formwal" style="display:none">
   631  <h2>Edit wallet
   632  <input style="float:right" type="button" value="Cancel" onclick="close_editor()">
   633  </h2>
   634  <table width="100%">
   635  <form method="post" id="wallet_edit_form" action="cfg" onsubmit="return false;">
   636  <tr>
   637  	<td align="left">
   638  		<input type="checkbox" id="allow_name_change" onchange="allow_name_change_clicked()">
   639  		Choose new name: <input type="text" disabled="true" id="walletfname" name="walletfname" value="" class="mono">
   640  	<td align="right">
   641  		<input type="button" value="Save Wallet" onclick="save_web_wallet()">
   642  <tr><td colspan="2">
   643  	<textarea name="walletdata" id="walletdata" style="width:100%" rows="25">{WALLET_DATA}</textarea><br>
   644  	<i>
   645  	Only list your wallet's <b>public addresses</b> here!
   646  	Empty lines and lines starting with <b>#</b> are ignored.<br>
   647  	Make a line of <b># SegWit</b> or <b># SegWit P2SH</b> or <b># SegWit Tap</b>
   648  	 to auto-translate change addresses to SegWit format in <a href="snd">MakeTx</a> tab.
   649  	</i>
   650  </form>
   651  </table>
   652  </div>
   653  
   654  
   655  <form id="form_b" method="post" action="cfg" style="margin:0px;text-align:center" onsubmit="return confirm('Disable wallet functionality')">
   656  <input type="hidden" name="wallet" value="off">
   657  <input type="hidden" name="page" value="/wal">
   658  <input type="submit" value="Disable wallet functionality for lower memory usage and faster block processing">
   659  </form>
   660  
   661  
   662  <script>
   663  if (typeof(localStorage.gocoinWallets)=="string") {
   664  	build_wallet_list()
   665  } else {
   666  	localStorage.gocoinWallets = ""
   667  }
   668  
   669  function show_mempool_clicked() {
   670  	localStorage.setItem("wallet_show_mempool", show_mempol.checked)
   671  	quick_switch_wallet()
   672  }
   673  
   674  // reaload page on new block
   675  var _lblo = 0
   676  blno.addEventListener("lastblock", function(e) {
   677  	if (!e.block.WalletON) {
   678  		location.reload()
   679  		return
   680  	}
   681  	if (_lblo==0) {
   682  		_lblo = e.block.Height
   683  		if (e.block.MinValue>0) {
   684  			min_val_btc.innerText = val2str(e.block.MinValue)
   685  			wallet_min_warning.style.display = 'block'
   686  		}
   687  	} else if (e.block.Height!=_lblo) {
   688  		_lblo = e.block.Height
   689  		if (!edit_in_progress) {
   690  			fetch_wallet_balance(null)
   691  		}
   692  	}
   693  })
   694  qswal.addEventListener("loadwallet", function(e) {
   695  	if (edit_in_progress) {
   696  		close_editor()
   697  	}
   698  	fetch_wallet_balance(e.name)
   699  })
   700  document.addEventListener('DOMContentLoaded', function() {
   701  	show_mempol.checked = localStorage.getItem("wallet_show_mempool") == 'true'
   702  	quick_switch_wallet() // this is to force loading wallet after loading
   703  	window.onkeyup = function (event) {
   704  		if(event.keyCode == 27)  closepopup()
   705  	}
   706  })
   707  
   708  p2sh_sw_mode = (localStorage.getItem("wallet_segwit_p2sh")==="true")
   709  p2sh_sw_mode_changed()
   710  
   711  address_type = parseInt(localStorage.getItem("wallet_address_type")) || 0
   712  update_address_type()
   713  
   714  if (!server_mode) {
   715  	form_b.style.display = 'block'
   716  }
   717  </script>