├── .env.sample ├── .eslintrc.json ├── .gitignore ├── LICENSE ├── README.md ├── auth.d.ts ├── components ├── Layout.tsx └── Meta.tsx ├── next-env.d.ts ├── next.config.js ├── package-lock.json ├── package.json ├── pages ├── _app.tsx ├── api │ ├── auth │ │ └── [...nextauth].ts │ ├── gates │ │ ├── access.ts │ │ ├── all.ts │ │ ├── create.ts │ │ └── delete.ts │ └── github │ │ ├── repo.ts │ │ └── repos.ts ├── index.tsx └── repo │ ├── create │ └── [owner] │ │ └── [repo].tsx │ └── join │ └── [id].tsx ├── prisma ├── db.ts ├── migrations │ ├── 20220405100937_initialize │ │ └── migration.sql │ └── migration_lock.toml └── schema.prisma ├── public ├── favicon.ico ├── logo.svg └── meta.png ├── styles ├── components │ └── Layout.module.scss ├── global.scss └── pages │ ├── Create.module.scss │ ├── Home.module.scss │ └── Join.module.scss └── tsconfig.json /.env.sample: -------------------------------------------------------------------------------- 1 | # Some sane defaults provided 2 | NEXTAUTH_URL="http://localhost:3000" 3 | NEXTAUTH_SECRET="NpUFdWakhCjbuIIogCvj" 4 | GITHUB_CLIENT_ID="" 5 | GITHUB_CLIENT_SECRET="" 6 | DATABASE_URL="postgresql://postgres:password@host:port" 7 | RPC_API="https://api.mycryptoapi.com/eth" -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals", 3 | "rules": { 4 | "@next/next/no-img-element": "off", 5 | "import/no-anonymous-default-export": "off" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.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 | 27 | # local env files 28 | .env 29 | .env.local 30 | .env.development.local 31 | .env.test.local 32 | .env.production.local 33 | 34 | # vercel 35 | .vercel -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |

GateRepo

3 |

4 |

5 | About 6 | | 7 | Implementation 8 | | 9 | License 10 |

11 | 12 | # About 13 | 14 | Simple implementation of ERC20 [token-gating](https://coinmetro.com/blog/what-is-token-gating/) GitHub repositories. 15 | 16 | Fueled by [Mike's tweet](https://twitter.com/mikedemarais/status/1511116843557306373?s=20&t=2LQ3BchO9bKAWVQsvphJbw). 17 | 18 | # Implementation 19 | 20 | 1. Users login with [GitHub OAuth](https://docs.github.com/en/developers/apps/building-oauth-apps/creating-an-oauth-app), we store their `access token` to take actions on their behalf. 21 | 2. Users can create new Gates for their repositories, specifying contract address, number of tokens needed, and number of invites to open. In the back-end, token name + decimals, and current latest block number is stored. 22 | 3. Users can share links to Gates. 23 | 4. Upon accessing a Gate invitation, users can sign-in with GitHub (again giving us their `access token`). Then, they connect their wallet and sign a message to verify ownership for our back-end. 24 | 5. Finally, in `/api/gates/access` we run a multi-step process: 25 | 1. Check that requesting user is authenticated 26 | 2. Check that all parameters have been posted (address, signature, gated repo ID) 27 | 3. Verify address ownership by matching address to signature 28 | 4. Check if gated repo by ID exists 29 | 5. Check if gated repo has available open invitations 30 | 6. Check if address held necessary balance at block number 31 | 7. Check if we have access token for requesting user 32 | 8. Check if requesting user is not already a collaborator on private repo 33 | 9. Check if we have access token for private repo owner 34 | 10. Send invite from owner to requesting user to join private repo 35 | 11. Accept invite from owner via requesting user to join private repo 36 | 12. Increment number of used invites (decreasing available slots) 37 | 38 | # Build and run locally 39 | 40 | ```bash 41 | # Collect repo 42 | git clone https://github.com/anish-agnihotri/GateRepo 43 | cd GateRepo 44 | 45 | # Install dependencies 46 | npm install 47 | 48 | # Update environment variables 49 | cp .env.sample .env 50 | vim .env 51 | 52 | # Run application 53 | npm run dev 54 | ``` 55 | 56 | ## Environment variables 57 | 58 | 1. `NEXTAUTH_URL`: Site link, `http://localhost:3000` if developing locally, `https://gaterepo.com` for this deployed instance 59 | 2. `NEXTAUTH_SECRET`: Any randomly generated string as a secret, e.g.: `NpUFdWakhCjbuIIogCvj` 60 | 3. `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET`: Follow the instructions [here](https://docs.github.com/en/developers/apps/building-oauth-apps/creating-an-oauth-app) for spinning up a new GitHub OAuth application. When asked, the authorization callback URL is `http://localhost:3000/api/auth/callback/github` (local) or `https://your_domain.com/api/auth/callback/github` (deployed). Once setup, your OAuth applications `Client ID` is your `GITHUB_CLIENT_ID` and your `Client Secret` is your `GITHUB_CLIENT_SECRET` 61 | 4. `DATABASE_URL`: Postgres database connection URL 62 | 5. `RPC_API`: Any Ethereum Mainnet JSON-RPC endpoint 63 | 64 | # Limitations 65 | 66 | 1. GitHub API has a rate-limit of sending a maximum of [50 invitations](https://octokit.github.io/rest.js/v18#repos-add-collaborator) for a repository per 24 hour period. 67 | 2. Application does not run a scheduled job to check continuing token ownership (to remove users who transfer their tokens). This is deferred to the user if desired functionality. 68 | 3. Application currently only supports [ERC20 tokens](https://ethereum.org/en/developers/docs/standards/tokens/erc-20/) but is easily extensible to other token formats by updating the snapshot strategy in `/pages/api/gates/access.ts`. 69 | 4. Allows a single address to verify token ownership on behalf of multiple GitHub users (not a one-to-one between GitHub users and addresses). Easily changeable should user require uniqueness by tracking address-to-gateId in database in `/pages/api/gates/access.ts`. 70 | 5. GitHub OAuth scopes are fairly invasive (`repo,read:user,user:email`). If you are privacy-aware, I'd recommended running your own fork or migrating to an app-based system? 71 | 72 | # License 73 | 74 | [GNU Affero GPL v3.0](https://github.com/Anish-Agnihotri/GateRepo/blob/master/LICENSE) 75 | -------------------------------------------------------------------------------- /auth.d.ts: -------------------------------------------------------------------------------- 1 | import "next-auth"; 2 | 3 | declare module "next-auth" { 4 | interface User { 5 | id: string; 6 | } 7 | 8 | interface Session { 9 | user: User; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /components/Layout.tsx: -------------------------------------------------------------------------------- 1 | import Link from "next/link"; // Routing 2 | import Meta from "components/Meta"; // Meta tags 3 | import styles from "styles/components/Layout.module.scss"; // Component styles 4 | import { useSession, signIn, signOut } from "next-auth/react"; // Auth 5 | 6 | // Types 7 | import type { Session } from "next-auth"; 8 | import type { ReactElement } from "react"; 9 | 10 | // Layout wrapper 11 | export default function Layout({ 12 | children, 13 | }: { 14 | children: ReactElement | ReactElement[]; 15 | }) { 16 | // Collect authenticated session 17 | const { data: session } = useSession(); 18 | 19 | return ( 20 |
21 | {/* Meta tags */} 22 | 23 | 24 | {/* Logo */} 25 | 26 | 27 | logo 28 | 29 | 30 | 31 | {!session ? ( 32 | // If unauthenticated, display unauthenticated 33 | 34 | ) : ( 35 | // If authentiated: 36 |
37 | {/* Render children */} 38 |
{children}
39 | 40 | {/* Auth status */} 41 | 42 |
43 | )} 44 | 45 | 46 |
47 | ); 48 | } 49 | 50 | // Sign in state 51 | export function Unauthenticated() { 52 | return ( 53 |
54 |

55 | GateRepo is a simple way to token gate access to 56 | private GitHub repositories. 57 |

58 | 59 |
60 | ); 61 | } 62 | 63 | // Authenticated state 64 | export function Authenticated({ session }: { session: Session }) { 65 | return ( 66 |
67 |
68 | Avatar 76 |

{session.user.name}

77 |
78 | 79 | {/* Name + Sign out */} 80 |
81 | 82 |
83 |
84 | ); 85 | } 86 | 87 | // Credits 88 | export function Credits() { 89 | return ( 90 |
91 |

92 | A quick{" "} 93 | 98 | hack 99 | {" "} 100 | by{" "} 101 | 106 | Anish Agnihotri 107 | 108 | . 109 |

