Skip to content

Commit 12595e3

Browse files
committed
Merge remote-tracking branch 'upstream/stable'
2 parents e0d31d8 + e5a00c0 commit 12595e3

19 files changed

Lines changed: 236 additions & 86 deletions

File tree

app/app/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
# kudos
9898
re_path(r'^kudos/?$', kudos.views.about, name='kudos_main'),
9999
re_path(r'^kudos/about/?$', kudos.views.about, name='kudos_about'),
100+
re_path(r'^kudos/sync/?$', kudos.views.sync, name='kudos_sync'),
100101
re_path(r'^kudos/marketplace/?$', kudos.views.marketplace, name='kudos_marketplace'),
101102
re_path(r'^kudos/mint/?$', kudos.views.mint, name='kudos_mint'),
102103
re_path(r'^kudos/send/?$', kudos.views.send_2, name='kudos_send'),

app/assets/onepager/js/receive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ $(document).ready(function() {
164164
gasLimit = new web3.utils.BN(gasLimit);
165165
var send_amount = holderBalance.sub(gasLimit.mul(gas_price_wei)).sub(buffer);
166166

167-
if (document.override_send_amount) {
167+
if (document.override_send_amount && (document.override_send_amount * 10 ** 18) < send_amount) {
168168
send_amount = document.override_send_amount * 10 ** 18; // TODO: decimals
169169
}
170170

app/assets/v2/js/pages/profile.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,34 @@ $(document).ready(function() {
1010
}
1111
});
1212
}
13+
$('#kudos-section').on('click', '.fa-sync', function(e) {
14+
e.preventDefault();
15+
e.stopPropagation();
16+
if ($(this).data('owned') == 'False') {
17+
_alert('To re-issue this kudos, please contact the sender and have them re-send it.', 'error');
18+
return;
19+
}
20+
let url = '/kudos/sync/?pk=' + $(this).data('id');
21+
let $target = $(this).parents('.flip-card__extra-data').find('.block_explorer_link');
22+
23+
$.get(url, function(response) {
24+
let block_ex_url = response['url'];
25+
let txid = response['txid'];
26+
27+
$target.attr('href', block_ex_url);
28+
let txid_trunc = txid.substring(0, 5) + '...' + txid.substring(txid.length - 10, txid.length);
29+
30+
$target.text(txid_trunc);
31+
$target.css('color', 'grey');
32+
setTimeout(function() {
33+
$target.css('color', 'white');
34+
}, 1000);
35+
_alert('Sync re-submitted to chain.', 'info', 1000);
36+
});
37+
$(this).remove();
38+
39+
});
40+
1341

1442
$('#kudos-section').on('click keypress', '.flip-card', e => {
1543
if ($(e.target).is('a')) {

app/dashboard/models.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3160,6 +3160,13 @@ def kudos_authored(self):
31603160
from kudos.models import Token
31613161
return Token.objects.filter(artist=self.handle, num_clones_allowed__gt=1, hidden=False)
31623162

3163+
@property
3164+
def get_failed_kudos(self):
3165+
from kudos.models import KudosTransfer
3166+
pks = list(self.get_my_kudos.values_list('pk', flat=True)) + list(self.get_sent_kudos.values_list('pk', flat=True))
3167+
qs = KudosTransfer.objects.filter(pk__in=pks)
3168+
return qs.filter(Q(txid='pending_celery') | Q(tx_status__in=['dropped', 'unknown']))
3169+
31633170
@property
31643171
def get_my_kudos(self):
31653172
from kudos.models import KudosTransfer
@@ -3175,7 +3182,8 @@ def get_my_kudos(self):
31753182
kudos_transfers = kudos_transfers.filter(
31763183
kudos_token_cloned_from__contract__network__in=[settings.KUDOS_NETWORK, 'xdai']
31773184
)
3178-
kudos_transfers = kudos_transfers.send_success() | kudos_transfers.send_pending() | kudos_transfers.not_submitted()
3185+
# Multiple support requests for kudos not showing on profile were caused by this
3186+
# kudos_transfers = kudos_transfers.send_success() | kudos_transfers.send_pending() | kudos_transfers.not_submitted()
31793187

31803188
# remove this line IFF we ever move to showing multiple kudos transfers on a profile
31813189
kudos_transfers = kudos_transfers.distinct('id')
@@ -3191,7 +3199,8 @@ def get_sent_kudos(self):
31913199
kt_sender_profile = KudosTransfer.objects.filter(sender_profile=self)
31923200

31933201
kudos_transfers = kt_address | kt_sender_profile
3194-
kudos_transfers = kudos_transfers.send_success() | kudos_transfers.send_pending() | kudos_transfers.not_submitted()
3202+
# Multiple support requests for kudos not showing on profile were caused by this
3203+
# kudos_transfers = kudos_transfers.send_success() | kudos_transfers.send_pending() | kudos_transfers.not_submitted()
31953204
kudos_transfers = kudos_transfers.filter(
31963205
kudos_token_cloned_from__contract__network__in=[settings.KUDOS_NETWORK, 'xdai']
31973206
)

app/dashboard/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,6 +2883,8 @@ def get_profile_tab(request, profile, tab, prev_context):
28832883
kudos_limit = 8
28842884
context['kudos'] = owned_kudos[0:kudos_limit]
28852885
context['sent_kudos'] = sent_kudos[0:kudos_limit]
2886+
if request.GET.get('failed', 0):
2887+
context['kudos'] = profile.get_failed_kudos
28862888
context['kudos_count'] = owned_kudos.count()
28872889
context['sent_kudos_count'] = sent_kudos.count()
28882890
elif tab == 'ptokens':

app/kudos/helpers.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,73 @@ def reconcile_kudos_preferred_wallet(profile):
9999
profile.save()
100100

101101
return profile.preferred_kudos_wallet
102+
103+
104+
def re_send_kudos_transfer(kt, override_with_xdai_okay):
105+
from dashboard.utils import get_web3, has_tx_mined
106+
from gas.utils import recommend_min_gas_price_to_confirm_in_time
107+
from kudos.utils import kudos_abi
108+
from web3 import Web3
109+
from kudos.models import KudosTransfer
110+
from django.utils import timezone
111+
112+
gas_clear_within_mins = 1
113+
gas_multiplier = 1.2
114+
115+
if not kt.kudos_token_cloned_from.is_owned_by_gitcoin:
116+
print(f'{kt.id} => not owned by gitcoin')
117+
return
118+
119+
network = kt.network
120+
if network == 'mainnet':
121+
if kt.kudos_token_cloned_from.on_xdai and override_with_xdai_okay:
122+
network = 'xdai'
123+
kt.network = 'xdai'
124+
kt.kudos_token_cloned_from = kt.kudos_token_cloned_from.on_xdai
125+
kt.save()
126+
w3 = get_web3(network)
127+
kudos_contract_address = Web3.toChecksumAddress(settings.KUDOS_CONTRACT_MAINNET)
128+
if network == 'xdai':
129+
kudos_contract_address = Web3.toChecksumAddress(settings.KUDOS_CONTRACT_XDAI)
130+
kudos_owner_address = Web3.toChecksumAddress(settings.KUDOS_OWNER_ACCOUNT)
131+
nonce = w3.eth.getTransactionCount(kudos_owner_address)
132+
133+
token_id = kt.kudos_token_cloned_from.token_id
134+
address = kt.receive_address
135+
if not address:
136+
address = kt.recipient_profile.preferred_payout_address
137+
if not address:
138+
address = kt.recipient_profile.last_observed_payout_address
139+
price_finney = kt.kudos_token_cloned_from.price_finney
140+
141+
try:
142+
143+
contract = w3.eth.contract(Web3.toChecksumAddress(kudos_contract_address), abi=kudos_abi())
144+
gasPrice = int(gas_multiplier * float(recommend_min_gas_price_to_confirm_in_time(gas_clear_within_mins)) * 10**9)
145+
if network == 'xdai':
146+
gasPrice = 1 * 10**9
147+
tx = contract.functions.clone(Web3.toChecksumAddress(address), token_id, 1).buildTransaction({
148+
'nonce': nonce,
149+
'gas': 500000,
150+
'gasPrice': gasPrice,
151+
'value': int(price_finney / 1000.0 * 10**18),
152+
})
153+
154+
signed = w3.eth.account.signTransaction(tx, settings.KUDOS_PRIVATE_KEY)
155+
txid = w3.eth.sendRawTransaction(signed.rawTransaction).hex()
156+
nonce += 1
157+
print(f'sent tx nonce:{nonce} for kt:{kt.id} on {network}')
158+
kt.txid = txid
159+
kt.receive_txid = txid
160+
kt.tx_status = 'pending'
161+
kt.receive_tx_status = 'pending'
162+
kt.network = network
163+
kt.tx_time = timezone.now()
164+
kt.receive_tx_time = timezone.now()
165+
kt.save()
166+
return txid
167+
168+
except Exception as e:
169+
print(e)
170+
error = "Could not redeem your kudos. Please try again soon."
171+
return None

app/kudos/management/commands/process_pending_kudos_distributions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def handle(self, *args, **options):
4646
_async = options['async']
4747
override_gas_price = options['override_gas_price']
4848
order_by = options['order_by'].replace('_', '-')
49-
delay_if_gas_prices_gt_redeem = 300
49+
delay_if_gas_prices_gt_redeem = 200
5050
send_notif_email = True
5151
send_on_xdai = True
5252
gitcoin_owner_addr = '0x6239FF1040E412491557a7a02b2CBcC5aE85dc8F'

app/kudos/tasks.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ def redeem_bulk_kudos(self, kt_id, delay_if_gas_prices_gt_redeem= 50, override_g
6767
with redis.lock("tasks:all_kudos_requests", timeout=LOCK_TIMEOUT):
6868
with redis.lock("tasks:redeem_bulk_kudos:%s" % kt_id, timeout=override_lock_timeout):
6969
multiplier = 1
70-
# high gas prices, 5 hour gas limit - DL
71-
gas_price = int(float(recommend_min_gas_price_to_confirm_in_time(300)) * multiplier)
70+
gas_price = int(float(recommend_min_gas_price_to_confirm_in_time(1)) * multiplier * 10**9)
71+
if network == 'xdai':
72+
gas_price = 1 * 10**9
73+
7274
if override_gas_price:
7375
gas_price = override_gas_price
7476
if gas_price > delay_if_gas_prices_gt_redeem:

app/kudos/templates/shared/kudos_card_hover_content.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,15 @@
4747
<a href="{{kt.github_url}}" target="_blank">{% trans 'Issue url' %}</a>
4848
{% endif %}
4949
{% if kt.receive_txid == 'pending_celery' %}
50-
Pending Issuance on Chain
50+
Pending Issuance on Chain
5151
{% else %}
52-
<a title="{% trans 'tx on block explroer' %}" href="{{kt.receive_tx_blockexplorer_link}}" target="_blank" class="mb-1">{{ kt.receive_txid|humanize_address }}</a>
52+
<a title="{% trans 'tx on block explorer' %}" href="{{kt.receive_tx_blockexplorer_link}}" target="_blank" class="mb-1 block_explorer_link">{{ kt.receive_txid|humanize_address }}</a>
5353
{% endif %}
54+
{% if kt.receive_txid == 'pending_celery' or kt.receive_tx_status == 'dropped' or kt.receive_tx_status == 'unknown' %}
55+
{% if github_handle == kt.username or github_handle == kt.from_username or 1 %}
56+
<div><i class="fas fa-sync" data-id="{{kt.id}}" data-owned='{{kt.kudos_token_cloned_from.is_owned_by_gitcoin}}'></i></div>
57+
{% endif %}
58+
{% endif %}
59+
5460
</div>
5561
{% endfor %}

app/kudos/views.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,29 @@ def get_profile(handle):
8383
return to_profile
8484

8585

86+
def sync(request):
87+
response = {}
88+
try:
89+
kt_id = request.GET.get('pk')
90+
kt = KudosTransfer.objects.get(pk=kt_id)
91+
response['txid'] = kt.txid
92+
if kt.kudos_token_cloned_from.is_owned_by_gitcoin:
93+
if request.user.is_authenticated:
94+
if request.user.profile.handle in [kt.username.replace('@',''), kt.from_username.replace('@','')] or settings.DEBUG:
95+
authd = not kt.tx_time or kt.tx_time < (timezone.now() - timezone.timedelta(minutes=30))
96+
authd = authd and (kt.receive_txid == 'pending_celery' or kt.receive_tx_status == 'dropped' or kt.receive_tx_status == 'unknown')
97+
if authd:
98+
from kudos.helpers import re_send_kudos_transfer
99+
response['txid'] = re_send_kudos_transfer(kt, True)
100+
from dashboard.utils import tx_id_to_block_explorer_url
101+
response['url'] = tx_id_to_block_explorer_url(kt.txid, kt.network)
102+
response['success'] = 1
103+
except Exception as e:
104+
response['error'] = str(e)
105+
106+
return JsonResponse(response)
107+
108+
86109
def about(request):
87110
"""Render the Kudos 'about' page."""
88111
activity_limit = 5

0 commit comments

Comments
 (0)