├── .env.example ├── .eslintrc.json ├── .gitignore ├── LICENSE.md ├── README.md ├── next-env.d.ts ├── next.config.js ├── package.json ├── pages ├── _app.tsx ├── api │ ├── auth │ │ └── [...thirdweb].ts │ └── generate-discount.ts └── index.tsx ├── public ├── favicon.ico └── thirdweb.svg ├── styles ├── Home.module.css └── globals.css └── tsconfig.json /.env.example: -------------------------------------------------------------------------------- 1 | ADMIN_PRIVATE_KEY=xxx # Private key of your wallet 2 | SHOPIFY_ACCESS_TOKEN=xxx # Your Shopify access token 3 | NFT_COLLECTION_ADDRESS=xxx # The address of your NFT Collection smart contract 4 | SHOPIFY_DISCOUNT_ID=xxx # Grab from here: https://xxx.myshopify.com/admin/discounts/ 5 | SHOPIFY_SITE_URL=xxx # Your Shopify site URL without the trailing / 6 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | .pnpm-debug.log* 27 | 28 | # local env files 29 | .env.local 30 | .env.development.local 31 | .env.test.local 32 | .env.production.local 33 | 34 | # vercel 35 | .vercel 36 | 37 | # typescript 38 | *.tsbuildinfo 39 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2021 Non-Fungible Labs, Inc 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Shopify Discount Codes for NFT Holders 2 | 3 | This template allows you to generate discount codes for your Shopify store to holders of your NFT Collection using [Auth](https://portal.thirdweb.com/auth). 4 | 5 | ## Using This Repo 6 | 7 | To create your own version of this template, you can use the following steps: 8 | 9 | Run this command from the terminal to clone this project and install the required dependencies: 10 | 11 | ```bash 12 | npx thirdweb create --template shopify-discount-codes 13 | ``` 14 | 15 | Create a copy of the `.env.example` file and rename it to `.env`. Then, fill in the values for the following environment variables: 16 | 17 | ```text 18 | ADMIN_PRIVATE_KEY=xxx 19 | NFT_COLLECTION_ADDRESS=xxx 20 | SHOPIFY_SECRET_KEY=xxx 21 | SHOPIFY_SITE_URL=xxx 22 | SHOPIFY_ACCESS_TOKEN=xxx 23 | ``` 24 | 25 | ## Guide 26 | 27 | This section explores the core elements of the code. 28 | 29 | ### Auth 30 | 31 | First, we setup thirdweb Auth by configuring our `ThirdwebProvider` in the `_app.tsx` file: 32 | 33 | ```tsx 34 | // This is the chain your dApp will work on. 35 | const activeChain = "polygon"; 36 | 37 | function MyApp({ Component, pageProps }: AppProps) { 38 | return ( 39 | 46 | 47 | 48 | ); 49 | } 50 | 51 | export default MyApp; 52 | ``` 53 | 54 | We also create an API route at `/api/auth/[...thirdweb].ts` that exports the `ThirdwebAuthHandler`: 55 | 56 | ```tsx 57 | import { ThirdwebAuth } from "@thirdweb-dev/auth/next"; 58 | 59 | export const { ThirdwebAuthHandler, getUser } = ThirdwebAuth({ 60 | // Using environment variables to secure your private key is a security vulnerability. 61 | // Learn how to store your private key securely: 62 | // https://portal.thirdweb.com/sdk/set-up-the-sdk/securing-your-private-key 63 | privateKey: process.env.ADMIN_PRIVATE_KEY || "", 64 | // Set this to your domain to prevent signature malleability attacks. 65 | domain: "example.com", 66 | }); 67 | 68 | // Export the handler to setup all your endpoints 69 | export default ThirdwebAuthHandler(); 70 | ``` 71 | 72 | Now, on the homepage at `index.tsx`, users can connect their wallet and sign a message that proves their identity using the `ConnectWallet` button: 73 | 74 | ```tsx 75 | const Home: NextPage = () => { 76 | return ( 77 | 83 | ); 84 | }; 85 | 86 | export default Home; 87 | ``` 88 | 89 | ### Generating Discount Codes 90 | 91 | On the client, we make a request to the `api/generate-discount.ts` API route in a `useEffect` block whenever the user signs in to the application: 92 | 93 | ```tsx 94 | const Home: NextPage = () => { 95 | const user = useUser(); 96 | 97 | const [generatedDiscount, setGeneratedDiscount] = useState(""); 98 | 99 | async function generateDiscount() { 100 | try { 101 | const response = await fetch("/api/generate-discount", { 102 | method: "POST", 103 | headers: { 104 | "Content-Type": "application/json", 105 | }, 106 | }); 107 | 108 | const { discountCode } = await response.json(); 109 | 110 | setGeneratedDiscount(discountCode); 111 | } catch (error) { 112 | console.error(error); 113 | setGeneratedDiscount("Not eligible for discount"); 114 | } 115 | } 116 | 117 | // Whenever the `user` is available, call the generateDiscount function. 118 | useEffect(() => { 119 | if (user.user?.address) { 120 | generateDiscount(); 121 | } 122 | }, [user.user?.address]); 123 | }; 124 | ``` 125 | 126 | This API route interacts with the Shopify API to generate a discount code for the user after checking their NFT balance. 127 | 128 | First, we're going to ensure the user has signed in with their wallet: 129 | 130 | ```tsx 131 | // Load environment variables 132 | const { 133 | SHOPIFY_SITE_URL, 134 | SHOPIFY_ACCESS_TOKEN, 135 | NFT_COLLECTION_ADDRESS, 136 | SHOPIFY_DISCOUNT_ID, 137 | } = process.env; 138 | 139 | // Grab the current thirdweb auth user (wallet address) 140 | const thirdwebUser = await getUser(req); 141 | // If there is no user, return an error 142 | if (!thirdwebUser) { 143 | return res.status(401).json({ error: "Unauthorized" }); 144 | } 145 | ``` 146 | 147 | Next, we'll connect to the thirdweb SDK and check the balance of the authenticated wallet: 148 | 149 | ```js 150 | // Initialize the SDK to check the user's balance 151 | const sdk = new ThirdwebSDK("goerli"); 152 | 153 | // Check the user's balance 154 | const edition = await sdk.getEdition(NFT_COLLECTION_ADDRESS!); 155 | // Here, we're checking token ID 0 specifically, just as an example. 156 | const balance = await edition.balanceOf(thirdwebUser.address, 0); 157 | 158 | // If the user doesn't own any NFTs, return an error 159 | if (balance.eq(0)) { 160 | return res.status(401).json({ error: "Unauthorized" }); 161 | } 162 | ``` 163 | 164 | If they aren't authenticated or don't own any NFTs from the collection, we send them a `401 unauthorized response` and don't generate a discount code for them. 165 | 166 | Finally, if they _do_ own an NFT, we can make a `POST` request to Shopify to generate a discount code for them: 167 | 168 | ```js 169 | // Create a new client for the specified shop. 170 | const client = new Shopify.Clients.Rest( 171 | SHOPIFY_SITE_URL!, 172 | SHOPIFY_ACCESS_TOKEN! 173 | ); 174 | 175 | // Create a new discount code with the Shopify API 176 | const response = await client.post({ 177 | type: DataType.JSON, 178 | path: `/admin/api/2022-10/price_rules/${SHOPIFY_DISCOUNT_ID}/discount_codes.json`, 179 | data: { 180 | discount_code: { 181 | code: thirdwebUser.address, 182 | usage_count: 1, 183 | }, 184 | }, 185 | }); 186 | 187 | res 188 | .status(200) 189 | .json({ discountCode: response.body.discount_code.code as string }); 190 | ``` 191 | 192 | ## Join our Discord! 193 | 194 | For any questions or suggestions, join our discord at [https://discord.gg/thirdweb](https://discord.gg/thirdweb). 195 | -------------------------------------------------------------------------------- /next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | reactStrictMode: true, 4 | } 5 | 6 | module.exports = nextConfig 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "next-typescript-starter", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "@shopify/shopify-api": "^5.1.0", 13 | "@thirdweb-dev/auth": "^2.0.11", 14 | "@thirdweb-dev/react": "^3", 15 | "@thirdweb-dev/sdk": "^3", 16 | "ethers": "^5.6.8", 17 | "next": "^13", 18 | "react": "^18.2.0", 19 | "react-dom": "^18.2.0" 20 | }, 21 | "devDependencies": { 22 | "@types/node": "^18.11.12", 23 | "@types/react": "^18.0.26", 24 | "eslint": "^8.29.0", 25 | "eslint-config-next": "^13", 26 | "typescript": "^4.9.2" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import type { AppProps } from "next/app"; 2 | import { ChainId, ThirdwebProvider } from "@thirdweb-dev/react"; 3 | import "../styles/globals.css"; 4 | 5 | // This is the chain your dApp will work on. 6 | const activeChain = "polygon"; 7 | 8 | function MyApp({ Component, pageProps }: AppProps) { 9 | return ( 10 | 17 | 18 | 19 | ); 20 | } 21 | 22 | export default MyApp; 23 | -------------------------------------------------------------------------------- /pages/api/auth/[...thirdweb].ts: -------------------------------------------------------------------------------- 1 | import { ThirdwebAuth } from "@thirdweb-dev/auth/next"; 2 | 3 | export const { ThirdwebAuthHandler, getUser } = ThirdwebAuth({ 4 | // Using environment variables to secure your private key is a security vulnerability. 5 | // Learn how to store your private key securely: 6 | // https://portal.thirdweb.com/sdk/set-up-the-sdk/securing-your-private-key 7 | privateKey: process.env.ADMIN_PRIVATE_KEY || "", 8 | // Set this to your domain to prevent signature malleability attacks. 9 | domain: "example.com", 10 | }); 11 | 12 | // Export the handler to setup all your endpoints 13 | export default ThirdwebAuthHandler(); 14 | -------------------------------------------------------------------------------- /pages/api/generate-discount.ts: -------------------------------------------------------------------------------- 1 | // This API Route uses the Shopify API to generate a discount code for a customer 2 | // First, it checks to see if they own an NFT from a specific collection before generating a discount code 3 | import { ThirdwebSDK } from "@thirdweb-dev/sdk"; 4 | import type { NextApiRequest, NextApiResponse } from "next"; 5 | import { getUser } from "./auth/[...thirdweb]"; 6 | import Shopify, { DataType } from "@shopify/shopify-api"; 7 | 8 | export default async function generateDiscount( 9 | req: NextApiRequest, 10 | res: NextApiResponse 11 | ) { 12 | // Load environment variables 13 | const { 14 | SHOPIFY_SITE_URL, 15 | SHOPIFY_ACCESS_TOKEN, 16 | NFT_COLLECTION_ADDRESS, 17 | SHOPIFY_DISCOUNT_ID, 18 | } = process.env; 19 | 20 | // Grab the current thirdweb auth user (wallet address) 21 | const thirdwebUser = await getUser(req); 22 | // If there is no user, return an error 23 | if (!thirdwebUser) { 24 | return res.status(401).json({ error: "Unauthorized" }); 25 | } 26 | 27 | // Initialize the SDK to check the user's balance 28 | const sdk = new ThirdwebSDK("goerli"); 29 | 30 | // Check the user's balance 31 | const edition = await sdk.getEdition(NFT_COLLECTION_ADDRESS!); 32 | // Here, we're checking token ID 0 specifically, just as an example. 33 | const balance = await edition.balanceOf(thirdwebUser.address, 0); 34 | 35 | // If the user doesn't own any NFTs, return an error 36 | if (balance.eq(0)) { 37 | return res.status(401).json({ error: "Unauthorized" }); 38 | } 39 | 40 | // Create a new client for the specified shop. 41 | const client = new Shopify.Clients.Rest( 42 | SHOPIFY_SITE_URL!, 43 | SHOPIFY_ACCESS_TOKEN! 44 | ); 45 | 46 | // Create a new discount code with the Shopify API 47 | const response = await client.post({ 48 | type: DataType.JSON, 49 | path: `/admin/api/2022-10/price_rules/${SHOPIFY_DISCOUNT_ID}/discount_codes.json`, 50 | data: { 51 | discount_code: { 52 | code: thirdwebUser.address, 53 | usage_count: 1, 54 | }, 55 | }, 56 | }); 57 | 58 | res 59 | .status(200) 60 | .json({ discountCode: response.body.discount_code.code as string }); 61 | } 62 | -------------------------------------------------------------------------------- /pages/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import { ConnectWallet, useUser } from "@thirdweb-dev/react"; 3 | import type { NextPage } from "next"; 4 | import styles from "../styles/Home.module.css"; 5 | 6 | const Home: NextPage = () => { 7 | const user = useUser(); 8 | 9 | const [generatedDiscount, setGeneratedDiscount] = useState(""); 10 | 11 | async function generateDiscount() { 12 | try { 13 | const response = await fetch("/api/generate-discount", { 14 | method: "POST", 15 | headers: { 16 | "Content-Type": "application/json", 17 | }, 18 | }); 19 | 20 | const { discountCode } = await response.json(); 21 | 22 | setGeneratedDiscount(discountCode); 23 | } catch (error) { 24 | console.error(error); 25 | setGeneratedDiscount("Not eligible for discount"); 26 | } 27 | } 28 | 29 | // Whenever the `user` is available, call the generateDiscount function. 30 | useEffect(() => { 31 | if (user.user?.address) { 32 | generateDiscount(); 33 | } 34 | }, [user.user?.address]); 35 | 36 | return ( 37 |
38 |
39 | 45 |
46 | 47 | {generatedDiscount && ( 48 |

49 | Your discount code is: {generatedDiscount} 50 |

51 | )} 52 |
53 | ); 54 | }; 55 | 56 | export default Home; 57 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thirdweb-example/shopify-discount-codes/9508761d17b81e697a8d548625b7a3b572e80a31/public/favicon.ico -------------------------------------------------------------------------------- /public/thirdweb.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /styles/Home.module.css: -------------------------------------------------------------------------------- 1 | .container { 2 | width: 100%; 3 | height: 95vh; 4 | display: flex; 5 | align-items: center; 6 | justify-content: center; 7 | flex-direction: column; 8 | padding: 0 2rem; 9 | } 10 | 11 | .main { 12 | min-height: 100vh; 13 | padding: 4rem 0; 14 | flex: 1; 15 | display: flex; 16 | flex-direction: column; 17 | justify-content: center; 18 | align-items: center; 19 | } 20 | 21 | .title a { 22 | color: #f213a4; 23 | text-decoration: none; 24 | } 25 | 26 | .title a:hover, 27 | .title a:focus, 28 | .title a:active { 29 | text-decoration: underline; 30 | } 31 | 32 | .title { 33 | margin: 0; 34 | line-height: 1.15; 35 | font-size: 4rem; 36 | } 37 | 38 | .title, 39 | .description { 40 | text-align: center; 41 | } 42 | 43 | .connect { 44 | margin-bottom: 2rem; 45 | width: 230px; 46 | } 47 | 48 | .description { 49 | margin-top: 3rem; 50 | margin-bottom: 2rem; 51 | line-height: 1.5; 52 | font-size: 1.5rem; 53 | } 54 | 55 | .code { 56 | background: #fafafa; 57 | border-radius: 5px; 58 | padding: 0.75rem; 59 | font-size: 1.1rem; 60 | font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, 61 | Bitstream Vera Sans Mono, Courier New, monospace; 62 | } 63 | 64 | .grid { 65 | display: flex; 66 | align-items: center; 67 | justify-content: center; 68 | flex-wrap: wrap; 69 | max-width: 1200px; 70 | } 71 | 72 | .card { 73 | background-color: #1b2129; 74 | margin: 1rem; 75 | padding: 1.5rem; 76 | text-align: left; 77 | color: inherit; 78 | text-decoration: none; 79 | border: 1px solid #eaeaea; 80 | border-radius: 10px; 81 | transition: color 0.15s ease, border-color 0.15s ease; 82 | max-width: 350px; 83 | } 84 | 85 | .card:hover, 86 | .card:focus, 87 | .card:active { 88 | background-color: #272c34; 89 | color: #0ea5e9; 90 | border-color: #0ea5e9; 91 | } 92 | 93 | .card h2 { 94 | margin: 0 0 1rem 0; 95 | font-size: 1.5rem; 96 | } 97 | 98 | .card p { 99 | margin: 0; 100 | font-size: 1.25rem; 101 | line-height: 1.5; 102 | } 103 | 104 | .logo { 105 | height: 1em; 106 | margin-left: 0.5rem; 107 | } 108 | 109 | .buttonContainer { 110 | width: 256px; 111 | } 112 | 113 | @media (max-width: 600px) { 114 | .grid { 115 | width: 100%; 116 | flex-direction: column; 117 | } 118 | } 119 | 120 | @media (prefers-color-scheme: dark) { 121 | .card, 122 | .footer { 123 | border-color: #222; 124 | } 125 | .code { 126 | background: #111; 127 | } 128 | .logo img { 129 | filter: invert(1); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /styles/globals.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | padding: 0; 4 | margin: 0; 5 | font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, 6 | Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; 7 | } 8 | 9 | a { 10 | color: #7dd3fc; 11 | text-decoration: none; 12 | } 13 | 14 | * { 15 | box-sizing: border-box; 16 | } 17 | 18 | @media (prefers-color-scheme: dark) { 19 | html { 20 | color-scheme: dark; 21 | } 22 | body { 23 | color: #e7e8e8; 24 | background: #0f1318; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "esModuleInterop": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "jsx": "preserve", 16 | "incremental": true 17 | }, 18 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], 19 | "exclude": ["node_modules"] 20 | } 21 | --------------------------------------------------------------------------------