110 |
111 | ); 112 | } 113 | -------------------------------------------------------------------------------- /components/Meta.tsx: -------------------------------------------------------------------------------- 1 | import Head from "next/head"; // HTML Head 2 | 3 | // Meta (w/ optional custom overrides) 4 | export default function Meta({ 5 | title, 6 | description, 7 | url, 8 | }: { 9 | title?: string; 10 | description?: string; 11 | url?: string; 12 | }) { 13 | // Custom overrides from page 14 | const siteTitle: string = 15 | title ?? "GateRepo - Token-gated GitHub Repositories"; 16 | const siteDescription: string = 17 | description ?? 18 | "GateRepo is a simple way to token gate access to private GitHub repositories."; 19 | const siteUrl: string = url ?? "https://gaterepo.com/"; 20 | 21 | return ( 22 | 23 | {/* Primary Meta Tags */} 24 | GateRepo — Token-gated GitHub Repositories 25 | 26 | 27 | 28 | {/* Open Graph + Facebook */} 29 | 30 | 31 | 32 | 33 | 34 | 35 | {/* Twitter */} 36 | 37 | 38 | 39 | 40 | 41 | 42 | {/* Favicon */} 43 | 44 | 45 | ); 46 | } 47 | -------------------------------------------------------------------------------- /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 | module.exports = { 3 | reactStrictMode: true, 4 | }; 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gaterepo", 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 | "@next-auth/prisma-adapter": "^1.0.3", 13 | "@octokit/rest": "^18.12.0", 14 | "@prisma/client": "^3.11.1", 15 | "@snapshot-labs/snapshot.js": "^0.1.10", 16 | "@web3-react/core": "^6.1.9", 17 | "@web3-react/injected-connector": "^6.0.7", 18 | "@web3-react/walletconnect-connector": "^6.2.13", 19 | "axios": "^0.26.1", 20 | "eth-sig-util": "^3.0.1", 21 | "ethereumjs-util": "^7.1.4", 22 | "ethers": "^5.6.2", 23 | "next": "12.1.4", 24 | "next-auth": "^4.3.1", 25 | "nextjs-progressbar": "^0.0.14", 26 | "prisma": "^3.11.1", 27 | "react": "18.0.0", 28 | "react-dom": "18.0.0", 29 | "react-loader-spinner": "^6.0.0-0", 30 | "react-toastify": "^8.2.0", 31 | "sass": "^1.49.11" 32 | }, 33 | "devDependencies": { 34 | "@types/node": "^17.0.23", 35 | "@types/react": "17.0.43", 36 | "eslint": "8.12.0", 37 | "eslint-config-next": "12.1.4", 38 | "typescript": "4.6.3" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import "styles/global.scss"; // Global styles 2 | import { providers } from "ethers"; // Ethers provider 3 | import "react-toastify/dist/ReactToastify.css"; // Toast styles 4 | import NextNProgress from "nextjs-progressbar"; // Progress bar 5 | import { ToastContainer } from "react-toastify"; // Toast container 6 | import { SessionProvider } from "next-auth/react"; // Session wrapper 7 | import { Web3ReactProvider } from "@web3-react/core"; // Web3 provider 8 | 9 | // Types 10 | import type { AppProps } from "next/app"; 11 | 12 | /** 13 | * Returns instantiated Ethers provider 14 | * @param provider from Web3React 15 | * @returns {providers.Web3Provider} ethers provider 16 | */ 17 | function getLibrary(provider: any): providers.Web3Provider { 18 | return new providers.Web3Provider(provider); 19 | } 20 | 21 | export default function GateRepo({ 22 | Component, 23 | pageProps: { session, ...pageProps }, 24 | }: AppProps) { 25 | return ( 26 | // Wrap page in session provider 27 | 28 | {/* Wrap page in Web3 provider */} 29 | 30 | {/* Progress bar */} 31 | 37 | 38 | {/* Page content */} 39 | 40 | 41 | {/* Toast notifications */} 42 | 43 | 44 | 45 | ); 46 | } 47 | -------------------------------------------------------------------------------- /pages/api/auth/[...nextauth].ts: -------------------------------------------------------------------------------- 1 | import db from "prisma/db"; // Database 2 | import NextAuth from "next-auth"; // Auth 3 | import GitHubProvider from "next-auth/providers/github"; // GitHub Auth 4 | import { PrismaAdapter } from "@next-auth/prisma-adapter"; // Auth => DB 5 | 6 | // Types 7 | import type { Account } from "@prisma/client"; 8 | 9 | /** 10 | * Refreshes GitHub access token on each login 11 | * @param {string} providerAccountId to update 12 | * @param {string} accessToken new token 13 | */ 14 | const updateAccessToken = async ( 15 | providerAccountId: string, 16 | accessToken: string 17 | ): Promise => { 18 | // Select account by GitHub provider id 19 | const selectionMetric = { 20 | provider_providerAccountId: { 21 | provider: "github", 22 | providerAccountId, 23 | }, 24 | }; 25 | 26 | // Check if account exists 27 | const account: Account | null = await db.account.findUnique({ 28 | where: selectionMetric, 29 | }); 30 | // If no account existing: 31 | if (!account) { 32 | // Return to let Prisma adapter initially process new user 33 | return; 34 | } 35 | 36 | await db.account.update({ 37 | where: selectionMetric, 38 | data: { 39 | // Update access token 40 | access_token: accessToken, 41 | }, 42 | }); 43 | }; 44 | 45 | export default NextAuth({ 46 | // Prisma DB 47 | adapter: PrismaAdapter(db), 48 | providers: [ 49 | // GitHub Auth 50 | GitHubProvider({ 51 | clientId: process.env.GITHUB_CLIENT_ID, 52 | clientSecret: process.env.GITHUB_CLIENT_SECRET, 53 | authorization: { 54 | params: { 55 | // Additional permissions: repo r/w 56 | scope: "repo,read:user,user:email", 57 | }, 58 | }, 59 | }), 60 | ], 61 | callbacks: { 62 | signIn: async ({ account }) => { 63 | // Update access token on fresh sign in 64 | if (account.access_token) { 65 | await updateAccessToken( 66 | account.providerAccountId, 67 | account.access_token 68 | ); 69 | } 70 | return true; 71 | }, 72 | session: async ({ session, user }) => { 73 | // Attach user id to session 74 | session.user.id = user.id; 75 | return session; 76 | }, 77 | }, 78 | }); 79 | -------------------------------------------------------------------------------- /pages/api/gates/access.ts: -------------------------------------------------------------------------------- 1 | import db from "prisma/db"; // DB 2 | import { ethers } from "ethers"; // Ethers 3 | import { Octokit } from "@octokit/rest"; // GitHub 4 | import { getSession } from "next-auth/react"; // Auth 5 | import snapshot from "@snapshot-labs/snapshot.js"; // Snapshot.js 6 | import { recoverPersonalSignature } from "eth-sig-util"; // Utils: Ethereum signature verification 7 | 8 | // Types 9 | import type { Gate, User } from "@prisma/client"; 10 | import type { NextApiRequest, NextApiResponse } from "next"; 11 | export type GateExtended = Gate & { creator: { name: string | null } }; 12 | 13 | // Ethers provider 14 | const provider = new ethers.providers.StaticJsonRpcProvider( 15 | process.env.RPC_API, 16 | 1 17 | ); 18 | 19 | // Enums 20 | enum Response { 21 | Exists = 200, 22 | Unknown = 404, 23 | } 24 | 25 | /** 26 | * Get gate from DB 27 | * @param {string} gateId to collect 28 | * @returns {Promise} gate, if exists, or null 29 | */ 30 | export const getGate = async (gateId: string): Promise => { 31 | return await db.gate.findUnique({ 32 | where: { 33 | id: gateId, 34 | }, 35 | include: { 36 | creator: { 37 | select: { 38 | name: true, 39 | }, 40 | }, 41 | }, 42 | }); 43 | }; 44 | 45 | /** 46 | * Collects number of contract tokens held by a user at specific snapshot blocknumber 47 | * @param {string} userAddress holder 48 | * @param {string} tokenAddress token contract 49 | * @param {string} tokenDecimals token decimals 50 | * @param {number} blockNumber snapshot number 51 | * @returns {Promise} number of tokens owned 52 | */ 53 | const collectVotesForToken = async ( 54 | userAddress: string, 55 | tokenAddress: string, 56 | tokenDecimals: number, 57 | blockNumber: number 58 | ): Promise => { 59 | // Collect balance of user 60 | const response = await snapshot.strategies["erc20-balance-of"]( 61 | "Count", // Any space 62 | // Network 63 | "1", 64 | // Ethers provider 65 | provider, 66 | // Voters 67 | [userAddress], 68 | // Token 69 | { 70 | address: tokenAddress, 71 | symbol: "Query", 72 | decimals: tokenDecimals, 73 | }, 74 | // Block number of snapshot 75 | blockNumber 76 | ); 77 | 78 | // If some token snapshot exists 79 | if (userAddress in response) { 80 | // Return token count 81 | return response[userAddress]; 82 | } else { 83 | // Else, return 0 tokens 84 | return 0; 85 | } 86 | }; 87 | 88 | export default async (req: NextApiRequest, res: NextApiResponse) => { 89 | // Check authentication 90 | const session = await getSession({ req }); 91 | if (!session || !session.user.id) { 92 | res.status(500).send({ error: "Not authenticated." }); 93 | return; 94 | } 95 | 96 | // Collect params 97 | const { 98 | address, // Ethereum address with tokens 99 | signature, // Signature verifying Ethereum address ownership 100 | gateId, // Gated repo ID 101 | }: { address: string; signature: string; gateId: string } = req.body; 102 | if (!address || !signature || !gateId) { 103 | res.status(500).send({ error: "Missing parameters." }); 104 | return; 105 | } 106 | 107 | // Verify address ownership 108 | const messageToVerify: string = `GateRepo: Verifying my address is ${address}`; 109 | const decodedAddress: string = recoverPersonalSignature({ 110 | data: messageToVerify, 111 | sig: signature, 112 | }); 113 | if (address.toLowerCase() !== decodedAddress.toLowerCase()) { 114 | res.status(500).send({ error: "Invalid address verification signature." }); 115 | return; 116 | } 117 | 118 | // Check if gated repo exists 119 | const gate = await db.gate.findUnique({ 120 | where: { 121 | id: gateId, 122 | }, 123 | include: { 124 | creator: { 125 | select: { 126 | accounts: { 127 | select: { 128 | access_token: true, 129 | }, 130 | }, 131 | }, 132 | }, 133 | }, 134 | }); 135 | if (!gate || !gate.id) { 136 | res.status(500).send({ error: "Gated repo no longer exists." }); 137 | return; 138 | } 139 | 140 | // Check if gated repo has available invite space 141 | const hasEmptyInvites: boolean = gate.numInvites - gate.usedInvites > 0; 142 | if (!hasEmptyInvites) { 143 | res.status(500).send({ error: "Gated repo has no more invites." }); 144 | return; 145 | } 146 | 147 | // Check if address held necessary tokens 148 | const numTokensHeld: number = await collectVotesForToken( 149 | address, 150 | gate.contract, 151 | gate.contractDecimals, 152 | gate.blockNumber 153 | ); 154 | if (gate.numTokens > numTokensHeld) { 155 | res.status(500).send({ error: "Insufficient token balance." }); 156 | return; 157 | } 158 | 159 | // Check if user exists 160 | const user: // User object 161 | | (User & { 162 | // + Array of access_tokens from accounts 163 | accounts: { 164 | access_token: string | null; 165 | }[]; 166 | }) 167 | | null = await db.user.findUnique({ 168 | where: { 169 | id: session.user.id, 170 | }, 171 | include: { 172 | accounts: { 173 | select: { 174 | access_token: true, 175 | }, 176 | }, 177 | }, 178 | }); 179 | // Collect access token 180 | const userAccessToken: string | null | undefined = 181 | user?.accounts[0].access_token; 182 | // Run checks 183 | if (!user || !userAccessToken) { 184 | res.status(500).send({ error: "Error retrieving GitHub user." }); 185 | } 186 | 187 | // Check if user is already part of repository 188 | let isExistingUser: boolean = false; 189 | const gh = new Octokit({ auth: userAccessToken }); 190 | try { 191 | // Check if user has access to repo 192 | const { status } = await gh.rest.repos.get({ 193 | owner: gate.repoOwner, 194 | repo: gate.repoName, 195 | }); 196 | // If status 200, repo exists 197 | if (status === Response.Exists) isExistingUser = true; 198 | } catch (e: any) { 199 | // Any thrown error implies no access to repo 200 | // Still, for good measure, we force to false 201 | if (e?.status && e?.status === Response.Unknown) { 202 | isExistingUser = false; 203 | } 204 | } 205 | if (isExistingUser) { 206 | res.status(500).send({ error: "User already has access to private repo." }); 207 | return; 208 | } 209 | 210 | // Check if owner access token exists 211 | const ownerAccessToken: string | null | undefined = 212 | gate.creator.accounts[0].access_token; 213 | if (!ownerAccessToken) { 214 | res.status(500).send({ erorr: "Private repo owner no longer exists." }); 215 | } 216 | 217 | // Send invite from owner to user to join repository 218 | let invitationId: number | null = null; 219 | try { 220 | const { 221 | // Collect username for requesting user (we only store account ID in db) 222 | data: { login: username }, 223 | }: { data: { login: string } } = await gh.rest.users.getAuthenticated(); 224 | // Configure owner Octokit instance 225 | const ownerGh = new Octokit({ auth: ownerAccessToken }); 226 | // Create new invite to user from owner 227 | const { 228 | data: { id }, 229 | }: { data: { id: number } } = await ownerGh.rest.repos.addCollaborator({ 230 | owner: gate.repoOwner, 231 | repo: gate.repoName, 232 | username, 233 | }); 234 | // If invitation id exists, update variable 235 | if (id) invitationId = id; 236 | } finally { 237 | // Check for existance, else throw (no catch via finally) 238 | if (!invitationId) { 239 | res 240 | .status(500) 241 | .send({ error: "Could not issue invite to join private repo." }); 242 | return; 243 | } 244 | } 245 | 246 | // Accept invite from user to join repository 247 | let acceptInviteSuccess: boolean = false; 248 | try { 249 | // Accept invitation by id 250 | const { status } = await gh.rest.repos.acceptInvitationForAuthenticatedUser( 251 | { 252 | invitation_id: invitationId, 253 | } 254 | ); 255 | // Confirm status is success 256 | if (status >= 200 && status <= 299) acceptInviteSuccess = true; 257 | } finally { 258 | // Check for success, else throw (no catch via finally) 259 | if (!acceptInviteSuccess) { 260 | res 261 | .status(500) 262 | .send({ error: "Could not accept invite to join private repo." }); 263 | return; 264 | } 265 | } 266 | 267 | /** 268 | * Increment number of used invites 269 | * FIXME: Technically, this is exploitable (blocking) assuming two+ users 270 | * send consecutive requests. Should be an increment at begining of function, 271 | * a revert in case of a 500, or a kept change if success. 272 | */ 273 | const { creator, ...rest } = gate; 274 | const newGate: Gate = await db.gate.update({ 275 | where: { 276 | id: gateId, 277 | }, 278 | data: { 279 | ...rest, 280 | usedInvites: rest.usedInvites + 1, 281 | }, 282 | }); 283 | // Ensure increment and return final success 284 | if (newGate.usedInvites <= gate.usedInvites) { 285 | res.status(500).send({ error: "Could not burn used invite." }); 286 | return; 287 | } else { 288 | // Else, throw final success 289 | res.status(200).send({ success: true }); 290 | return; 291 | } 292 | }; 293 | -------------------------------------------------------------------------------- /pages/api/gates/all.ts: -------------------------------------------------------------------------------- 1 | import db from "prisma/db"; // DB 2 | import { getSession } from "next-auth/react"; // Auth 3 | 4 | // Types 5 | import type { Gate } from "@prisma/client"; 6 | import type { NextApiRequest, NextApiResponse } from "next"; 7 | 8 | /** 9 | * Collects all gates created by user 10 | * @param {string} userId to check 11 | * @returns {Promise} all created gates 12 | */ 13 | export const getGatesByUser = async (userId: string): Promise => { 14 | return ( 15 | ( 16 | await db.gate.findMany({ 17 | where: { 18 | creatorId: userId, 19 | }, 20 | }) 21 | ) 22 | // Filter by unused 23 | .filter((v) => v.numInvites != v.usedInvites) 24 | // Sort by block number 25 | .sort((a, b) => b.blockNumber - a.blockNumber) 26 | ); 27 | }; 28 | 29 | export default async (req: NextApiRequest, res: NextApiResponse) => { 30 | // Check authentication 31 | const session = await getSession({ req }); 32 | if (!session || !session.user.id) { 33 | res.status(500).send({ error: "Not authenticated." }); 34 | return; 35 | } 36 | 37 | try { 38 | // Collect and send gates 39 | const gates: Gate[] = await getGatesByUser(session?.user.id ?? ""); 40 | res.status(200).send(gates); 41 | } catch (e) { 42 | // Else, return error 43 | res.status(500).send({ error: String(e) }); 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /pages/api/gates/create.ts: -------------------------------------------------------------------------------- 1 | import db from "prisma/db"; // DB 2 | import { ethers } from "ethers"; // Ethers 3 | import { getSession } from "next-auth/react"; // Auth 4 | import { getRepo } from "pages/api/github/repo"; // Repo 5 | import { isValidAddress } from "pages/repo/create/[owner]/[repo]"; // Validation 6 | 7 | // Types 8 | import type { Repo } from "pages/api/github/repos"; 9 | import type { NextApiRequest, NextApiResponse } from "next"; 10 | 11 | // Ethers provider 12 | const provider = new ethers.providers.StaticJsonRpcProvider( 13 | process.env.RPC_API, 14 | 1 15 | ); 16 | 17 | /** 18 | * Collects details about ERC20 token 19 | * @param {string} contractAddress token 20 | * @returns {Promise<{ name: string, decimals: number }>} ERC20 name + decimals 21 | */ 22 | const getERC20Details = async ( 23 | contractAddress: string 24 | ): Promise<{ name: string; decimals: number }> => { 25 | // Setup contract 26 | const contract = new ethers.Contract( 27 | contractAddress, 28 | [ 29 | "function name() public view returns (string memory)", 30 | "function decimals() public view returns (uint8)", 31 | ], 32 | provider 33 | ); 34 | 35 | // Get name and decimals 36 | const name: string = await contract.name(); 37 | const decimals: number = await contract.decimals(); 38 | return { name, decimals }; 39 | }; 40 | 41 | /** 42 | * Create new gated repository 43 | * @param {string} userId user 44 | * @param {string} owner of repository 45 | * @param {string} repo name 46 | * @param {string} contract address 47 | * @param {number} numTokens count 48 | * @param {number} numInvites count 49 | * @returns {Promise} gated repository id 50 | */ 51 | const createGatedRepo = async ( 52 | userId: string, 53 | owner: string, 54 | repo: string, 55 | contract: string, 56 | numTokens: number, 57 | numInvites: number 58 | ): Promise => { 59 | // Check if you have permission to repo 60 | const repository: Repo = await getRepo(userId, owner, repo); 61 | if (!repository) throw new Error("No access to repository."); 62 | 63 | // Collect ERC20 details 64 | const { name, decimals } = await getERC20Details(contract); 65 | // Collect latest block number to peg balance to 66 | const blockNumber: number = await provider.getBlockNumber(); 67 | 68 | // Create and return gated repo entry 69 | const { id }: { id: string } = await db.gate.create({ 70 | data: { 71 | repoOwner: owner, 72 | repoName: repo, 73 | blockNumber, 74 | contract, 75 | contractName: name, 76 | contractDecimals: decimals, 77 | numTokens, 78 | numInvites, 79 | creator: { 80 | connect: { 81 | id: userId, 82 | }, 83 | }, 84 | }, 85 | select: { 86 | id: true, 87 | }, 88 | }); 89 | return id; 90 | }; 91 | 92 | export default async (req: NextApiRequest, res: NextApiResponse) => { 93 | // Check authentication 94 | const session = await getSession({ req }); 95 | if (!session || !session.user.id) { 96 | res.status(500).send({ error: "Not authenticated." }); 97 | return; 98 | } 99 | 100 | // Collect body params and check for non-empty 101 | const { 102 | owner, 103 | repo, 104 | contract, 105 | tokens, 106 | invites, 107 | }: { 108 | owner: string; 109 | repo: string; 110 | contract: string; 111 | tokens: number; 112 | invites: number; 113 | } = req.body; 114 | if (!owner || !repo || !isValidAddress(contract) || !tokens || !invites) { 115 | res.status(500).send({ error: "Missing parameters." }); 116 | return; 117 | } 118 | 119 | try { 120 | // Create new gated repo 121 | const gateId: string = await createGatedRepo( 122 | session?.user.id ?? "", 123 | owner, 124 | repo, 125 | contract, 126 | tokens, 127 | invites 128 | ); 129 | res.status(200).send({ id: gateId }); 130 | } catch (e) { 131 | console.log(e); 132 | // Else, return error 133 | res.status(500).send({ error: String(e) }); 134 | } 135 | }; 136 | -------------------------------------------------------------------------------- /pages/api/gates/delete.ts: -------------------------------------------------------------------------------- 1 | import db from "prisma/db"; // DB 2 | import { getSession } from "next-auth/react"; // Auth 3 | 4 | // Types 5 | import type { NextApiRequest, NextApiResponse } from "next"; 6 | 7 | /** 8 | * Deletes a gate 9 | * @param {string} userId prompting deletion 10 | * @param {string} gateId to delete 11 | */ 12 | export const deleteGate = async ( 13 | userId: string, 14 | gateId: string 15 | ): Promise => { 16 | // Check if gate exists 17 | const gate = await db.gate.findUnique({ 18 | where: { 19 | id: gateId, 20 | }, 21 | select: { 22 | creatorId: true, 23 | }, 24 | }); 25 | if (!gate || !gate.creatorId) { 26 | throw new Error("Gate does not exist."); 27 | } 28 | 29 | // Check if user has deletion privelege 30 | if (userId !== gate.creatorId) { 31 | throw new Error("Not authenticated to delete gate."); 32 | } 33 | 34 | // Delete gate 35 | await db.gate.delete({ 36 | where: { 37 | id: gateId, 38 | }, 39 | }); 40 | }; 41 | 42 | export default async (req: NextApiRequest, res: NextApiResponse) => { 43 | // Check authentication 44 | const session = await getSession({ req }); 45 | if (!session || !session.user.id) { 46 | res.status(500).send({ error: "Not authenticated." }); 47 | return; 48 | } 49 | 50 | // Collect body params and check for non-empty 51 | const { 52 | id, 53 | }: { 54 | id: string; 55 | } = req.body; 56 | if (!id) { 57 | res.status(500).send({ error: "Missing parameters." }); 58 | return; 59 | } 60 | 61 | try { 62 | // Delete gate 63 | await deleteGate(session?.user.id ?? "", id); 64 | res.status(200).send({ deleted: true }); 65 | } catch (e) { 66 | // Else, return error 67 | res.status(500).send({ error: String(e) }); 68 | } 69 | }; 70 | -------------------------------------------------------------------------------- /pages/api/github/repo.ts: -------------------------------------------------------------------------------- 1 | import db from "prisma/db"; // DB 2 | import { Octokit } from "@octokit/rest"; // GitHub 3 | import { getSession } from "next-auth/react"; // Auth 4 | 5 | // Types 6 | import type { Repo } from "pages/api/github/repos"; 7 | import type { NextApiRequest, NextApiResponse } from "next"; 8 | 9 | /** 10 | * Collects single private repo 11 | * @param {string} userId authenticated user 12 | * @param {string} owner repo owner 13 | * @param {string} repo repo name 14 | * @returns {Promise} owned, private repo 15 | */ 16 | export const getRepo = async ( 17 | userId: string, 18 | owner: string, 19 | repo: string 20 | ): Promise => { 21 | // Collect GitHub access token for user 22 | const user = await db.user.findUnique({ 23 | where: { 24 | // Select by userId 25 | id: userId, 26 | }, 27 | select: { 28 | accounts: { 29 | select: { 30 | // Collect access token 31 | access_token: true, 32 | }, 33 | }, 34 | }, 35 | }); 36 | 37 | // Throw if no access token in db 38 | if (!user || !user.accounts[0].access_token) { 39 | throw new Error("User not found."); 40 | } 41 | 42 | // Setup Octokit 43 | const accessToken: string = user.accounts[0].access_token; 44 | const gh = new Octokit({ auth: accessToken }); 45 | 46 | // Get repo 47 | const { data: repository } = await gh.rest.repos.get({ 48 | owner, 49 | repo, 50 | }); 51 | 52 | // If no access to repository, throw 53 | if (!repository || !repository.permissions?.admin) { 54 | throw new Error("Repo does not exist or no access."); 55 | } 56 | 57 | return { 58 | fullName: repository.full_name, 59 | htmlURL: repository.html_url, 60 | }; 61 | }; 62 | 63 | export default async (req: NextApiRequest, res: NextApiResponse) => { 64 | // Check authentication 65 | const session = await getSession({ req }); 66 | if (!session || !session.user.id) { 67 | res.status(500).send({ error: "Not authenticated." }); 68 | return; 69 | } 70 | 71 | // Collect body params and check for non-empty 72 | const { owner, repo }: { owner: string; repo: string } = req.body; 73 | if (!owner || !repo) { 74 | res.status(500).send({ error: "Missing owner or repo." }); 75 | return; 76 | } 77 | 78 | try { 79 | // Collect and send repo 80 | const repository: Repo = await getRepo(session?.user.id ?? "", owner, repo); 81 | res.status(200).send(repository); 82 | } catch (e) { 83 | // Else, return error 84 | res.status(500).send({ error: String(e) }); 85 | } 86 | }; 87 | -------------------------------------------------------------------------------- /pages/api/github/repos.ts: -------------------------------------------------------------------------------- 1 | import db from "prisma/db"; // DB 2 | import { Octokit } from "@octokit/rest"; // GitHub 3 | import { getSession } from "next-auth/react"; // Auth 4 | 5 | // Types 6 | import type { NextApiRequest, NextApiResponse } from "next"; 7 | export type Repo = { 8 | fullName: string; 9 | htmlURL: string; 10 | }; 11 | 12 | /** 13 | * Collects all private repos owned by a user 14 | * @param {string} userId in database 15 | * @returns {Promise} list of owned, private repos 16 | */ 17 | export const getRepos = async (userId: string): Promise => { 18 | // Collect GitHub access token for user 19 | const user = await db.user.findUnique({ 20 | where: { 21 | // Select by userId 22 | id: userId, 23 | }, 24 | select: { 25 | accounts: { 26 | select: { 27 | // Collect access token 28 | access_token: true, 29 | }, 30 | }, 31 | }, 32 | }); 33 | 34 | // Throw if no access token in db 35 | if (!user || !user.accounts[0].access_token) { 36 | throw new Error("User not found."); 37 | } 38 | 39 | // Setup Octokit 40 | const accessToken: string = user.accounts[0].access_token; 41 | const gh = new Octokit({ auth: accessToken }); 42 | 43 | // Loop till all repos collected 44 | // (GH API enforces max 100 per page with no cursor) 45 | let lastPage = false; 46 | let sourceRepos = []; 47 | for (let i = 0; !lastPage; i++) { 48 | const { data } = await gh.rest.repos.listForAuthenticatedUser({ 49 | // Only private repos 50 | visibility: "private", 51 | // All repo affiliations 52 | affiliation: "owner,collaborator,organization_member", 53 | sort: "pushed", 54 | per_page: 100, 55 | page: i, 56 | }); 57 | // Append new repos 58 | sourceRepos.push(...data); 59 | 60 | // If no more repos, break 61 | if (data.length == 0) { 62 | lastPage = true; 63 | } 64 | } 65 | 66 | let repos: Repo[] = []; 67 | let repoExist: Record = {}; 68 | // Filter repos by admin & non-archive + non-disabled 69 | for (const repo of sourceRepos) { 70 | // Filter repos for duplicates 71 | // Occasionally, GitHub will duplicate API response on creating new repos 72 | if (repo.full_name in repoExist) { 73 | continue; 74 | } 75 | 76 | if (!repo.archived && !repo.disabled && repo.permissions?.admin) { 77 | repos.push({ 78 | fullName: repo.full_name, 79 | htmlURL: repo.html_url, 80 | }); 81 | // Update duplicates check 82 | repoExist[repo.full_name] = true; 83 | } 84 | } 85 | 86 | return repos; 87 | }; 88 | 89 | export default async (req: NextApiRequest, res: NextApiResponse) => { 90 | // Check authentication 91 | const session = await getSession({ req }); 92 | if (!session || !session.user.id) { 93 | res.status(500).send({ error: "Not authenticated." }); 94 | return; 95 | } 96 | 97 | try { 98 | // Collect and send repos 99 | const repos: Repo[] = await getRepos(session?.user.id ?? ""); 100 | res.status(200).send(repos); 101 | } catch (e) { 102 | // Else, return error 103 | res.status(500).send({ error: String(e) }); 104 | } 105 | }; 106 | -------------------------------------------------------------------------------- /pages/index.tsx: -------------------------------------------------------------------------------- 1 | import axios from "axios"; // Requests 2 | import { toast } from "react-toastify"; // Notifications 3 | import Layout from "components/Layout"; // Layout wrapper 4 | import { useRouter } from "next/router"; // Navigation 5 | import { useEffect, useState } from "react"; // State management 6 | import { getSession } from "next-auth/react"; // Auth 7 | import styles from "styles/pages/Home.module.scss"; // Page styles 8 | import { InfinitySpin } from "react-loader-spinner"; // Loader 9 | 10 | // Types 11 | import type { Gate } from "@prisma/client"; 12 | import type { Repo } from "pages/api/github/repos"; 13 | 14 | export default function Home({ userId }: { userId: string | null }) { 15 | // Routing 16 | const { push } = useRouter(); 17 | 18 | // Repos + Loading 19 | const [repos, setRepos] = useState([]); 20 | const [repoLoading, setRepoLoading] = useState(true); 21 | 22 | // Gates + loading 23 | const [gates, setGates] = useState([]); 24 | const [gateLoading, setGateLoading] = useState(true); 25 | 26 | /** 27 | * Collects all private repos where user has admin access 28 | */ 29 | const getAllRepos = async () => { 30 | setRepoLoading(true); // Toggle loading 31 | 32 | try { 33 | // Collect and store 34 | const { data } = await axios.get("/api/github/repos"); 35 | setRepos(data); 36 | } catch (e) { 37 | console.error(e); 38 | } 39 | 40 | setRepoLoading(false); // Toggle loading 41 | }; 42 | 43 | /** 44 | * Collects all gates 45 | */ 46 | const getGates = async () => { 47 | setGateLoading(true); // Toggle loading 48 | 49 | try { 50 | // Collect and store 51 | const { data } = await axios.get("/api/gates/all"); 52 | console.log(data); 53 | setGates(data); 54 | } catch (e) { 55 | console.error(e); 56 | } 57 | 58 | setGateLoading(false); // Toggle loading 59 | }; 60 | 61 | // On mount -> Collect repos if authenticated 62 | useEffect(() => { 63 | if (userId && repos.length == 0) { 64 | getAllRepos(); 65 | } 66 | }, [userId]); 67 | 68 | // On mount -> Collect gates if authenticated 69 | useEffect(() => { 70 | if (userId && gates.length == 0) { 71 | getGates(); 72 | } 73 | }, [userId]); 74 | 75 | return ( 76 | 77 |
78 | {/* All private repos */} 79 |

All Repos

80 |

Private repos you have admin access to:

81 |
82 | {repoLoading ? ( 83 | // Loading state 84 | 85 | ) : // All repos 86 | repos.length > 0 ? ( 87 | repos.map((repo: Repo, i: number) => { 88 | return ( 89 |
90 | {/* Repo name + link */} 91 | 96 | {repo.fullName} 97 | 98 | 99 | {/* Create gated repo */} 100 | 103 |
104 | ); 105 | }) 106 | ) : ( 107 | 108 | )} 109 |
110 | 111 | {/* Existing gated repos */} 112 |

Gated Repos

113 |

Active gates with unused invites:

114 |
115 | {gateLoading ? ( 116 | // Loading state 117 | 118 | ) : gates.length > 0 ? ( 119 | gates.map((gate: Gate, i: number) => { 120 | return ; 121 | }) 122 | ) : ( 123 | // Else, display empty 124 | 125 | )} 126 |
127 |
128 |
129 | ); 130 | } 131 | 132 | // Loading spinner 133 | function Loading() { 134 | return ( 135 |
136 | 137 |
138 | ); 139 | } 140 | 141 | // Empty placeholder 142 | function Empty() { 143 | return ( 144 |
145 |

No repos found

146 |
147 | ); 148 | } 149 | 150 | // Individual gate 151 | function IndividualGate({ 152 | gate, 153 | getGates, 154 | }: { 155 | gate: Gate; 156 | getGates: () => void; 157 | }) { 158 | const [copyText, setCopyText] = useState("Copy Invite"); // Copy button 159 | const [deleteLoading, setDeleteLoading] = useState(false); // Delete button loading 160 | 161 | const numUnusedInvites: number = gate.numInvites - gate.usedInvites; // Unused invites 162 | 163 | /** 164 | * Deletes gate 165 | * @param {string} gateId to delete 166 | */ 167 | const deleteGate = async (gateId: string) => { 168 | setDeleteLoading(true); // Toggle loading 169 | 170 | try { 171 | // Push delete 172 | await axios.post("/api/gates/delete", { id: gateId }); 173 | // Reload all gates 174 | await getGates(); 175 | // Toast success 176 | toast.success("Successfully deleted gate."); 177 | } catch (e) { 178 | // Else, log error 179 | console.error(e); 180 | toast.error("Error deleting gate."); 181 | } 182 | 183 | setDeleteLoading(false); // Toggle loading 184 | }; 185 | 186 | /** 187 | * Copy gateId to clipboard 188 | * @param {string} gateId to copy 189 | */ 190 | const copyInvite = (gateId: string) => { 191 | // Copy to clipboard 192 | navigator.clipboard.writeText(`https://gaterepo.com/repo/join/${gateId}`); 193 | 194 | // Update button 195 | setCopyText("Copied!"); 196 | setTimeout(() => setCopyText("Copy Invite"), 2000); 197 | }; 198 | 199 | /** 200 | * Formats number to us-en format (commas) 201 | * @param {number} num to format 202 | * @returns {string} formatted number 203 | */ 204 | const formatNumber = (num: number): string => { 205 | return num.toLocaleString("us-en"); 206 | }; 207 | 208 | return ( 209 |
210 | {/* Repository */} 211 | 220 | 221 | {/* Invite status */} 222 |
223 |

