Skip to content

Commit

Permalink
Fix race conditions when inserting tokens on TokenNotValid
Browse files Browse the repository at this point in the history
- Add admin page for `TokenNotValid`
  • Loading branch information
Uxio0 committed Nov 19, 2024
1 parent 94e5ee3 commit 06a66f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion safe_transaction_service/tokens/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
HasLogoFilterAdmin,
)

from .models import Token, TokenList
from .models import Token, TokenList, TokenNotValid


@admin.register(Token)
Expand Down Expand Up @@ -34,3 +34,10 @@ class TokenListAdmin(admin.ModelAdmin):
)
ordering = ("pk",)
search_fields = ["url", "description"]


@admin.register(TokenNotValid)
class TokenNotValidAdmin(AdvancedAdminSearchMixin, admin.ModelAdmin):
list_display = ("address",)
ordering = ("address",)
search_fields = ["==address"]
4 changes: 2 additions & 2 deletions safe_transaction_service/tokens/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ def create_from_blockchain(
logger.debug(
"Cannot find anything on blockchain for token=%s", token_address
)
TokenNotValid.objects.create(address=token_address)
TokenNotValid.objects.get_or_create(address=token_address)
return None

# Ignore tokens with empty name or symbol
if not erc_info.name or not erc_info.symbol:
logger.warning(
"Token with address=%s has not name or symbol", token_address
)
TokenNotValid.objects.create(address=token_address)
TokenNotValid.objects.get_or_create(address=token_address)
return None

name_and_symbol: list[str] = []
Expand Down

0 comments on commit 06a66f6

Please sign in to comment.