Skip to content

Commit

Permalink
Version 1 released
Browse files Browse the repository at this point in the history
  • Loading branch information
galaxyAbstractor committed Jun 17, 2011
1 parent 6983143 commit 3795217
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 129 deletions.
10 changes: 10 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,10 @@
Copyright (c) 2011, galaxyAbstractor http://pixomania.net
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 0 additions & 1 deletion chrome.manifest
@@ -1,6 +1,5 @@
overlay chrome://browser/content/browser.xul chrome://firecoin/content/firecoinOverlay.xul
overlay chrome://navigator/content/navigator.xul chrome://firecoin/content/firecoinOverlay.xul
overlay chrome://firecoin/content/donateDialogOverlay.xul
content firecoin chrome/content/firecoin/

skin firecoin classic/1.0 chrome/skin/classic/firecoin/
Expand Down
36 changes: 0 additions & 36 deletions chrome/content/firecoin/about.xul

This file was deleted.

8 changes: 0 additions & 8 deletions chrome/content/firecoin/contents.rdf
Expand Up @@ -20,13 +20,5 @@ xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
<RDF:li>chrome://httpproxifier/content/firecoinOverlay.xul</RDF:li>
</RDF:Seq>

<RDF:Description RDF:about="urn:mozilla:package:firecoin"
chrome:displayName="FireCoin v 1.0"
chrome:author="galaxyAbstractor"
chrome:authorURL="mailto:galaxyAbstractor@gmail.com"
chrome:name="FireCoin"
chrome:extension="true"
chrome:description="Easily donate BTC to siteowners">
</RDF:Description>

</RDF:RDF>
149 changes: 119 additions & 30 deletions chrome/content/firecoin/firecoinOverlay.js
Expand Up @@ -13,58 +13,117 @@
********************************************************************/

