Skip to content

Commit 2f08eaf

Browse files
committed
adding links to control.html list of payments
1 parent 6dedcf4 commit 2f08eaf

3 files changed

Lines changed: 45 additions & 6 deletions

File tree

pretix_eth/network/tokens.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Optional
12
import decimal
23

34
from django.core.exceptions import ImproperlyConfigured
@@ -69,6 +70,7 @@ class IToken(object):
6970
TOKEN_AND_NETWORK_ID_COMBINED = None # {TOKEN_SYMBOL}-{NETWORK_IDENTIFIER}
7071
IS_NATIVE_ASSET = True # Not a token - e.g. ETH in L1.
7172
ADDRESS = None # If a token, then the smart contract address.
73+
EIP3091_EXPLORER_URL = None # if set, allows links to transactions to be generated
7274

7375
def __init__(self):
7476
self._validate_class_variables()
@@ -158,6 +160,19 @@ def get_balance_of_address(self, hex_wallet_address, rpc_url):
158160
)
159161
return token_contract.functions.balanceOf(checksum_address).call()
160162

163+
def get_transaction_link(self, transaction_hash: Optional[str]) -> Optional[
164+
str]:
165+
return '{base}/tx/{hash}'.format(
166+
base=self.EIP3091_EXPLORER_URL,
167+
hash=transaction_hash,
168+
)
169+
170+
def get_address_link(self, address: Optional[str]) -> Optional[str]:
171+
return '{base}/address/{address}'.format(
172+
base=self.EIP3091_EXPLORER_URL,
173+
address=address,
174+
)
175+
161176

162177
""" L1 Networks """
163178

@@ -166,6 +181,7 @@ class L1(IToken):
166181
NETWORK_IDENTIFIER = "L1"
167182
NETWORK_VERBOSE_NAME = "Ethereum Mainnet"
168183
CHAIN_ID = 1
184+
EIP3091_EXPLORER_URL = "https://etherscan.io"
169185

170186
def payment_instructions(
171187
self, wallet_address, payment_amount, amount_in_token_base_unit
@@ -213,6 +229,7 @@ class RinkebyL1(L1):
213229
NETWORK_IDENTIFIER = "Rinkeby"
214230
NETWORK_VERBOSE_NAME = "Rinkeby Ethereum Testnet"
215231
CHAIN_ID = 4
232+
EIP3091_EXPLORER_URL = "https://rinkeby.etherscan.io"
216233

217234

218235
class GoerliL1(L1):
@@ -223,6 +240,7 @@ class GoerliL1(L1):
223240
NETWORK_IDENTIFIER = "Goerli"
224241
NETWORK_VERBOSE_NAME = "Goerli Ethereum Testnet"
225242
CHAIN_ID = 5
243+
EIP3091_EXPLORER_URL = "https://goerli.etherscan.io"
226244

227245

228246
class EthRinkebyL1(RinkebyL1):
@@ -290,6 +308,7 @@ class Optimism(L1):
290308
NETWORK_IDENTIFIER = "Optimism"
291309
NETWORK_VERBOSE_NAME = "Optimism Mainnet"
292310
CHAIN_ID = 10
311+
EIP3091_EXPLORER_URL = "https://optimistic.etherscan.io"
293312

294313

295314
class KovanOptimism(Optimism):
@@ -300,6 +319,7 @@ class KovanOptimism(Optimism):
300319
NETWORK_IDENTIFIER = "KovanOptimism"
301320
NETWORK_VERBOSE_NAME = "Kovan Optimism Testnet"
302321
CHAIN_ID = 69
322+
EIP3091_EXPLORER_URL = "https://kovan-optimistic.etherscan.io"
303323

304324

305325
class EthKovanOptimism(KovanOptimism):
@@ -349,6 +369,7 @@ class Arbitrum(L1):
349369
NETWORK_IDENTIFIER = "Arbitrum"
350370
NETWORK_VERBOSE_NAME = "Arbitrum Mainnet"
351371
CHAIN_ID = 42161
372+
EIP3091_EXPLORER_URL = "https://explorer.arbitrum.io"
352373

353374
def payment_instructions(
354375
self, wallet_address, payment_amount, amount_in_token_base_unit
@@ -391,6 +412,7 @@ class RinkebyArbitrum(Arbitrum):
391412
NETWORK_IDENTIFIER = "RinkebyArbitrum"
392413
NETWORK_VERBOSE_NAME = "Rinkeby Arbitrum Testnet"
393414
CHAIN_ID = 421611
415+
EIP3091_EXPLORER_URL = "https://rinkeby-explorer.arbitrum.io"
394416

395417

396418
class ETHRinkebyArbitrum(RinkebyArbitrum):

pretix_eth/payment.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,21 +307,28 @@ def payment_control_render(self, request: HttpRequest, payment: OrderPayment):
307307
if last_signed_message is not None:
308308
transaction_sender_address = last_signed_message.sender_address
309309
transaction_recipient_address = last_signed_message.recipient_address
310-
block_explorer_link = None
311310
transaction_hash = last_signed_message.transaction_hash
312311
else:
313312
transaction_sender_address = None
314313
transaction_recipient_address = None
315-
block_explorer_link = None
316314
transaction_hash = None
317315

316+
token: IToken = all_token_and_network_ids_to_tokens[
317+
payment.info_data["currency_type"]]
318+
318319
ctx = {
319320
"payment_info": payment.info_data,
321+
"token": token,
320322
"wallet_address": hex_wallet_address,
321323
"transaction_sender_address": transaction_sender_address,
324+
"transaction_sender_address_link": token.get_address_link(
325+
transaction_sender_address),
322326
"transaction_recipient_address": transaction_recipient_address,
323-
"block_explorer_link": block_explorer_link,
324-
"transaction_hash": transaction_hash
327+
"transaction_recipient_address_link": token.get_address_link(
328+
transaction_recipient_address),
329+
"transaction_hash": transaction_hash,
330+
"transaction_hash_link": token.get_transaction_link(
331+
transaction_hash),
325332
}
326333

327334
return template.render(ctx)

pretix_eth/templates/pretix_eth/control.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,22 @@
99
<dt>{% trans "Expected Receiving Wallet Address" %}</dt>
1010
<dd>{{ wallet_address }}</dd>
1111
<dt>{% trans "Transaction Sender Address" %}</dt>
12+
{% if transaction_sender_address_link %}
13+
<dd><a href="{{ transaction_sender_address_link }}" target="_blank">{{
14+
transaction_sender_address }}</a></dd>
15+
{% else %}
1216
<dd>{{ transaction_sender_address }}</dd>
17+
{% endif %}
1318
<dt>{% trans "Transaction Recipient Address" %}</dt>
19+
{% if transaction_recipient_address_link %}
20+
<dd><a href="{{ transaction_recipient_address_link }}" target="_blank">{{
21+
transaction_recipient_address }}</a></dd>
22+
{% else %}
1423
<dd>{{ transaction_recipient_address }}</dd>
24+
{% endif %}
1525
<dt>{% trans "Transaction Hash" %}</dt>
16-
{% if block_explorer_link %}
17-
<dd><a href="{{ block_explorer_link }}" target="_blank">{{
26+
{% if transaction_hash_link %}
27+
<dd><a href="{{ transaction_hash_link }}" target="_blank">{{
1828
transaction_hash }}</a></dd>
1929
{% else %}
2030
<dd>{{ transaction_hash }}</dd>

0 commit comments

Comments
 (0)