Skip to content

Commit

Permalink
Added donations
Browse files Browse the repository at this point in the history
  • Loading branch information
gertjaap committed Dec 10, 2018
1 parent 9016608 commit e69b9fa
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 79 deletions.
33 changes: 32 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Config struct {
RpcPassword string
Port uint16
Cors bool
Donate bool
}

func InitConfig() (*Config, error) {
Expand All @@ -28,11 +29,12 @@ func InitConfig() (*Config, error) {
func (c *Config) DefaultConfig() string {
defaultConfig := ""
defaultConfig += "network=testnet\n"
defaultConfig += "rpchost=localhost:15889\n"
defaultConfig += "rpchost=localhost:15888\n"
defaultConfig += "rpcuser=vtc\n"
defaultConfig += "rpcpassword=vtc\n"
defaultConfig += "port=27888\n"
defaultConfig += "cors=false\n"
defaultConfig += "donate=true\n"

return defaultConfig
}
Expand Down Expand Up @@ -64,6 +66,7 @@ func (c *Config) Read() error {
c.RpcPassword = cfg.Section("").Key("rpcpassword").String()
c.Port = uint16(cfg.Section("").Key("port").MustInt(27888))
c.Cors = cfg.Section("").Key("cors").MustBool(false)
c.Donate = cfg.Section("").Key("donate").MustBool(true)

return nil
}
Expand All @@ -82,6 +85,34 @@ func (c *Config) Initialize() error {
return c.CheckValid()
}

func (c *Config) EnableDonations() error {
c.Donate = true
cfg, err := ini.Load("vertcoin-openassets.conf")
if err != nil {
return err
}
cfg.Section("").Key("donate").SetValue("true")
err = cfg.SaveTo("vertcoin-openassets.conf")
if err != nil {
return err
}
return nil
}

func (c *Config) DisableDonations() error {
c.Donate = false
cfg, err := ini.Load("vertcoin-openassets.conf")
if err != nil {
return err
}
cfg.Section("").Key("donate").SetValue("false")
err = cfg.SaveTo("vertcoin-openassets.conf")
if err != nil {
return err
}
return nil
}

func (c *Config) CheckValid() error {
if c.Network == nil {
return fmt.Errorf("Network is not configured")
Expand Down
5 changes: 5 additions & 0 deletions config/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Network struct {
AssetAddressPrefix string
StartHash *chainhash.Hash
Name string
DonationAddress string
}

func GetNetwork(name string) *Network {
Expand All @@ -18,18 +19,22 @@ func GetNetwork(name string) *Network {
n.AssetAddressPrefix = "rvtca"
n.StartHash = &chainhash.Hash{}
n.Name = "REGTEST"
n.DonationAddress = "rvtc1q9tyr0dmqfphm7hg9vaeh0yw9lttpfc436vgcwy"
return n
} else if name == "testnet" {
n.VtcAddressPrefix = "tvtc"
n.AssetAddressPrefix = "tvtca"
n.StartHash, _ = chainhash.NewHashFromStr("cecdde91a6e53ead307ef615b78b6f47a0f5e4d3046e1a0df7501507ed28ffb6")
n.Name = "TESTNET"
n.DonationAddress = "tvtc1qkh87j422ntkwd5pg8pkg9edgav8k4rfs757hln"
return n
} else if name == "mainnet" {
n.VtcAddressPrefix = "vtc"
n.AssetAddressPrefix = "vtca"
n.StartHash, _ = chainhash.NewHashFromStr("c9a400541bc579e1121c1990d94b96f4eef5bdc922fd5b763dbb4789cd28ce6d")
n.Name = "MAINNET"
n.DonationAddress = "vtc1qddgd7hg5hy8xl3a0fvlqc2zw0xr9fs69838u6w"

return n
}

Expand Down
216 changes: 139 additions & 77 deletions react-ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import QRCode from 'qrcode.react';
class App extends Component {
constructor(props) {
super(props);
this.baseUrl = "http://localhost:27888/api/"
this.baseUrl = "/api/"
if(window.location.host == "localhost:3000") { // When running in REACT Dev
this.baseUrl = "http://localhost:27888/api/"
}
this.toggle = this.toggle.bind(this);
this.state = {
isOpen: false,
Expand All @@ -42,7 +45,8 @@ class App extends Component {
sendTo:"",
issueTicker: "",
issueDecimals: 8,
issueSupply: 0
issueSupply: 0,
donating: true,
};
this.refreshAssets = this.refreshAssets.bind(this);
this.refreshBalance = this.refreshBalance.bind(this);
Expand All @@ -51,7 +55,34 @@ class App extends Component {
this.refreshNetwork = this.refreshNetwork.bind(this);
this.refreshAddresses = this.refreshAddresses.bind(this);
this.refresh = this.refresh.bind(this);
this.toggleDonations = this.toggleDonations.bind(this);
this.refreshDonations = this.refreshDonations.bind(this);
}

toggleDonations() {
if(this.state.donating === true) {
fetch(this.baseUrl + "donations/disable")
.then((res) => { return res.json(); })
.then((data) => {
this.setState({donating: false});
})
} else {
fetch(this.baseUrl + "donations/enable")
.then((res) => { return res.json(); })
.then((data) => {
this.setState({donating: true});
})
}
}

refreshDonations() {
fetch(this.baseUrl + "donations/status")
.then((res) => { return res.json(); })
.then((data) => {
this.setState({donating: data});
})
}

sendAsset(asset, amount, to) {
var realAmount = new BigNumber(amount).times(new BigNumber("1e" + asset.Decimals.toString())).toNumber();
fetch(this.baseUrl + "transferAsset", {
Expand Down Expand Up @@ -83,11 +114,9 @@ class App extends Component {
'Content-Type': 'application/json'
},
body: JSON.stringify({

"Ticker": ticker,
"TotalSupply" : realAmount,
"Decimals": decimals

"Decimals": parseInt(decimals)
})
})
.then((res) => { return res.json(); })
Expand Down Expand Up @@ -130,6 +159,7 @@ class App extends Component {

componentDidMount() {
this.refreshNetwork();
this.refreshDonations();
this.refresh();
this.refreshInterval = setInterval(this.refresh, 5000);
}
Expand All @@ -142,6 +172,7 @@ class App extends Component {
this.refreshBalance();
this.refreshAddresses();
this.refreshAssets();

}

toggle() {
Expand Down Expand Up @@ -217,77 +248,105 @@ class App extends Component {
</Container>);
break;
case 'send':
mainPage = (<Container>
<Row>
<Col>
<Form>
<FormGroup row>
<Label for="amount" sm={2}>Amount:</Label>

<Col sm={10}>
<InputGroup>
<Input type="number" name="amount" id="amount" placeholder="Enter amount" value={this.state.sendAmount} onChange={e => this.setState({ sendAmount: e.target.value })} />
<InputGroupAddon addonType="append">{this.state.sendAsset.Ticker}</InputGroupAddon>
</InputGroup>
</Col>
</FormGroup>
<FormGroup row>
<Label for="recipient" sm={2}>Recipient:</Label>
<Col sm={10}>
<Input type="text" name="recipient" id="recipient" placeholder="Enter recipient address" value={this.state.sendTo} onChange={e => this.setState({ sendTo: e.target.value })} />
</Col>
</FormGroup>
<FormGroup row>
<Col>
<Button onClick={(e) => {
this.sendAsset(this.state.sendAsset, this.state.sendAmount, this.state.sendTo)
}}>Send</Button>
</Col>
</FormGroup>
</Form>
</Col>
</Row>
</Container>);
break;
case 'issue':
mainPage = (<Container>
<Row>
<Col>
<h2>Issue a new asset</h2>
<Form>
<FormGroup row>
<Label for="ticker" sm={3}>Ticker:</Label>
<Col sm={9}>
<Input type="text" name="ticker" id="ticker" placeholder="Enter ticker symbol" value={this.state.issueTicker} onChange={e => this.setState({ issueTicker: e.target.value.toUpperCase() })} />
</Col>
</FormGroup>
<FormGroup row>
<Label for="amount" sm={3}>Decimals:</Label>
<Col sm={9}>
<Input type="number" name="decimals" id="decimals" placeholder="Enter decimals of the smallest fraction" value={this.state.issueDecimals} onChange={e => this.setState({ issueDecimals: e.target.value })} />
</Col>
</FormGroup>
<FormGroup row>
<Label for="supply" sm={3}>Total Supply:</Label>
<Col sm={9}>
<InputGroup>
<Input type="text" name="supply" id="supply" placeholder="Enter total supply to mint (in whole coins)" value={this.state.issueSupply} onChange={e => this.setState({ issueSupply: e.target.value })} />
<InputGroupAddon addonType="append">{this.state.issueTicker}</InputGroupAddon>
</InputGroup>
</Col>
</FormGroup>
<FormGroup row>
<Col>
<Button onClick={(e) => {
this.issueAsset(this.state.issueTicker, this.state.issueDecimals, this.state.issueSupply)
}}>Issue {this.state.issueTicker}</Button>
</Col>
</FormGroup>
</Form>
</Col>
</Row>
</Container>);
break;
mainPage = (<Container>
<Row>
<Col>
<Form>
<FormGroup row>
<Label for="amount" sm={2}>Amount:</Label>

<Col sm={10}>
<InputGroup>
<Input type="number" name="amount" id="amount" placeholder="Enter amount" value={this.state.sendAmount} onChange={e => this.setState({ sendAmount: e.target.value })} />
<InputGroupAddon addonType="append">{this.state.sendAsset.Ticker}</InputGroupAddon>
</InputGroup>
</Col>
</FormGroup>
<FormGroup row>
<Label for="recipient" sm={2}>Recipient:</Label>
<Col sm={10}>
<Input type="text" name="recipient" id="recipient" placeholder="Enter recipient address" value={this.state.sendTo} onChange={e => this.setState({ sendTo: e.target.value })} />
</Col>
</FormGroup>
<FormGroup row>
<Col>
<Button onClick={(e) => {
this.sendAsset(this.state.sendAsset, this.state.sendAmount, this.state.sendTo)
}}>Send</Button>
</Col>
</FormGroup>
</Form>
</Col>
</Row>
</Container>);
break;
case 'issue':
mainPage = (<Container>
<Row>
<Col>
<h2>Issue a new asset</h2>
<Form>
<FormGroup row>
<Label for="ticker" sm={3}>Ticker:</Label>
<Col sm={9}>
<Input type="text" name="ticker" id="ticker" placeholder="Enter ticker symbol" value={this.state.issueTicker} onChange={e => this.setState({ issueTicker: e.target.value.toUpperCase() })} />
</Col>
</FormGroup>
<FormGroup row>
<Label for="amount" sm={3}>Decimals:</Label>
<Col sm={9}>
<Input type="number" name="decimals" id="decimals" placeholder="Enter decimals of the smallest fraction" value={this.state.issueDecimals} onChange={e => this.setState({ issueDecimals: e.target.value })} />
</Col>
</FormGroup>
<FormGroup row>
<Label for="supply" sm={3}>Total Supply:</Label>
<Col sm={9}>
<InputGroup>
<Input type="text" name="supply" id="supply" placeholder="Enter total supply to mint (in whole coins)" value={this.state.issueSupply} onChange={e => this.setState({ issueSupply: e.target.value })} />
<InputGroupAddon addonType="append">{this.state.issueTicker}</InputGroupAddon>
</InputGroup>
</Col>
</FormGroup>
<FormGroup row>
<Col>
<Button onClick={(e) => {
this.issueAsset(this.state.issueTicker, this.state.issueDecimals, this.state.issueSupply)
}}>Issue {this.state.issueTicker}</Button>
</Col>
</FormGroup>
</Form>
</Col>
</Row>
</Container>);
break;
case 'donation':
var donationButtonIntro = (
<p>You are currently not donating. Please consider switching on these tiny donation to support the development of OpenAssets</p>
);
if(this.state.donating === true) {
donationButtonIntro = (
<p>You are currently donating. If want to stop supporting the maintenance of this software, you can switch the donations off.</p>
);
}
mainPage = (
<Container>
<Row>
<Col>
<h2>Donations</h2>
<p>The development of Vertcoin and Vertcoin OpenAssets relies entirely on volunteers. By enabling donations, the software includes tiny payments in each OpenAsset transaction:</p>
<p>
<ul>
<li>When issuing a new assset, a donation of 0.001 VTC is included</li>
<li>When transferring an asset, a donation of 0.0001 VTC is included</li>
</ul>
</p>
{donationButtonIntro}
<Button className={(this.state.donating === true) ? "btn-danger" : "btn-success"} onClick={(e) => { this.toggleDonations() }}>{(this.state.donating === true) ? "Disable" : "Enable"}</Button>
</Col>
</Row>
</Container>
);
break;
}

var networkBadge = "";
Expand All @@ -311,9 +370,12 @@ class App extends Component {
<NavItem>
<NavLink href="#" onClick={(e) => { this.setState({page:'issue'}) }}>Issue</NavLink>
</NavItem>
<NavItem>
<NavLink href="#" onClick={(e) => { this.setState({page:'donation'}) }}>Donation: <b>{ this.state.donating ? 'On' : 'Off' }</b></NavLink>
</NavItem>
<NavItem>
<div class="nav-link">
<b>{ coins.toString() }</b>.<small>{ fractions.toString() }</small>&nbsp;<b>VTC</b>
| Balance: <b>{ coins.toString() }</b>.<small>{ fractions.toString() }</small>&nbsp;<b>VTC</b>
</div>
</NavItem>
</Nav>
Expand Down
Loading

0 comments on commit e69b9fa

Please sign in to comment.