8000 gitcoinbot leaves a comment on the feed when a txn clears or is pending by owocki · Pull Request #8614 · gitcoinco/web · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

gitcoinbot leaves a comment on the feed when a txn clears or is pending #8614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions app/grants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from economy.utils import ConversionRateNotFoundError, convert_amount
from gas.utils import eth_usd_conv_rate, recommend_min_gas_price_to_confirm_in_time
from grants.utils import generate_collection_thumbnail, get_upload_filename, is_grant_team_member
from townsquare.models import Favorite
from townsquare.models import Favorite, Comment
from web3 import Web3

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -1746,6 +1746,24 @@ def identity_identifier(self, mechanism):
else:
return self.profile_for_clr.id

def leave_gitcoinbot_comment_for_status(self, status):
try:
from dashboard.models import Profile
comment = f"Transaction status: {status} (as of {timezone.now().strftime('%Y-%m-%d %H:%m %Z')})"
profile = Profile.objects.get(handle='gitcoinbot')
activity = self.subscription.activities.first()
Comment.objects.update_or_create(
profile=profile,
activity=activity,
defaults={
"comment":comment,
"is_edited":True,
}
);
except Exception as e:
print(e)


def update_tx_status(self):
"""Updates tx status for Ethereum contributions."""
try:
Expand Down Expand Up @@ -1802,11 +1820,13 @@ def update_tx_status(self):
then = timezone.now() - timezone.timedelta(hours=1)
if self.created_on > then:
print('txn pending')
self.leave_gitcoinbot_comment_for_status('pending')
else:
self.success = False
self.validator_passed = False
self.validator_comment = "txn pending for more than 1 hours, assuming failure"
print(self.validator_comment)
self.leave_gitcoinbot_comment_for_status('dropped')
return

# Handle dropped txns
Expand All @@ -1815,6 +1835,7 @@ def update_tx_status(self):
self.validator_passed = False
self.validator_comment = "txn not found"
print('txn not found')
self.leave_gitcoinbot_comment_for_status('dropped')
return

# Validate that the token transfers occurred
Expand All @@ -1829,21 +1850,25 @@ def update_tx_status(self):

else:
# This validator is only for eth_std and eth_zksync, so exit for other contribution types
self.leave_gitcoinbot_comment_for_status('unknown')
return

# Validator complete!

if self.success:
print("TODO: do stuff related to successful contribs, like emails")
else:
print("TODO: do stuff related to failed contribs, like emails")
except Exception as e:
self.leave_gitcoinbot_comment_for_status('error')
self.validator_passed = False
self.validator_comment = str(e)
print(f"Exception: {self.validator_comment}")
self.tx_cleared = False
self.split_tx_confirmed = False
self.success = False
if self.success:
print("TODO: do stuff related to successful contribs, like emails")
self.leave_gitcoinbot_comment_for_status('success')
else:
print("TODO: do stuff related to failed contribs, like emails")
self.leave_gitcoinbot_comment_for_status('failed')


@receiver(post_save, sender=Contribution, dispatch_uid="psave_contrib")
Expand Down
12 changes: 6 additions & 6 deletions app/grants/templates/grants/detail/_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ <h5 class="mb-5 text-muted" v-if="!transactions.grantTransactions?.length && !lo
</span>
</div>
<div class="row justify-content-end text-secondary">
<span v-if="!transaction.success">
(Failed)
</span>
<span v-if="!transaction.tx_cleared">
(Pending)&nbsp;
</span>
<span v-b-tooltip.hover.top="transaction.subscription.amount_per_period_usdt">
[[transaction.subscription.amount_per_period_usdt | formatNumberWithDecimal ]] USD
</span>
<span v-if="!transaction.success">
- (Failed)
</span>
<span v-else-if="!transaction.tx_cleared">
- (Pending)&nbsp;
</span>
</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/townsquare/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def presave_comment(sender, instance, **kwargs):
def postsave_comment(sender, instance, created, **kwargs):
from townsquare.tasks import send_comment_email
if created:
send_comment_email.delay(instance.pk)
if not instance.is_edited:
send_comment_email.delay(instance.pk)


class OfferQuerySet(models.QuerySet):
Expand Down
0