Skip to content

Commit

Permalink
bump frontend deps
Browse files Browse the repository at this point in the history
  • Loading branch information
lassejaco committed Jan 23, 2024
1 parent 88311d6 commit 9509ad0
Show file tree
Hide file tree
Showing 15 changed files with 9,450 additions and 48 deletions.
12 changes: 8 additions & 4 deletions pretix_eth/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,27 @@ def signal_process_response(sender, request, response, **kwargs):
h = _parse_csp(response['Content-Security-Policy'])
_merge_csp(h, {
'style-src': [
'https://fonts.googleapis.com',
"'unsafe-inline'"
],
'img-src': [
'https://registry.walletconnect.com',
"https://explorer-api.walletconnect.com",
"https://*.bridge.walletconnect.org",
"blob: data:"
],
'script-src': [
# unsafe-inline/eval required for webpack bundles (we cannot know names in advance).
"'unsafe-inline'",
"'unsafe-eval'"
],
'font-src': [
"https://fonts.gstatic.com"
],
'frame-src': [
'https://verify.walletconnect.com/'
'https://verify.walletconnect.org',
'https://verify.walletconnect.com'
],
# Chrome correctly errors out without this CSP
'connect-src': [
"https://api.web3modal.com",
"wss://relay.walletconnect.com",
"https://zkevm-rpc.com/",
"https://explorer-api.walletconnect.com",
Expand Down
2 changes: 1 addition & 1 deletion pretix_eth/static/pretix_eth/eth_plugin.css
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ button#uniswap_btn:hover {
display: block;
}

w3m-core-button {
w3m-button {
display: block;
margin-bottom: 10px;
}
Expand Down
4 changes: 2 additions & 2 deletions pretix_eth/static/pretix_eth/web3modal-dist/manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"main.js": "/static/pretix_eth/web3modal-dist/web3modal.4411707096ff89c614b4.js",
"periodicCheck.js": "/static/pretix_eth/web3modal-dist/web3modal.177d8cabdae10dcc5990.js"
"main.js": "/static/pretix_eth/web3modal-dist/web3modal.0d8a283067a5e9dbd598.js",
"periodicCheck.js": "/static/pretix_eth/web3modal-dist/web3modal.30b71e763c28fe96ef2e.js"
}
5,436 changes: 5,436 additions & 0 deletions pretix_eth/static/pretix_eth/web3modal-dist/web3modal.0d8a283067a5e9dbd598.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ PERFORMANCE OF THIS SOFTWARE.

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */

/**
* @license
* Copyright 2017 Google LLC
Expand All @@ -40,6 +42,12 @@ PERFORMANCE OF THIS SOFTWARE.
* SPDX-License-Identifier: BSD-3-Clause
*/

/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/

/**
* @license
* Copyright 2021 Google LLC
Expand All @@ -54,3 +62,13 @@ PERFORMANCE OF THIS SOFTWARE.
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/

/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

This file was deleted.

Large diffs are not rendered by default.

This file was deleted.

7 changes: 3 additions & 4 deletions pretix_eth/static/pretix_eth/web3modal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
"author": "",
"license": "ISC",
"dependencies": {
"@wagmi/core": "^1.3.2",
"@web3modal/ethereum": "^2.6.1",
"@web3modal/html": "^2.6.1",
"viem": "^1.1.6",
"@wagmi/core": "1.4.13",
"@web3modal/wagmi1": "^4.0.0-544a28f1",
"viem": "1.21.4",
"webpack": "^5.75.0"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion pretix_eth/static/pretix_eth/web3modal/src/chains.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { arbitrum, arbitrumGoerli, mainnet, goerli, optimism, optimismGoerli, sepolia, zkSync, polygonZkEvm } from "@wagmi/core/chains";
// import { arbitrum, arbitrumGoerli, mainnet, goerli, optimism, optimismGoerli, sepolia, zkSync, polygonZkEvm } from "@wagmi/core/chains";
import { arbitrum, arbitrumGoerli, mainnet, goerli, optimism, optimismGoerli, sepolia, zkSync, polygonZkEvm } from "viem/chains";

// Safe is only supported on certain networks there doesn't seem to be any smart way to detect if a network is supported (it doesn't follow https://github.com/ethereum-lists/chains ?), so this has to be manually configured
// Safe documentation: https://github.com/safe-global/safe-docs/blob/main/learn/safe-core/safe-core-api/available-services.md
Expand Down
43 changes: 37 additions & 6 deletions pretix_eth/static/pretix_eth/web3modal/src/core.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

import { signTypedData, erc20ABI, getAccount, getNetwork, switchNetwork, sendTransaction, readContract, prepareWriteContract, writeContract, getPublicClient } from "@wagmi/core";
import { signTypedData, erc20ABI, getAccount, getNetwork, switchNetwork, sendTransaction, readContract, writeContract, getPublicClient } from "@wagmi/core";
import {
getTransactionDetailsURL,
showError, resetErrorMessage, displayOnlyId,
Expand All @@ -9,6 +9,22 @@ import {
} from './interface.js';
import { runPeriodicCheck } from './periodic_check.js';

function validate_txhash(addr) {
return /^0x([A-Fa-f0-9]{64})$/.test(addr);
}

const checkResult = (result) => {
try {
const parsed = JSON.parse(result);

if (parsed.error) {
throw parsed.error;
}
} catch (e) {

}
}

/*
* Called on "Connect wallet and pay" button click and every chain/account change
*
Expand Down Expand Up @@ -102,6 +118,8 @@ async function sign() {

const signature = await signTypedData(message);

// For some ungodly reason wagmi doesn't error out on some errors - have to check the return value for errors to avoid any issues
checkResult(signature);

// Validate signature on the backend before proceeding:
const url = new URL(window.location.origin + window.__validateSignatureUrl);
Expand All @@ -124,7 +142,7 @@ async function sign() {
if (response.ok) {
await submitTransaction();
} else {
showError('EIP1271 error: unable to verify signature; your wallet may not be supported.')
showError('EIP1271 validation error: unable to verify signature; your wallet may not be supported.')

GlobalPretixEthState.signatureRequested = false;

Expand All @@ -133,6 +151,9 @@ async function sign() {
} else {
const signature = await signTypedData(message)

// For some ungodly reason wagmi doesn't error out on some errors - have to check the return value for errors to avoid any issues
checkResult(signature);

GlobalPretixEthState.messageSignature = signature;
GlobalPretixEthState.signedByAccount = GlobalPretixEthState.selectedAccount;

Expand Down Expand Up @@ -182,27 +203,37 @@ async function submitTransaction() {
displayOnlyId("send-transaction");

try {
const { hash } = await writeContract({
const result = await writeContract({
abi: erc20ABI,
address: daiContractAddress,
functionName: 'transfer',
args: [GlobalPretixEthState.paymentDetails['recipient_address'], GlobalPretixEthState.paymentDetails['amount']]
})

await submitSignature(hash);
const valid = validate_txhash(result.hash);

if (!valid) throw 'Invalid transaction hash';

checkResult(result);

await submitSignature(result.hash);
} catch (e) {
showError(e);
}
} else { // crypto transfer
displayOnlyId("send-transaction");

try {
const { hash } = await sendTransaction({
const result = await sendTransaction({
to: GlobalPretixEthState.paymentDetails['recipient_address'],
value: GlobalPretixEthState.paymentDetails['amount']
});

await submitSignature(hash);
const valid = validate_txhash(result.hash);

if (!valid) throw 'Invalid transaction hash';

await submitSignature(result.hash);
} catch (e) {
showError(e);
}
Expand Down
2 changes: 1 addition & 1 deletion pretix_eth/static/pretix_eth/web3modal/src/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function signIn() {
return true;
}

await GlobalPretixEthState.web3Modal.openModal()
await GlobalPretixEthState.web3Modal.open()
} catch (e) {
console.error(e, 'Sign in failed')

Expand Down
41 changes: 16 additions & 25 deletions pretix_eth/static/pretix_eth/web3modal/src/web3modal.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"use strict";

import { configureChains, createConfig, watchAccount, watchNetwork } from "@wagmi/core";
import { EthereumClient, w3mConnectors, w3mProvider } from '@web3modal/ethereum'
import { Web3Modal } from "@web3modal/html";
import { watchAccount, watchNetwork } from "@wagmi/core";
import { createWeb3Modal, defaultWagmiConfig } from '@web3modal/wagmi1/react'
import { showError, GlobalPretixEthState, signIn, displayOnlyId, getCookie } from './interface.js';
import { makePayment } from './core.js';
import chains from "./chains.js";
import chainsInfo from "./chains.js";

async function init() {
const desiredChainID = GlobalPretixEthState.elements.buttonConnect.getAttribute("data-chain-id");
Expand All @@ -14,35 +13,27 @@ async function init() {
// Some wallets read the page title and presents it to the user in the wallet - the pretix generated one looks confusing, so we override it before instantiating web3modal
document.title = 'Pretix Payment';

const desiredChain = chains.filter(chainInfo => chainInfo.chain.id === parseInt(desiredChainID));
const desiredChain = chainsInfo.filter(chainInfo => chainInfo.chain.id === parseInt(desiredChainID));

if (desiredChain.length < 1) {
showError('Invalid chain ID');

return;
}

const { publicClient } = configureChains([desiredChain[0].chain], [w3mProvider({ projectId: walletConnectProjectId })])

const wagmiClient = createConfig({
autoConnect: true,
connectors: [
...w3mConnectors({
projectId:
walletConnectProjectId,
version: 2,
chains: [desiredChain[0].chain]
})
],
publicClient,
});
const metadata = {
name: 'Pretix Payment Plugin',
description: 'Pretix Payment Plugin',
url: window.location.origin,
icons: ['https://avatars.githubusercontent.com/u/37784886']
}
const chains = [desiredChain[0].chain, desiredChain[0].chain];
const wagmiConfig = defaultWagmiConfig({ chains, projectId: walletConnectProjectId, appName: metadata.name })

GlobalPretixEthState.web3Modal = createWeb3Modal({
wagmiConfig, projectId: walletConnectProjectId, chains, themeMode: 'light'
})

// Web3Modal and Ethereum Client
const ethereumClient = new EthereumClient(wagmiClient, desiredChain);
GlobalPretixEthState.web3Modal = new Web3Modal(
{ projectId: walletConnectProjectId },
ethereumClient
);
GlobalPretixEthState.safeNetworkIdentifier = desiredChain[0].safeNetworkIdentifier;

let lastAccountStatus;
Expand Down
Loading

0 comments on commit 9509ad0

Please sign in to comment.