Skip to content

Commit 0cc1a75

Browse files
committed
Initial commit for EthOS redemption
1 parent bf6221a commit 0cc1a75

15 files changed

+268
-62
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ insert_final_newline = true
1010
trim_trailing_whitespace = true
1111

1212
# 4 space indentation
13-
[*.{py}]
13+
[*.py]
1414
indent_size = 4

app/app/settings.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,18 @@
394394
WEB3_HTTP_PROVIDER = env('WEB3_HTTP_PROVIDER', default='https://rinkeby.infura.io')
395395

396396
# COLO Coin
397-
COLO_ACCOUNT_ADDRESS = env('COLO_ACCOUNT_ADDRESS', default='')
398-
COLO_ACCOUNT_PRIVATE_KEY = env('COLO_ACCOUNT_PRIVATE_KEY', default='')
397+
COLO_ACCOUNT_ADDRESS = env('COLO_ACCOUNT_ADDRESS', default='') # TODO
398+
COLO_ACCOUNT_PRIVATE_KEY = env('COLO_ACCOUNT_PRIVATE_KEY', default='') # TODO
399+
400+
# EthOS
401+
ETHOS_CONTRACT_ADDRESS = env('ETHOS_CONTRACT_ADDRESS', default='') # TODO
402+
ETHOS_ACCOUNT_ADDRESS = env('ETHOS_ACCOUNT_ADDRESS', default='') # TODO
403+
ETHOS_ACCOUNT_PRIVATE_KEY = env('ETHOS_ACCOUNT_PRIVATE_KEY', default='') # TODO
404+
405+
ETHOS_TWITTER_CONSUMER_KEY = env('ETHOS_TWITTER_CONSUMER_KEY', default='') # TODO
406+
ETHOS_TWITTER_CONSUMER_SECRET = env('ETHOS_TWITTER_CONSUMER_SECRET', default='') # TODO
407+
ETHOS_TWITTER_ACCESS_TOKEN = env('ETHOS_TWITTER_ACCESS_TOKEN', default='') # TODO
408+
ETHOS_TWITTER_ACCESS_SECRET = env('ETHOS_TWITTER_ACCESS_SECRET', default='') # TODO
399409

400410
# Silk Profiling and Performance Monitoring
401411
ENABLE_SILK = env.bool('ENABLE_SILK', default=False)

app/app/urls.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import dashboard.views
3131
import dataviz.d3_views
3232
import dataviz.views
33+
import ethos.views
3334
import external_bounties.views
3435
import faucet.views
3536
import gitcoinbot.views
@@ -39,7 +40,6 @@
3940
import retail.emails
4041
import retail.views
4142
import tdi.views
42-
import ethos.views
4343
from dashboard.router import router as dbrouter
4444
from external_bounties.router import router as ebrouter
4545

@@ -119,6 +119,8 @@
119119

120120
# redeem coin
121121
url(r'^coin/redeem/(.*)/?', dashboard.views.redeem_coin, name='redeem'),
122+
123+
# EthOS
122124
url(r'^ethos/(.*)/?', ethos.views.redeem_coin, name='redeem_coin'),
123125

124126
# images

app/assets/yge/redeem_ethos.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
/* eslint-disable no-console */
22
window.onload = function() {
3-
43
setTimeout(function() {
54
$('loading').style.display = 'none';
6-
7-
if (coin_status === 'INITIAL') {
8-
$('send_eth').style.display = 'block';
9-
} else if (coin_status === 'PENDING') {
10-
$('send_eth_done').style.display = 'block';
11-
$('colo_txid').innerHTML = '<a href="https://' + etherscanDomain() + '/tx/' + colo_txid + '" target="_blank" rel="noopener noreferrer">See your transaction on the blockchain here</a>';
12-
}
5+
$('send_eth').style.display = 'block';
136
}, 500);
147
};
158