224 | Unused Invites: 225 | {formatNumber(numUnusedInvites)} 226 |

227 |

228 | Tokens Required: {formatNumber(gate.numTokens)}{" "} 229 | 234 | {gate.contractName} 235 | {" "} 236 | token{gate.numTokens == 1 ? "" : "s"} 237 |

238 |

239 | Token Check Block Number:{" "} 240 | 245 | #{formatNumber(gate.blockNumber)} 246 | 247 |

248 |
249 | 250 | {/* Actions */} 251 |
252 | 253 | 256 |
257 |
258 | ); 259 | } 260 | 261 | export async function getServerSideProps(context: any) { 262 | // Collect session, check auth 263 | const session = await getSession(context); 264 | 265 | return { 266 | props: { 267 | session, 268 | userId: session?.user.id ?? null, 269 | }, 270 | }; 271 | } 272 | -------------------------------------------------------------------------------- /pages/repo/create/[owner]/[repo].tsx: -------------------------------------------------------------------------------- 1 | import axios from "axios"; // Requests 2 | import { ethers } from "ethers"; // Ethers 3 | import { useState } from "react"; // State management 4 | import { toast } from "react-toastify"; // Toast notifications 5 | import Layout from "components/Layout"; // Layout wrapper 6 | import { useRouter } from "next/router"; // Navigation 7 | import { getSession } from "next-auth/react"; // Auth 8 | import { getRepo } from "pages/api/github/repo"; // Repo details 9 | import styles from "styles/pages/Create.module.scss"; // Page styles 10 | 11 | // Types 12 | import type { Repo } from "pages/api/github/repos"; 13 | 14 | /** 15 | * Check if a provided address is valid 16 | * @param {string} address to check 17 | * @returns {boolean} validity 18 | */ 19 | export function isValidAddress(address: string): boolean { 20 | try { 21 | // Check if address is valid + checksum match 22 | ethers.utils.getAddress(address); 23 | } catch { 24 | // If not, return false 25 | return false; 26 | } 27 | 28 | // Else, return true 29 | return true; 30 | } 31 | 32 | export default function Create({ 33 | owner, 34 | repository, 35 | repo, 36 | }: { 37 | owner: string; 38 | repository: string; 39 | repo: Repo; 40 | }) { 41 | // Routing 42 | const { push } = useRouter(); 43 | 44 | const [address, setAddress] = useState(""); // Contract address 45 | const [numTokens, setNumTokens] = useState(1); // Number of required tokens 46 | const [loading, setLoading] = useState(false); // Loading 47 | const [numParticipants, setNumParticipants] = useState(10); // Maximum invite count 48 | 49 | // Input validation 50 | const invalidAddress: boolean = !isValidAddress(address); 51 | const invalidNum: boolean = numTokens == 0 || numParticipants == 0; 52 | const invalidInput: boolean = invalidAddress || invalidNum; 53 | 54 | /** 55 | * Creates new gated repository 56 | */ 57 | const createGate = async () => { 58 | setLoading(true); // Toggle loading 59 | 60 | try { 61 | const { 62 | data: { id }, 63 | }: { data: { id: string } } = await axios.post(`/api/gates/create`, { 64 | owner, 65 | repo: repository, 66 | contract: address, 67 | tokens: numTokens, 68 | invites: numParticipants, 69 | }); 70 | // Copy invite to clipboard 71 | navigator.clipboard.writeText(`https://gaterepo.com/repo/join/${id}`); 72 | 73 | // Toast and return to home 74 | toast.success("Successfully created gated repository. Invite copied."); 75 | push("/"); 76 | } catch (e) { 77 | console.error(e); 78 | toast.error("Error when creating gated repository."); 79 | } 80 | 81 | setLoading(false); // Toggle loading 82 | }; 83 | 84 | return ( 85 | 86 |
87 | {/* Description */} 88 |

Token Gate

89 |

90 | Restricting access to{" "} 91 | 92 | @{repo.fullName} 93 | 94 | . 95 |

96 | 97 | {/* Input menu */} 98 |
99 | {/* Contract */} 100 | 101 | setAddress(e.target.value)} 107 | /> 108 | 109 | {/* Number of required tokens */} 110 | 111 | setNumTokens(Number(e.target.value))} 118 | /> 119 | 120 | {/* Max invite count */} 121 | 122 | setNumParticipants(Number(e.target.value))} 129 | /> 130 | 131 | {/* Create gated repository */} 132 | 144 |
145 |
146 |
147 | ); 148 | } 149 | 150 | export async function getServerSideProps(context: any) { 151 | // Collect session 152 | const session = await getSession(context); 153 | // Collect repo from URL 154 | const { owner, repo: repository }: { owner: string; repo: string } = 155 | context.query; 156 | 157 | try { 158 | // Throw if params not present 159 | if (!owner || !repository || !session || !session.user.id) 160 | throw new Error(); 161 | 162 | // Collect repo (check admin access) or throw 163 | const repo: Repo = await getRepo(session.user.id, owner, repository); 164 | if (!repo) throw new Error(); 165 | 166 | return { 167 | props: { 168 | owner, 169 | repository, 170 | repo, 171 | }, 172 | }; 173 | } catch { 174 | // On error, redirect 175 | return { 176 | redirect: { 177 | destination: "/", 178 | permanent: false, 179 | }, 180 | }; 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /pages/repo/join/[id].tsx: -------------------------------------------------------------------------------- 1 | import axios from "axios"; // Requests 2 | import Link from "next/link"; // Routing 3 | import { useState } from "react"; // State management 4 | import Meta from "components/Meta"; // Meta 5 | import { toast } from "react-toastify"; // Toast notifications 6 | import { bufferToHex } from "ethereumjs-util"; // Utils: Buffer => Hex 7 | import styles from "styles/pages/Join.module.scss"; // Page styles 8 | import { getSession, useSession } from "next-auth/react"; // Auth 9 | import { getGate, GateExtended } from "pages/api/gates/access"; // Gate details 10 | import layoutStyles from "styles/components/Layout.module.scss"; // Layout override styles 11 | import { Authenticated, Unauthenticated } from "components/Layout"; // Auth components 12 | 13 | // Web3 14 | import { useWeb3React } from "@web3-react/core"; 15 | import { InjectedConnector } from "@web3-react/injected-connector"; 16 | import { WalletConnectConnector } from "@web3-react/walletconnect-connector"; 17 | 18 | export default function Join({ gate }: { gate: GateExtended }) { 19 | // Collect authenticated session 20 | const { data: session } = useSession(); 21 | // Join loading 22 | const [joinLoading, setJoinLoading] = useState(false); 23 | // Web3React connection 24 | const [connectionStarted, setConnectionStarted] = useState(false); 25 | // Web3React setup 26 | const { active, account, activate, deactivate, library } = useWeb3React(); 27 | 28 | // Templated content 29 | const templateDescription: string = gate.creator.name 30 | ? // If creator name not null, personalize invitation 31 | `${gate.creator.name} has invited you to join their private @${gate.repoOwner}/${gate.repoName} repository.` 32 | : // Else, generalize invitation 33 | `You have been invited to join the private @${gate.repoOwner}/${gate.repoName} repository.`; 34 | 35 | /** 36 | * Formats number to us-en format (commas) 37 | * @param {number} num to format 38 | * @returns {string} formatted number 39 | */ 40 | const formatNumber = (num: number): string => { 41 | return num.toLocaleString("us-en"); 42 | }; 43 | 44 | /** 45 | * Connect metamask 46 | */ 47 | const connectMetaMask = () => { 48 | setConnectionStarted(true); 49 | activate( 50 | new InjectedConnector({ 51 | supportedChainIds: [1], 52 | }) 53 | ); 54 | setConnectionStarted(false); 55 | }; 56 | 57 | /** 58 | * Connect WalletConnect 59 | */ 60 | const connectWalletConnect = () => { 61 | setConnectionStarted(true); 62 | activate( 63 | new WalletConnectConnector({ 64 | rpc: { 1: process.env.NEXT_PUBLIC_RPC ?? "" }, 65 | }) 66 | ); 67 | setConnectionStarted(false); 68 | }; 69 | 70 | /** 71 | * Disconnect wallet 72 | */ 73 | const disconnectWallet = () => { 74 | deactivate(); 75 | setConnectionStarted(false); 76 | }; 77 | 78 | /** 79 | * Join private repository 80 | */ 81 | const joinRepo = async () => { 82 | setJoinLoading(true); // Toggle loading 83 | 84 | // Generate message to sign 85 | const message: string = bufferToHex( 86 | Buffer.from(`GateRepo: Verifying my address is ${account}`) 87 | ); 88 | 89 | let signature: string | null = null; 90 | try { 91 | // Request signature from wallet 92 | signature = await library.send("personal_sign", [message, account]); 93 | } catch (e) { 94 | // Throw error if user denied 95 | console.error(e); 96 | toast.error("Error: could not verify Ethereum account."); 97 | } 98 | 99 | // Revert if no signature 100 | if (!signature) { 101 | setJoinLoading(false); // Toggle loading 102 | return; 103 | } 104 | 105 | try { 106 | // Post data to access 107 | await axios.post("/api/gates/access", { 108 | address: account, 109 | signature, 110 | gateId: gate.id, 111 | }); 112 | 113 | // If successful, toast and redirect 114 | toast.success("Successfully joined private repository. Redirecting..."); 115 | setTimeout(() => { 116 | window.location.href = `https://github.com/${gate.repoOwner}/${gate.repoName}`; 117 | }, 2000); 118 | } catch (e: any) { 119 | // If error message, toast 120 | if (e?.response.data.error) { 121 | toast.error(`Error: ${e.response.data.error}`); 122 | } 123 | // Else, log all errors 124 | console.error(e); 125 | setJoinLoading(false); // Toggle loading 126 | } 127 | 128 | setJoinLoading(false); // Toggle loading 129 | }; 130 | 131 | return ( 132 |
133 | {/* Meta tags */} 134 | 139 | 140 | {/* Logo */} 141 | 142 | 143 | logo 144 | 145 | 146 | 147 |
148 | {/* Description */} 149 |

Private Repo Invitation

150 |

{templateDescription}

151 | 152 | {session && session.user.id && ( 153 | // If authenticated, allow connecting wallet 154 |
155 |

{!active ? "Connect Wallet" : "Join Repository"}

156 |

157 | Accessing this repository requires having held{" "} 158 | {formatNumber(gate.numTokens)}{" "} 159 | 164 | {gate.contractName} 165 | {" "} 166 | token{gate.numTokens == 1 ? "" : "s"} at block{" "} 167 | 172 | #{formatNumber(gate.blockNumber)} 173 | 174 | . 175 |

176 | 177 | {/* Connect wallet */} 178 | {!active ? ( 179 | // Not active 180 |
181 | 187 | 193 |
194 | ) : ( 195 | // Connected 196 |
197 | 202 | 208 |
209 | )} 210 |
211 | )} 212 | 213 | {/* GitHub Authentication state */} 214 | {!session || !session.user.id ? ( 215 | // Unauthenticated 216 | 217 | ) : ( 218 | // Authenticated 219 | 220 | )} 221 |
222 |
223 | ); 224 | } 225 | 226 | export async function getServerSideProps(context: any) { 227 | // Collect session 228 | const session = await getSession(context); 229 | // Collect gate id from URL 230 | const { id }: { id: string } = context.query; 231 | 232 | try { 233 | // Throw if params not present 234 | if (!id) throw new Error(); 235 | 236 | // Collect gate or throw 237 | const gate: GateExtended | null = await getGate(id); 238 | if (!gate) throw new Error(); 239 | 240 | // Validation 241 | const hasEmptyInvites: boolean = gate.numInvites - gate.usedInvites > 0; 242 | if (!hasEmptyInvites) throw new Error(); 243 | 244 | return { 245 | props: { 246 | gate, 247 | session, 248 | }, 249 | }; 250 | } catch { 251 | // On error, redirect 252 | return { 253 | redirect: { 254 | destination: "/", 255 | permanent: false, 256 | }, 257 | }; 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /prisma/db.ts: -------------------------------------------------------------------------------- 1 | import { PrismaClient } from "@prisma/client"; // Prisma 2 | 3 | // Export Prisma 4 | const db = new PrismaClient(); 5 | export default db; 6 | -------------------------------------------------------------------------------- /prisma/migrations/20220405100937_initialize/migration.sql: -------------------------------------------------------------------------------- 1 | -- CreateTable 2 | CREATE TABLE "Account" ( 3 | "id" TEXT NOT NULL, 4 | "userId" TEXT NOT NULL, 5 | "type" TEXT NOT NULL, 6 | "provider" TEXT NOT NULL, 7 | "providerAccountId" TEXT NOT NULL, 8 | "refresh_token" TEXT, 9 | "access_token" TEXT, 10 | "expires_at" INTEGER, 11 | "token_type" TEXT, 12 | "scope" TEXT, 13 | "id_token" TEXT, 14 | "session_state" TEXT, 15 | 16 | CONSTRAINT "Account_pkey" PRIMARY KEY ("id") 17 | ); 18 | 19 | -- CreateTable 20 | CREATE TABLE "Session" ( 21 | "id" TEXT NOT NULL, 22 | "sessionToken" TEXT NOT NULL, 23 | "userId" TEXT NOT NULL, 24 | "expires" TIMESTAMP(3) NOT NULL, 25 | 26 | CONSTRAINT "Session_pkey" PRIMARY KEY ("id") 27 | ); 28 | 29 | -- CreateTable 30 | CREATE TABLE "User" ( 31 | "id" TEXT NOT NULL, 32 | "name" TEXT, 33 | "email" TEXT, 34 | "emailVerified" TIMESTAMP(3), 35 | "image" TEXT, 36 | 37 | CONSTRAINT "User_pkey" PRIMARY KEY ("id") 38 | ); 39 | 40 | -- CreateTable 41 | CREATE TABLE "VerificationToken" ( 42 | "identifier" TEXT NOT NULL, 43 | "token" TEXT NOT NULL, 44 | "expires" TIMESTAMP(3) NOT NULL 45 | ); 46 | 47 | -- CreateTable 48 | CREATE TABLE "Gate" ( 49 | "id" TEXT NOT NULL, 50 | "creatorId" TEXT NOT NULL, 51 | "repoOwner" TEXT NOT NULL, 52 | "repoName" TEXT NOT NULL, 53 | "blockNumber" INTEGER NOT NULL, 54 | "contract" TEXT NOT NULL, 55 | "contractName" TEXT NOT NULL, 56 | "contractDecimals" INTEGER NOT NULL, 57 | "numTokens" DOUBLE PRECISION NOT NULL, 58 | "numInvites" INTEGER NOT NULL, 59 | "usedInvites" INTEGER NOT NULL DEFAULT 0, 60 | 61 | CONSTRAINT "Gate_pkey" PRIMARY KEY ("id") 62 | ); 63 | 64 | -- CreateIndex 65 | CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId"); 66 | 67 | -- CreateIndex 68 | CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken"); 69 | 70 | -- CreateIndex 71 | CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); 72 | 73 | -- CreateIndex 74 | CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token"); 75 | 76 | -- CreateIndex 77 | CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token"); 78 | 79 | -- AddForeignKey 80 | ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; 81 | 82 | -- AddForeignKey 83 | ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; 84 | 85 | -- AddForeignKey 86 | ALTER TABLE "Gate" ADD CONSTRAINT "Gate_creatorId_fkey" FOREIGN KEY ("creatorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 87 | -------------------------------------------------------------------------------- /prisma/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "postgresql" -------------------------------------------------------------------------------- /prisma/schema.prisma: -------------------------------------------------------------------------------- 1 | // This is your Prisma schema file, 2 | // learn more about it in the docs: https://pris.ly/d/prisma-schema 3 | 4 | generator client { 5 | provider = "prisma-client-js" 6 | } 7 | 8 | datasource db { 9 | provider = "postgresql" 10 | url = env("DATABASE_URL") 11 | } 12 | 13 | model Account { 14 | id String @id @default(cuid()) 15 | userId String 16 | type String 17 | provider String 18 | providerAccountId String 19 | refresh_token String? @db.Text 20 | access_token String? @db.Text 21 | expires_at Int? 22 | token_type String? 23 | scope String? 24 | id_token String? @db.Text 25 | session_state String? 26 | 27 | user User @relation(fields: [userId], references: [id], onDelete: Cascade) 28 | 29 | @@unique([provider, providerAccountId]) 30 | } 31 | 32 | model Session { 33 | id String @id @default(cuid()) 34 | sessionToken String @unique 35 | userId String 36 | expires DateTime 37 | user User @relation(fields: [userId], references: [id], onDelete: Cascade) 38 | } 39 | 40 | model User { 41 | id String @id @default(cuid()) 42 | name String? 43 | email String? @unique 44 | emailVerified DateTime? 45 | image String? 46 | accounts Account[] 47 | sessions Session[] 48 | gates Gate[] 49 | } 50 | 51 | model VerificationToken { 52 | identifier String 53 | token String @unique 54 | expires DateTime 55 | 56 | @@unique([identifier, token]) 57 | } 58 | 59 | model Gate { 60 | id String @id @default(cuid()) 61 | creatorId String 62 | repoOwner String 63 | repoName String 64 | blockNumber Int 65 | contract String 66 | contractName String 67 | contractDecimals Int 68 | numTokens Float 69 | numInvites Int 70 | usedInvites Int @default(0) 71 | creator User @relation(fields: [creatorId], references: [id]) 72 | } 73 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Anish-Agnihotri/GateRepo/d430483629d1ec59d78297f527ba0b62d08c6aff/public/favicon.ico -------------------------------------------------------------------------------- /public/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /public/meta.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Anish-Agnihotri/GateRepo/d430483629d1ec59d78297f527ba0b62d08c6aff/public/meta.png -------------------------------------------------------------------------------- /styles/components/Layout.module.scss: -------------------------------------------------------------------------------- 1 | // Layout wrapper 2 | .layout { 3 | min-width: 100vw; 4 | min-height: calc(100vh - 50px); 5 | display: flex; 6 | padding-top: 50px; 7 | 8 | flex-direction: column; 9 | align-items: center; 10 | 11 | // Logo 12 | > a { 13 | margin-bottom: 30px; 14 | 15 | > img { 16 | width: 250px; 17 | transition: 100ms ease-in-out; 18 | } 19 | 20 | &:hover { 21 | > img { 22 | opacity: 0.8; 23 | } 24 | } 25 | } 26 | 27 | h2 { 28 | color: var(--color-dark); 29 | margin: 0px; 30 | font-size: 14px; 31 | font-weight: 600; 32 | } 33 | } 34 | 35 | // Sizing 36 | .layout__main { 37 | display: flex; 38 | flex-direction: column; 39 | width: calc(100% - 32px); 40 | max-width: 432px; 41 | } 42 | 43 | // Authenticated 44 | .layout__main_auth { 45 | background-color: white; 46 | border: 1px solid var(--color-border); 47 | border-radius: 10px; 48 | display: flex; 49 | align-items: center; 50 | justify-content: space-between; 51 | text-align: right; 52 | padding: 10px; 53 | 54 | img { 55 | height: 30px; 56 | width: 30px; 57 | border-radius: 50%; 58 | } 59 | 60 | > div { 61 | display: flex; 62 | align-items: center; 63 | } 64 | 65 | h3 { 66 | margin: 0px; 67 | font-size: 14px; 68 | font-weight: 600; 69 | padding-left: 10px; 70 | } 71 | 72 | button { 73 | background-color: transparent; 74 | border: none; 75 | padding: 0px; 76 | text-decoration: underline; 77 | 78 | &:hover { 79 | opacity: 0.8; 80 | } 81 | } 82 | } 83 | 84 | // Unauthenticated 85 | .layout__unauthenticated { 86 | max-width: 432px; 87 | background-color: white; 88 | border: 1px solid var(--color-border); 89 | border-radius: 10px; 90 | padding: 20px; 91 | margin: 0px 16px; 92 | text-align: center; 93 | 94 | > p { 95 | color: var(--color-text-secondary); 96 | line-height: 1.5; 97 | margin-top: 0px; 98 | } 99 | 100 | > button { 101 | padding: 5px 12px; 102 | width: 100%; 103 | font-size: 12px; 104 | line-height: 20px; 105 | background-color: var(--color-button); 106 | border: 1px solid var(--color-border); 107 | border-radius: 6px; 108 | box-shadow: 0 1px 0 rgba(27, 31, 36, 0.04); 109 | transition: 100ms ease; 110 | 111 | &:hover { 112 | border-color: rgba(27, 31, 36, 0.15); 113 | background-color: var(--color-button-hover); 114 | } 115 | } 116 | } 117 | 118 | // Credits 119 | .layout__credit { 120 | margin-top: 20px; 121 | font-size: 14px; 122 | font-weight: 400; 123 | color: var(--color-text-secondary); 124 | 125 | a { 126 | text-decoration: underline; 127 | 128 | &:hover { 129 | opacity: 0.8; 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /styles/global.scss: -------------------------------------------------------------------------------- 1 | * { 2 | --color-dark: #24292f; 3 | --color-canvas: #f6f8fa; 4 | --color-border: #d0d7de; 5 | --color-button: #f4f5f7; 6 | --color-button-hover: #f3f4f6; 7 | --color-button-border: #1b1f2426; 8 | --color-text-invert: #ffffffb3; 9 | --color-text-primary: #24292f; 10 | --color-text-secondary: #57606a; 11 | 12 | // Green button 13 | --color-button-green: #2da44e; 14 | --color-button-green-hover: #2c974b; 15 | --color-button-green-disabled: #ffffffcc; 16 | --color-button-green-disabled-bg: #94d3a2; 17 | 18 | // Input 19 | --color-canvas-inset: #f6f8fa; 20 | } 21 | 22 | html, 23 | body { 24 | padding: 0; 25 | margin: 0; 26 | color: var(--color-text-primary); 27 | background-color: var(--color-canvas); 28 | font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, 29 | Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; 30 | } 31 | 32 | a { 33 | color: inherit; 34 | text-decoration: none; 35 | } 36 | 37 | * { 38 | box-sizing: border-box; 39 | } 40 | 41 | button { 42 | font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, 43 | Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; 44 | cursor: pointer; 45 | } 46 | 47 | input { 48 | font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, 49 | Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; 50 | } 51 | -------------------------------------------------------------------------------- /styles/pages/Create.module.scss: -------------------------------------------------------------------------------- 1 | // Sizing 2 | .create { 3 | > p { 4 | font-size: 15px; 5 | margin: 5px 0px 20px 0px; 6 | } 7 | 8 | > div { 9 | background-color: white; 10 | border: 1px solid var(--color-border); 11 | border-radius: 10px; 12 | margin-bottom: 30px; 13 | } 14 | } 15 | 16 | // Menu 17 | .create__menu { 18 | display: flex; 19 | flex-direction: column; 20 | 21 | label { 22 | font-size: 14px; 23 | font-weight: 600; 24 | margin: 10px 10px 5px 10px; 25 | } 26 | 27 | input { 28 | padding: 8px; 29 | font-size: 14px; 30 | background-color: var(--color-canvas-inset); 31 | border: 1px solid var(--color-button-border); 32 | border-radius: 5px; 33 | 34 | &:focus { 35 | background-color: white; 36 | } 37 | } 38 | 39 | input, 40 | button { 41 | margin: 0px 10px 0px 10px; 42 | } 43 | 44 | button { 45 | margin-top: 15px; 46 | margin-bottom: 10px; 47 | padding: 8px 10px; 48 | font-size: 14px; 49 | font-weight: 500; 50 | color: white; 51 | background-color: var(--color-button-green); 52 | border: 1px solid var(--color-button-border); 53 | border-radius: 6px; 54 | transition: 100ms ease; 55 | box-shadow: rgba(27, 31, 36, 0.1) 0px 1px 0px 0; 56 | 57 | &:hover { 58 | color: var(--color-button-hover); 59 | background-color: var(--color-button-green-hover); 60 | } 61 | 62 | &:disabled { 63 | cursor: not-allowed; 64 | color: var(--color-button-green-disabled); 65 | background-color: var(--color-button-green-disabled-bg); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /styles/pages/Home.module.scss: -------------------------------------------------------------------------------- 1 | // Sizing 2 | .home { 3 | > p { 4 | font-size: 15px; 5 | margin: 5px 0px 10px 0px; 6 | } 7 | 8 | > div { 9 | background-color: white; 10 | border: 1px solid var(--color-border); 11 | border-radius: 10px; 12 | margin-bottom: 30px; 13 | } 14 | } 15 | 16 | // Private repos 17 | .home__repo { 18 | max-height: 240px; 19 | overflow-y: scroll; 20 | } 21 | 22 | // Individual repo items 23 | .home__repo_item { 24 | margin: 10px; 25 | padding: 5px 10px; 26 | border-radius: 6px; 27 | background-color: var(--color-button-hover); 28 | display: flex; 29 | align-items: center; 30 | justify-content: space-between; 31 | border: 1px solid var(--color-border); 32 | 33 | a { 34 | font-size: 14px; 35 | font-weight: 600; 36 | max-width: 250px; 37 | white-space: nowrap; 38 | overflow: hidden; 39 | text-overflow: ellipsis; 40 | 41 | &:hover { 42 | opacity: 0.8; 43 | } 44 | } 45 | 46 | button { 47 | padding: 5px 10px; 48 | font-size: 14px; 49 | font-weight: 500; 50 | color: white; 51 | background-color: var(--color-button-green); 52 | border: 1px solid var(--color-button-border); 53 | border-radius: 6px; 54 | transition: 100ms ease; 55 | box-shadow: rgba(27, 31, 36, 0.1) 0px 1px 0px 0; 56 | 57 | &:hover { 58 | color: var(--color-button-hover); 59 | background-color: var(--color-button-green-hover); 60 | } 61 | 62 | &:disabled { 63 | cursor: not-allowed; 64 | color: var(--color-button-green-disabled); 65 | background-color: var(--color-button-green-disabled-bg); 66 | } 67 | } 68 | } 69 | 70 | // Loading state 71 | .home__loading { 72 | display: flex; 73 | flex-direction: column; 74 | align-items: center; 75 | 76 | > svg { 77 | transform: translateY(5px); 78 | } 79 | } 80 | 81 | // Empty state 82 | .home__empty { 83 | h3 { 84 | text-align: center; 85 | margin: 20px; 86 | font-size: 14px; 87 | font-weight: 500; 88 | color: var(--color-text-secondary); 89 | } 90 | } 91 | 92 | // Gates 93 | .home__gates { 94 | max-height: 240px; 95 | overflow-y: scroll; 96 | } 97 | 98 | // Gate item 99 | .home__gates_item { 100 | margin: 10px; 101 | border-radius: 6px; 102 | background-color: var(--color-button-hover); 103 | display: flex; 104 | flex-direction: column; 105 | align-items: center; 106 | border: 1px solid var(--color-border); 107 | 108 | > div:nth-of-type(1) { 109 | width: 100%; 110 | padding: 10px; 111 | border-bottom: 1px solid var(--color-border); 112 | 113 | > a { 114 | font-size: 14px; 115 | font-weight: 600; 116 | color: var(--color-dark); 117 | display: block; 118 | } 119 | } 120 | 121 | > div:nth-of-type(2) { 122 | width: 100%; 123 | padding: 10px; 124 | border-bottom: 1px solid var(--color-border); 125 | 126 | > p { 127 | margin: 3px 0px; 128 | font-size: 14px; 129 | color: var(--color-text-secondary); 130 | 131 | a { 132 | text-decoration: underline; 133 | 134 | &:hover { 135 | opacity: 0.8; 136 | } 137 | } 138 | } 139 | } 140 | 141 | > div:nth-of-type(3) { 142 | width: 100%; 143 | padding: 10px; 144 | display: flex; 145 | justify-content: space-between; 146 | 147 | button { 148 | width: 48%; 149 | padding: 7px 12px; 150 | border-radius: 6px; 151 | background-color: var(--color-button); 152 | border: 1px solid var(--color-border); 153 | box-shadow: 0 1px 0 rgba(27, 31, 36, 0.04); 154 | transition: 50ms ease-in-out; 155 | 156 | &:hover { 157 | opacity: 0.8; 158 | } 159 | 160 | &:disabled { 161 | cursor: not-allowed; 162 | } 163 | 164 | &:nth-of-type(2) { 165 | color: #cf222e; 166 | 167 | &:hover { 168 | opacity: 1; 169 | background-color: #cf222e; 170 | color: white; 171 | border-color: #cf222e; 172 | } 173 | 174 | &:disabled { 175 | opacity: 1; 176 | background-color: #cf222e; 177 | color: white; 178 | border-color: #cf222e; 179 | } 180 | } 181 | } 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /styles/pages/Join.module.scss: -------------------------------------------------------------------------------- 1 | // Sizing 2 | .join { 3 | display: flex; 4 | flex-direction: column; 5 | width: calc(100% - 32px); 6 | max-width: 432px; 7 | 8 | > h2 { 9 | text-align: center; 10 | font-size: 22px !important; 11 | } 12 | 13 | > p { 14 | font-size: 15px; 15 | text-align: center; 16 | margin: 5px 0px 20px 0px; 17 | line-height: 20px; 18 | } 19 | 20 | > div { 21 | background-color: white; 22 | border: 1px solid var(--color-border); 23 | border-radius: 10px; 24 | margin-bottom: 30px; 25 | } 26 | 27 | h3 { 28 | margin: 0px 10px 0px 0px; 29 | font-size: 14px; 30 | font-weight: 600; 31 | } 32 | } 33 | 34 | // Wallet 35 | .join__wallet { 36 | padding: 20px; 37 | 38 | h3 { 39 | text-align: center; 40 | font-size: 16px; 41 | font-weight: 600; 42 | } 43 | 44 | p { 45 | text-align: center; 46 | font-size: 14px; 47 | color: var(--color-text-secondary); 48 | line-height: 20px; 49 | margin-top: 5px; 50 | 51 | a { 52 | text-decoration: underline; 53 | 54 | &:hover { 55 | opacity: 0.8; 56 | } 57 | } 58 | } 59 | 60 | > div { 61 | display: flex; 62 | flex-direction: column; 63 | justify-content: space-between; 64 | height: 82px; 65 | padding-top: 10px; 66 | } 67 | } 68 | 69 | // Buttons 70 | .join__buttons_inactive { 71 | button { 72 | padding: 5px 12px; 73 | width: 100%; 74 | font-size: 14px; 75 | line-height: 20px; 76 | background-color: var(--color-button); 77 | border: 1px solid var(--color-border); 78 | border-radius: 6px; 79 | box-shadow: 0 1px 0 rgba(27, 31, 36, 0.04); 80 | transition: 100ms ease; 81 | 82 | &:hover { 83 | border-color: rgba(27, 31, 36, 0.15); 84 | background-color: var(--color-button-hover); 85 | } 86 | } 87 | } 88 | 89 | // Buttons - Active 90 | .join__buttons_active { 91 | height: 68px !important; 92 | 93 | button:nth-of-type(1) { 94 | padding: 5px 12px; 95 | font-size: 14px; 96 | font-weight: 500; 97 | color: white; 98 | line-height: 20px; 99 | background-color: var(--color-button-green); 100 | border: 1px solid var(--color-button-border); 101 | border-radius: 6px; 102 | transition: 100ms ease; 103 | box-shadow: rgba(27, 31, 36, 0.1) 0px 1px 0px 0; 104 | 105 | &:hover { 106 | color: var(--color-button-hover); 107 | background-color: var(--color-button-green-hover); 108 | } 109 | 110 | &:disabled { 111 | cursor: not-allowed; 112 | color: var(--color-button-green-disabled); 113 | background-color: var(--color-button-green-disabled-bg); 114 | } 115 | } 116 | 117 | button:nth-of-type(2) { 118 | background-color: transparent; 119 | border: none; 120 | font-size: 12px; 121 | text-decoration: underline; 122 | color: var(--color-text-secondary); 123 | 124 | &:hover { 125 | opacity: 0.8; 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /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 | "baseUrl": "./" 18 | }, 19 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], 20 | "exclude": ["node_modules"] 21 | } 22 | --------------------------------------------------------------------------------