var FireCoin = {
/**
* Is called when the user presses the toolbar button
*/
onclick: function() {
// Get the BitCoin address
var address = FireCoin.getMetaContents("bitcoin",content.document.getElementsByTagName("meta"));
// Validate the address
FireCoin.sendRequest("validateaddress", [address], FireCoin.isValid);
FireCoin.sendRequest("validateaddress", [address], null, FireCoin.isValid);
},

isValid: function (json) {
/**
* Callback to see if a address is valid or not
* @param json the returned JSON from the server
* @param extra an extra argument, used to hold the address if it's from a selection
*/
isValid: function (json, extra) {
if(json.result.isvalid){
// The address is valid, open the dialog
FireCoin.sendRequest("getinfo", [], FireCoin.openDialog);
FireCoin.sendRequest("getinfo", [], extra, FireCoin.openDialog);
} else {
// A invalid address was provided
alert("This site didn't provide a valid bitcoin address");
}
},
// If the site provides an URL, we'll store it so it can be accessed later on
url:null,
/**
* Opens the donation dialog
* @param json the returned JSON from the server
* @param extra an extra argument, used to hold the address if it's from a selection
*/
openDialog: function(json, extra){
if(json.result != null){
var balance = json.result.balance;
// Extra was set which means that it was from a selection
if(extra != null) {
// The selected address
var address = extra;
// No message can be specified on this
var message = "No message specified";
// And no URL either
var url = "nope.avi";
} else {
// This was provided from meta
// Get the BitCoin address
var address = FireCoin.getMetaContents("bitcoin",content.document.getElementsByTagName("meta"));
// Get the message
var message = FireCoin.getMetaContents("bitcoinmsg",content.document.getElementsByTagName("meta"));
// Get a thanks URL
var url = FireCoin.getMetaContents("bitcointhanks",content.document.getElementsByTagName("meta"));
}


// Check if there was a message or not, if not, set the message to "No message specified"
url = url != "nope.avi" ? url : null;
// Set the url
FireCoin.url = url;

// Check if there was a message or not, if not, set the message to "No message specified"
message = message != "nope.avi" ? message : "No message specified";

var params = {inn:{firecoinDonatingAddress:address, firecoinMessageBox:message, firecoinBalanceValue:balance}, out:null};
window.openDialog("chrome://firecoin/content/donateDialogOverlay.xul", "Donate BitCoins",
"chrome,dialog=yes,modal=yes,centerscreen", params);

openDialog: function(json){
var balance = json.result.balance;
// Get the BitCoin address
var address = FireCoin.getMetaContents("bitcoin",content.document.getElementsByTagName("meta"));
// Get the message
var message = FireCoin.getMetaContents("bitcoinmsg",content.document.getElementsByTagName("meta"));
// Check if there was a message or not, if not, set the message to "No message specified"
message = message != "nope.avi" ? message : "No message specified";

var params = {inn:{firecoinDonatingAddress:address, firecoinMessageBox:message, firecoinBalanceValue:balance}, out:null};
window.openDialog("chrome://firecoin/content/donateDialogOverlay.xul", "Donate BitCoins",
"chrome,dialog=yes,modal=yes,centerscreen", params);

if (params.out) {
// Send the money to the site
FireCoin.sendRequest("sendfrom", ["", params.out.address, params.out.amount, 1,"FireCoin donation"], FireCoin.vaildTransaction);
if(params.out.toAuthorAmount != 0){
// The user chose to donate 5% to me, so send it to me
FireCoin.sendRequest("sendfrom", ["","msKEs37CnQWrvQmXuvcAQK8VFNf1JSpTrU", params.out.toAuthorAmount, 1,"FireCoin donation to Addon author - Thanks!"], FireCoin.vaildTransaction);
if (params.out) {
// Send the money to the site
FireCoin.sendRequest("sendfrom", ["", params.out.address, params.out.amount, 1,"FireCoin donation"], null, FireCoin.vaildTransaction);
if(params.out.toAuthorAmount != 0){
// The user chose to donate 5% to me, so send it to me
FireCoin.sendRequest("sendfrom", ["","1KHTs795SKBd2yBfdfpf4BxArEq5RGrNZo", params.out.toAuthorAmount, 1,"FireCoin donation to Addon author - Thanks!"], null, FireCoin.vaildTransaction);
}
} else {
// User clicked cancel. Typically, nothing is done here.
}
} else {
// User clicked cancel. Typically, nothing is done here.
}
} else {
alert(json.error.message);
}
},

vaildTransaction: function(json) {
/**
* Check if the transaction was valid
* @param json the returned JSON from the server
* @param extra an extra argument, used to hold the address if it's from a selection
*/
vaildTransaction: function(json, extra) {

// Check for a valid transaction
if(json.result.error == null){
if(json.result != null){
alert("Donation Sent!");
if(FireCoin.url != null){
gBrowser.addTab(FireCoin.url);
FireCoin.url = null;
}
} else {
alert(json.error.message);
}
},

/**
* This is what is called when the user presses the menu item in the right-click menu
*/
sendBitcoins: function(){
// Get the selected text
var address = document.commandDispatcher.focusedWindow.getSelection().toString();
FireCoin.sendRequest("validateaddress", [address], address, FireCoin.isValid);
},

/**
* Get the content of a metatag
* @param mn the name of the metatag <meta _name="mn"_ />
* @param m all the meta elements
*/
getMetaContents: function(mn,m){

Expand All @@ -81,9 +140,10 @@ var FireCoin = {
* Sends a JSON-RPC call to the bitcoin server
* @param m the method to call
* @param p the params to send the method
* @param extra an extra argument, used to hold the address if it's from a selection
* @return a JSON object containing the response from bitcoin
*/
sendRequest: function(m, p, callback) {
sendRequest: function(m, p, extra, callback) {
var http = new XMLHttpRequest();
var url = "http://127.0.0.1:8332/";
var params = {jsonrpc: "1.0",method: m, params: p, id: "jsonrpc"};
Expand All @@ -96,14 +156,43 @@ var FireCoin = {

http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
callback(JSON.parse(http.responseText));
// Check if this originated from a selection
if(extra != null){
// Send the result to the callback function
callback(JSON.parse(http.responseText), extra);
} else {
// Send the result to the callback function
callback(JSON.parse(http.responseText));
}
} else if(http.readyState == 4 && http.status == 500) {
// BitCoin gives a 500 status when an error occured
callback(JSON.parse(http.responseText), null);
} else if(http.readyState == 4 && http.status != 200) {
// Could not connect to the server
alert("Cannot talk to Bitcoin server or the server closed the connection (this happens if the transaction wasn't possible). Are you sure it is running as a server? \n please read: https://en.bitcoin.it/wiki/Running_Bitcoin#Bitcoin.conf_Configuration_File and add the server=1 option to the config file")
}
}
http.send(JSON.stringify(params));
}
}

/**
* We need to add an event listener for when the righ-click menu opens, so we can show our item only when
* text is selected
*/
function init() {
var contextMenu = document.getElementById("contentAreaContextMenu");
if (contextMenu)
contextMenu.addEventListener("popupshowing", sendBitcoinShowHide, false);
}

/**
* Toggle the menu item
*/
function sendBitcoinShowHide(event) {
var show = document.getElementById("sendBitcoinsMenuItem");
show.hidden = !gContextMenu.isTextSelected;
}

window.addEventListener("load", function () {

Expand Down
5 changes: 5 additions & 0 deletions chrome/content/firecoin/firecoinOverlay.xul
Expand Up @@ -14,4 +14,9 @@
onclick="FireCoin.onclick();"/>
</toolbarpalette>

<popup id="contentAreaContextMenu">
<menuitem id="sendBitcoinsMenuItem" label="Send BitCoins" oncommand="FireCoin.sendBitcoins();"
insertafter="context-selectall"/>
</popup>

</overlay>
21 changes: 0 additions & 21 deletions chrome/content/firecoin/firecoinSettingsDialog.xul

This file was deleted.

32 changes: 0 additions & 32 deletions chrome/content/firecoin/settingsDialog.js

This file was deleted.

Binary file modified chrome/skin/classic/firecoin/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified chrome/skin/classic/firecoin/iconb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions chrome/skin/classic/firecoin/style.css
Expand Up @@ -16,6 +16,7 @@ toolbar[iconsize="small"] .firecoin-button-inactive {

#mainDonateDialog,#mainSettingsDialog {
width:300px;
background-color: #ffffff;
background-image: -moz-linear-gradient(
center bottom,
rgb(232,232,232) 0%,
Expand Down
3 changes: 2 additions & 1 deletion install.rdf
Expand Up @@ -13,7 +13,7 @@
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>1.5</em:minVersion>
<em:minVersion>3.5</em:minVersion>
<em:maxVersion>4.0.*</em:maxVersion>
</Description>
</em:targetApplication>
Expand All @@ -23,5 +23,6 @@
<em:description>Easily donate BTC to siteowners</em:description>
<em:creator>galaxyAbstractor</em:creator>
<em:homepageURL>http://www.pixomania.net/</em:homepageURL>
<em:iconURL>chrome://firecoin/skin/icon.png</em:iconURL>
</Description>
</RDF>
19 changes: 19 additions & 0 deletions readme.rst
@@ -1,7 +1,26 @@
Makes it easier for you to donate Bitcoins to siteowners with firefox.

How To Use
=======
After install, make sure that the toolbarbutton is placed in a toolbar. Then, make sure you read this guide:
https://en.bitcoin.it/wiki/Running_Bitcoin#Bitcoin.conf_Configuration_File

You need to make sure BitCoin is running as a server by putting these options to your bitcoin.conf file:
server=1
rpcuser=*Desired username*
rpcpassword=*Desired secure password*

Some things to note:
The addon will not show any transaction fees, but these will be paid automatically by the JSON-RPC API. So if you send 0.01BTC to someone, be aware that
it might cost 0.02BTC total.

There is an option on every transaction to pay 5% extra to me. This will only be paid if you check the checkbox (disabled by default) "Donate 5% to addon author?", never anything else.

You will have to authenticate to the JSON-RPC API once every browser session for security, but you will have the option to save the credentials with the firefox login manager.

Changelog
=======
* 17 Jun, 2011: Version 1 released!
* 16 Jun, 2011: Almost done. Balance works. Transaction works. Need some final touches though. Currently runs on Testnet.
* 07 Jun, 2011: Started implementing JSON-RPC requests. Will need to make it wait for reply before using data.
* 02 Jun, 2011: Back with the settings button in the donation dialog. Added onchange on the amount scroller so the total and remaining is updated.
Expand Down

0 comments on commit 3795217

Please sign in to comment.