169
function redeemCoin() {
1710
mixpanel.track('Redeem Coin Click', {});
1811
metaMaskWarning();
1912

20-
var forwarding_address = $('forwarding_address').value.trim();
21-
var twitter_usernanme = $('#twitter_username').value;
13+
var forwarding_address = $('forwarding_address').value;
14+
var twitter_username = $('twitter_username').value;
2215

2316
// Check for valid address
2417
isValidForwardingAddress = forwarding_address.indexOf('0x') != -1;
@@ -27,14 +20,21 @@ function redeemCoin() {
2720
return;
2821
}
2922

23+
// Check for twitter username
24+
if (!twitter_username) {
25+
_alert({message: gettext('Please enter your Twitter username')}, 'error');
26+
return;
27+
}
28+
3029
var sendEthInnerHTML = $('send_eth').innerHTML;
3130

3231
$('send_eth').innerHTML = '<img src="/static/yge/images/loading_v2.gif" style="max-width: 70px; max-height: 70px;"><br><h4>Submitting to the blockchain...</h4>';
3332

3433
fetch(window.location.href, {
3534
method: 'POST',
3635
body: JSON.stringify({
37-
address: forwarding_address
36+
address: forwarding_address.trim(),
37+
username: twitter_username.trim()
3838
})
3939
})
4040
.then(
@@ -52,6 +52,13 @@ function redeemCoin() {
5252
}
5353

5454
$('send_eth').innerHTML = sendEthInnerHTML;
55+
56+
// Prefill the input fields as the form is attached dynamically to the DOM
57+
setTimeout(function() {
58+
document.getElementById('send_eth').querySelector('#forwarding_address').value = forwarding_address;
59+
document.getElementById('send_eth').querySelector('#twitter_username').value = twitter_username;
60+
}, 100);
61+
5562
mixpanel.track('Redeem EthOS Coin Error', {
5663
error: data.message
5764
});

app/ethos/admin.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
from django.contrib import admin
22

3+
from ethos.models import Hop
4+
35
# Register your models here.
6+
7+
class GeneralAdmin(admin.ModelAdmin):
8+
ordering = ['-id']
9+
10+
11+
admin.site.register(Hop, GeneralAdmin)

app/ethos/management/__init__.py

Whitespace-only changes.

app/ethos/management/commands/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'''
2+
Copyright (C) 2017 Gitcoin Core
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Affero General Public License as published
6+
by the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Affero General Public License for more details.
13+
14+
You should have received a copy of the GNU Affero General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
'''
18+
19+
from django.core.management.base import BaseCommand
20+
from django.utils.crypto import get_random_string
21+
22+
from ethos.models import ShortCode
23+
24+
25+
class Command(BaseCommand):
26+
help = 'generates some ethos shortcodes'
27+
28+
def add_arguments(self, parser):
29+
parser.add_argument('count', type=int)
30+
31+
def handle(self, *args, **options):
32+
short_codes = []
33+
for i in range(0, options['count']):
34+
shortcode = get_random_string(8)
35+
short_codes.append(ShortCode(shortcode=shortcode))
36+
print(f'https://gitcoin.co/ethos/{shortcode}')
37+
38+
ShortCode.objects.bulk_create(short_codes)

app/ethos/migrations/0001_initial.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 2.0.4 on 2018-04-15 19:27
1+
# Generated by Django 2.0.4 on 2018-05-04 16:39
22

33
from django.db import migrations, models
44
import django.db.models.deletion
@@ -19,8 +19,10 @@ class Migration(migrations.Migration):
1919
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
2020
('created_on', models.DateTimeField(db_index=True, default=economy.models.get_time)),
2121
('modified_on', models.DateTimeField(default=economy.models.get_time)),
22+
('ip', models.GenericIPAddressField(protocol='IPv4')),
2223
('twitter_username', models.CharField(max_length=255)),
23-
('twitter_profile', models.URLField()),
24+
('twitter_profile_pic', models.URLField()),
25+
('txid', models.CharField(default='', max_length=255)),
2426
('web3_address', models.CharField(max_length=255)),
2527
('previous_hop', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='ethos.Hop')),
2628
],
@@ -41,4 +43,9 @@ class Migration(migrations.Migration):
4143
'verbose_name_plural': 'ShortCodes',
4244
},
4345
),
46+
migrations.AddField(
47+
model_name='hop',
48+
name='shortcode',
49+
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='actions', to='ethos.ShortCode'),
50+
),
4451
]

app/ethos/models.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
'''
1818

1919
from django.db import models
20+
2021
from economy.models import SuperModel
21-
from django.utils.text import slugify
22+
2223

2324
class ShortCode(SuperModel):
2425
"""Define the shortcode schema"""
@@ -27,7 +28,7 @@ class Meta:
2728
"""Define metadata associated with ShortCode."""
2829

2930
verbose_name_plural = 'ShortCodes'
30-
31+
3132
num_scans = models.PositiveSmallIntegerField(default=0)
3233
shortcode = models.CharField(max_length=255, default='')
3334

@@ -39,7 +40,10 @@ class Meta:
3940

4041
verbose_name_plural = 'Hops'
4142

43+
ip = models.GenericIPAddressField(protocol='IPv4')
4244
twitter_username = models.CharField(max_length=255)
43-
twitter_profile = models.URLField()
45+
twitter_profile_pic = models.URLField()
46+
txid = models.CharField(max_length=255, default='')
4447
web3_address = models.CharField(max_length=255)
45-
previous_hop = models.ForeignKey("self", on_delete=models.SET_NULL, blank=True, null=True)
48+
previous_hop = models.ForeignKey("self", on_delete=models.SET_NULL, blank=True, null=True)
49+
shortcode = models.ForeignKey(ShortCode, related_name='actions', on_delete=models.CASCADE, null=True)

app/ethos/templates/redeem_ethos.html

-15
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,5 @@ <h2>{%trans "Enter your name to continue." %}</h2>
7676
<br>
7777
</div>
7878
</div>
79-
<div id="send_eth_done" style="display:none;">
80-
<h1>{% trans "Congrats!" %}</h1>
81-
<p>{% trans "You've redeemed EthOS." %}<br /><span id="colo_txid"></span>.</p>
82-
</div>
83-
{% if coin_status %}
84-
<script type="text/javascript">
85-
var coin_status = '{{ coin_status }}';
86-
</script>
87-
{% endif %}
88-
{% if colo_txid %}
89-
<script type="text/javascript">
90-
var colo_txid = '{{ colo_txid }}';
91-
document.suppressweb3alert = true;
92-
</script>
93-
{% endif %}
9479
</section>
9580
{% endblock %}

app/ethos/tests.py

-3
This file was deleted.

0 commit comments

Comments
 (0)