Skip to content

Instantly share code, notes, and snippets.

@stevelukis
stevelukis / helper.py
Created December 16, 2021 03:02
A helper function to calculate Stripe service fee
service_fee_percentage = 2.9 / 100
service_fee_fixed = 30
def add_service_fee(price):
return (price + service_fee_fixed) / (1 - service_fee_percentage)
@stevelukis
stevelukis / views.py
Last active December 16, 2021 03:01
Checkout view
from django_stripe_integration import settings, helper #add helper
@method_decorator(csrf_exempt, name='dispatch')
class Checkout(generics.GenericAPIView):
def get(self, request, *args, **kwargs):
product_id = kwargs['product']
product = Product.objects.get(id=product_id)
price = int(product.price * 100)
domain_url = 'http://127.0.0.1:8000/'
stripe.api_key = settings.STRIPE_SECRET_KEY
@stevelukis
stevelukis / urls.py
Created December 16, 2021 02:53
Global urls
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from django_stripe_integration import settings, views
urlpatterns = [
path('admin/', admin.site.urls),
path('products/', include('product.urls')),
path('orders/', include('orders.urls')),
@stevelukis
stevelukis / views.py
Created December 16, 2021 02:50
StripeConfig view
@method_decorator(csrf_exempt, name='dispatch')
class StripeConfig(generics.GenericAPIView):
def get(self, request, *args, **kwargs):
stripe_config = {'publicKey': settings.STRIPE_PUBLISHABLE_KEY}
return JsonResponse(stripe_config, safe=False)
@stevelukis
stevelukis / index.tsx
Created December 10, 2021 07:49
Home component integrated with web3
import React, { useEffect, useState } from 'react';
import { Accordion, Alert, Button, Col, Container, Image, Row } from "react-bootstrap";
import { buyNFT, getMaxSupply, getTotalSupply } from "../../network/ethereum";
import { style } from "./Home.styles";
// Images
import Logo from '../../images/Logo.jpg';
type Props = {
currentAccount?: string;
@stevelukis
stevelukis / index.tsx
Created December 10, 2021 07:33
Header component of nft minting website
import React from 'react';
import { Button, Container, Nav, Navbar } from "react-bootstrap";
import { style } from './Header.styles'
import { Link } from "react-router-dom";
type Props = {
currentAccount?: string,
setCurrentAccount: React.Dispatch<React.SetStateAction<string | undefined>>
}
@stevelukis
stevelukis / useContract.ts
Created December 10, 2021 07:21
Hook to interact with smart contract
import { useEffect, useState } from "react";
import { getToken, getTokenUri } from "../network/ethereum";
type tokenMetadata = {
name: string,
description: string,
image: string,
edition: number
}
@stevelukis
stevelukis / useWallet.ts
Created December 10, 2021 07:18
Hook to interact with MetaMask
import { useState } from "react";
export const useWallet = () => {
const { ethereum } = window;
const [currentAccount, setCurrentAccount] = useState<string | undefined>(ethereum.selectedAddress);
// @ts-ignore
ethereum.on("accountsChanged", ([newAccount]) => {
console.log("accountsChanged: ", newAccount);
setCurrentAccount(newAccount);
@stevelukis
stevelukis / ethereum.ts
Created December 10, 2021 07:12
API to interact with the Ethereum network
import Web3 from 'web3';
import abi from '../contracts/abi.json';
import { AbiItem } from "web3-utils";
const rpcURL: string | undefined = process.env.REACT_APP_API_URL;
const web3 = new Web3(rpcURL!!);
const contractAddress = process.env.REACT_APP_CONTRACT_ADDRESS
const contract = new web3.eth.Contract(abi as AbiItem[], contractAddress);
@stevelukis
stevelukis / genImgPil04.py
Created December 7, 2021 04:09
import data from csv for generating image with text
import csv
from PIL import Image, ImageDraw, ImageFont
width = 512
height = 512
font = ImageFont.truetype("arial.ttf", size=20)
with open('data.csv', 'r') as f: