├── .gitignore ├── GIT_PUSH.bat ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── loading.gif ├── loading1.gif ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.test.tsx ├── App.tsx ├── asset │ └── video │ │ ├── drawn.mp4 │ │ ├── winhalos.mp4 │ │ └── winhorns.mp4 ├── bootstrap.min.css ├── declare.d.ts ├── index.css ├── index.tsx ├── logo.svg ├── pages │ ├── Loading.tsx │ ├── notify.tsx │ ├── solana_anchor.json │ └── stake.tsx ├── react-app-env.d.ts ├── reportWebVitals.ts ├── setupTests.ts └── wallet │ ├── connect.tsx │ ├── disconnect.tsx │ └── index.ts └── tsconfig.json /.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 | /build.zip 11 | 12 | # production 13 | /build 14 | 15 | # misc 16 | .DS_Store 17 | .env.local 18 | .env.development.local 19 | .env.test.local 20 | .env.production.local 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | -------------------------------------------------------------------------------- /GIT_PUSH.bat: -------------------------------------------------------------------------------- 1 | git init 2 | git add . 3 | git commit -m "first commit" 4 | git branch -M main 5 | git remote add origin https://github.com/mymiracle0118/solana_staking_frontend.git 6 | git push -u origin main -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # solana_staking_frontend -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@craco/craco": "^6.4.2", 7 | "@emotion/react": "^11.5.0", 8 | "@emotion/styled": "^11.3.0", 9 | "@headlessui/react": "^1.4.1", 10 | "@metaplex/js": "^3.3.0", 11 | "@mui/lab": "^5.0.0-alpha.57", 12 | "@mui/material": "^5.0.6", 13 | "@mui/styled-engine": "^5.2.0", 14 | "@project-serum/anchor": "^0.18.2", 15 | "@project-serum/sol-wallet-adapter": "^0.2.5", 16 | "@solana/spl-token": "^0.1.8", 17 | "@solana/spl-token-registry": "^0.2.2585", 18 | "@solana/wallet-adapter-base": "^0.7.0", 19 | "@solana/wallet-adapter-react": "^0.13.1", 20 | "@solana/wallet-adapter-react-ui": "^0.6.1", 21 | "@solana/wallet-adapter-wallets": "^0.11.3", 22 | "@solana/wallet-base": "0.0.1", 23 | "@solana/web3.js": "^1.31.0", 24 | "@testing-library/jest-dom": "^5.14.1", 25 | "@testing-library/react": "^11.2.7", 26 | "@testing-library/user-event": "^12.8.3", 27 | "@types/jest": "^26.0.24", 28 | "@types/node": "^12.20.25", 29 | "@types/react": "^17.0.22", 30 | "@types/react-dom": "^17.0.9", 31 | "antd": "^4.16.13", 32 | "axios": "^0.24.0", 33 | "bootstrap": "^5.1.1", 34 | "borsh": "^0.6.0", 35 | "bs58": "^4.0.1", 36 | "buffer": "^6.0.3", 37 | "buffer-layout": "^1.2.2", 38 | "moment": "^2.29.1", 39 | "mz": "^2.7.0", 40 | "notistack": "^2.0.3", 41 | "os": "^0.1.2", 42 | "oyster": "^0.2.0", 43 | "path": "^0.12.7", 44 | "react": "^17.0.2", 45 | "react-bootstrap": "^2.2.1", 46 | "react-dom": "^17.0.2", 47 | "react-icons": "^4.3.1", 48 | "react-scripts": "4.0.3", 49 | "typescript": "^4.4.3", 50 | "web-vitals": "^1.1.2", 51 | "yaml": "^1.10.2" 52 | }, 53 | "scripts": { 54 | "start": "react-scripts start", 55 | "build": "react-scripts build", 56 | "test": "react-scripts test", 57 | "eject": "react-scripts eject" 58 | }, 59 | "eslintConfig": { 60 | "extends": [ 61 | "react-app", 62 | "react-app/jest" 63 | ] 64 | }, 65 | "browserslist": { 66 | "production": [ 67 | ">0.2%", 68 | "not dead", 69 | "not op_mini all" 70 | ], 71 | "development": [ 72 | "last 1 chrome version", 73 | "last 1 firefox version", 74 | "last 1 safari version" 75 | ] 76 | }, 77 | "devDependencies": { 78 | "@types/bs58": "^4.0.1", 79 | "@types/mz": "^2.7.4" 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VeteranSoftDev/solana_staking_frontend/587e199ce66ac8427b9c2032792adef81f85d939/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 13 | 14 | 18 | 19 | 28 | HVH Staking 29 | 30 | 31 | 32 |
33 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /public/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VeteranSoftDev/solana_staking_frontend/587e199ce66ac8427b9c2032792adef81f85d939/public/loading.gif -------------------------------------------------------------------------------- /public/loading1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VeteranSoftDev/solana_staking_frontend/587e199ce66ac8427b9c2032792adef81f85d939/public/loading1.gif -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VeteranSoftDev/solana_staking_frontend/587e199ce66ac8427b9c2032792adef81f85d939/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VeteranSoftDev/solana_staking_frontend/587e199ce66ac8427b9c2032792adef81f85d939/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | 40 | #load_div { 41 | position: fixed; 42 | display: flex; 43 | flex-direction: column; 44 | justify-content: center; 45 | top: 0px; 46 | left: 0px; 47 | z-index: 10; 48 | width: 100vw; 49 | height: 100vh; 50 | text-align: center; 51 | background: white; 52 | opacity: 0.5; 53 | } 54 | 55 | .row { 56 | margin-top: 0px; 57 | margin-left: 0px; 58 | margin-right: 0px; 59 | } 60 | 61 | .loading{ 62 | margin: auto; 63 | } 64 | 65 | .mobile-nav { 66 | width: 100%; 67 | position: absolute; 68 | float: none; 69 | left: 0px; 70 | top: 70px; 71 | background-color: #201750; 72 | } 73 | 74 | .platform-label { 75 | text-align: center; 76 | } 77 | 78 | .platform-label p { 79 | color: #00E5FF; 80 | font-family: "Bebas Neue"; 81 | } 82 | 83 | .mobile-nav a { 84 | color: white; 85 | text-decoration: none; 86 | text-align: center; 87 | display: block; 88 | } 89 | 90 | .mobile-walletconnect { 91 | display: flex; 92 | justify-content: center; 93 | } 94 | 95 | .loading_disable{ 96 | display: none !important; 97 | } 98 | 99 | .header { 100 | position: fixed; 101 | width: 100%; 102 | display: flex; 103 | padding: 15px; 104 | background-color: #261c62; 105 | justify-content: center; 106 | left: 0px; 107 | } 108 | 109 | .logo-div { 110 | display: flex; 111 | justify-content: center; 112 | } 113 | 114 | .header-link { 115 | display: flex; 116 | justify-content: center; 117 | } 118 | 119 | .header-link a { 120 | margin: auto; 121 | text-decoration: none; 122 | color: white; 123 | /* height: 100%; */ 124 | align-content: center; 125 | } 126 | 127 | .header-link a:hover { 128 | color: white; 129 | } 130 | 131 | .vs-label { 132 | width: 100%; 133 | } 134 | 135 | .wallet-connect { 136 | display: flex; 137 | justify-content: center; 138 | align-content: center; 139 | } 140 | 141 | .wallet-adapter-dropdown { 142 | float: right !important; 143 | justify-content: center; 144 | } 145 | 146 | .wallet-adapter-button-trigger { 147 | background-color: inherit !important; 148 | } 149 | 150 | .wallet-adapter-button { 151 | background-color: inherit !important; 152 | } 153 | 154 | .flex-container { 155 | display: flex; 156 | } 157 | 158 | .label { 159 | display: inline-block; 160 | font-weight: bold; 161 | font-family: 'Gill Sans'; 162 | margin: auto; 163 | color: rgb(0, 0, 0); 164 | } 165 | 166 | .winteam-label { 167 | font-weight: bold; 168 | font-family: 'Gill Sans'; 169 | margin: auto; 170 | width: 100%; 171 | text-align: center; 172 | color: #00E5FF; 173 | } 174 | 175 | .time-show { 176 | font-weight: bold; 177 | color: #00E5FF; 178 | } 179 | 180 | .cur-time-show { 181 | font-weight: bold; 182 | font-style: italic; 183 | color: #232e66; 184 | /* display: flex; */ 185 | /* justify-content: center; */ 186 | } 187 | 188 | .cur-time-show p { 189 | width: auto; 190 | float: right; 191 | } 192 | 193 | .warning-label { 194 | color: #00E5FF; 195 | font-weight: bold; 196 | /* display: flex; */ 197 | /* justify-content: center; */ 198 | margin: auto; 199 | text-align: center; 200 | } 201 | 202 | .menu-div a { 203 | width: 100% !important; 204 | } 205 | 206 | .action-button { 207 | font-family: "Roboto", lomo copy; 208 | font-weight: 500; 209 | fill: #FFFFFF; 210 | color: #FFFFFF; 211 | background-color: #30D453; 212 | border-style: dotted; 213 | 214 | text-decoration: none; 215 | 216 | font-size: 16px; 217 | padding: 15px 30px; 218 | 219 | margin: auto; 220 | } 221 | 222 | .action-div { 223 | text-align: center; 224 | } 225 | 226 | .action-all-div { 227 | margin: auto; 228 | } 229 | 230 | .nft-div { 231 | text-align: center; 232 | } 233 | 234 | .nft-div p { 235 | color: #00E5FF; 236 | font-weight: bold; 237 | } 238 | 239 | .nft-collection-div { 240 | display: flex; 241 | justify-content: center; 242 | } 243 | 244 | .community-label { 245 | text-align: center; 246 | } 247 | 248 | .community-label p { 249 | color: #00E5FF; 250 | font-family: "Righteous", lomo copy; 251 | font-weight: bold; 252 | } 253 | 254 | .community-icon { 255 | display: flex; 256 | justify-content: center; 257 | } 258 | 259 | .community-icon a { 260 | width: 60px; 261 | } 262 | 263 | .state-table { 264 | color: #00E5FF; 265 | /* font-family: "Righteous", lomo copy; */ 266 | font-weight: bold; 267 | } 268 | 269 | @media only screen and (min-width: 600px) { 270 | 271 | .state-div { 272 | margin-top: 50px; 273 | } 274 | 275 | .action-button { 276 | width : 180px !important; 277 | } 278 | 279 | .community-icon { 280 | margin-top: 50px; 281 | margin-bottom: 80px; 282 | } 283 | 284 | .community-label { 285 | margin-top: 120px; 286 | } 287 | 288 | .community-label p { 289 | font-size: 50px; 290 | } 291 | 292 | .nft-collection-div { 293 | margin-top: 100px; 294 | } 295 | 296 | .nft-collection-div img { 297 | width: 300px; 298 | height: 300px; 299 | } 300 | 301 | .nft-div { 302 | margin-top: 60px; 303 | } 304 | 305 | .nft-div P { 306 | font-size: 40px; 307 | } 308 | 309 | .action-div { 310 | height: 70px; 311 | margin-top: 30px; 312 | } 313 | 314 | .action-all-div { 315 | /* padding: 20px; */ 316 | width: 70%; 317 | } 318 | 319 | .platform-label { 320 | margin-top: 80px; 321 | padding-top: 0px; 322 | padding-bottom: 50px; 323 | } 324 | 325 | .platform-label p { 326 | font-size: 70px; 327 | font-weight: bold; 328 | } 329 | 330 | .vs-label img { 331 | width: 70%; 332 | height: 80px; 333 | margin: auto; 334 | } 335 | 336 | .vs-video { 337 | margin-top: 68px; 338 | } 339 | 340 | .vs-video img{ 341 | width: 70%; 342 | margin: auto; 343 | margin-bottom: 100px; 344 | } 345 | 346 | .empty-div { 347 | height: 140px; 348 | } 349 | 350 | .menu-div { 351 | display: none; 352 | } 353 | 354 | .header-link a { 355 | font-size: 16px; 356 | } 357 | 358 | .wallet-connect { 359 | width: 40%; 360 | } 361 | 362 | .header-link { 363 | width: 40%; 364 | } 365 | 366 | .logo-div { 367 | width: 40%; 368 | } 369 | 370 | .logo-img { 371 | width: 105px; 372 | height: 50px; 373 | } 374 | 375 | .label { 376 | font-size: 50px; 377 | } 378 | 379 | .winteam-label { 380 | margin-top: 30px; 381 | font-size: 45px; 382 | } 383 | 384 | .time-show { 385 | font-size: 26px; 386 | } 387 | 388 | .cur-time-show { 389 | font-size: 20px; 390 | } 391 | 392 | .table { 393 | font-size: 20px; 394 | width: 60%; 395 | margin: auto; 396 | } 397 | 398 | .claim-label { 399 | width: 40%; 400 | font-size: 22px; 401 | font-weight: bold; 402 | } 403 | 404 | .video-style { 405 | width: 70%; 406 | } 407 | 408 | .warning-label { 409 | margin-top: 100px; 410 | font-size: 25px; 411 | width: 80%; 412 | } 413 | 414 | .warning-label p { 415 | margin-top: 20px; 416 | } 417 | 418 | .stake_button { 419 | padding: 8px 20px; 420 | font-size: 20px; 421 | width: 130px; 422 | padding: 10px 0px; 423 | } 424 | 425 | .unstake_button { 426 | padding: 8px 20px; 427 | font-size: 20px; 428 | width: 130px; 429 | padding: 10px 0px; 430 | } 431 | } 432 | 433 | @media only screen and (max-width: 574px) { 434 | 435 | .state-div { 436 | margin-top: 15px; 437 | } 438 | 439 | .action-button { 440 | width : 180px !important; 441 | } 442 | 443 | .community-icon { 444 | margin-top: 30px; 445 | margin-bottom: 50px; 446 | } 447 | 448 | .community-label { 449 | margin-top: 40px; 450 | } 451 | 452 | .community-label p { 453 | font-size: 25px; 454 | } 455 | 456 | .nft-collection-div { 457 | margin-top: 40px; 458 | } 459 | 460 | .nft-collection-div img { 461 | width: 180px; 462 | height: 180px; 463 | } 464 | 465 | .nft-div { 466 | margin-top: 35px; 467 | } 468 | 469 | .nft-div P { 470 | font-size: 30px; 471 | } 472 | 473 | .action-div { 474 | height: 70px; 475 | margin-top: 10px; 476 | } 477 | 478 | .action-all-div { 479 | /* padding: 20px; */ 480 | width: 70%; 481 | } 482 | 483 | .platform-label { 484 | padding-top: 0px; 485 | padding-bottom: 40px; 486 | } 487 | 488 | .platform-label p { 489 | font-size: 35px; 490 | font-weight: bold; 491 | } 492 | 493 | .vs-label img { 494 | width: 100%; 495 | height: 80px; 496 | margin: auto; 497 | } 498 | 499 | .vs-video img{ 500 | width: 100%; 501 | margin: auto; 502 | margin-bottom: 40px; 503 | } 504 | 505 | .vs-video { 506 | margin-top: 60px; 507 | } 508 | 509 | .empty-div { 510 | height: 120px; 511 | } 512 | 513 | .wallet-adapter-dropdown { 514 | float: none !important; 515 | } 516 | 517 | .menu-div { 518 | display: contents; 519 | } 520 | 521 | .header-link { 522 | display: none; 523 | } 524 | 525 | .wallet-connect { 526 | display: none; 527 | } 528 | 529 | .logo-div { 530 | width: 50px; 531 | } 532 | 533 | .logo-img { 534 | width: 50px; 535 | height: 35px; 536 | } 537 | 538 | .label { 539 | font-size: 16px; 540 | font-weight: bold; 541 | } 542 | 543 | .winteam-label { 544 | margin-top: 20px; 545 | font-size: 25px; 546 | } 547 | 548 | .time-show { 549 | font-size: 16px; 550 | font-weight: bold; 551 | } 552 | 553 | .cur-time-show { 554 | font-size: 16px; 555 | font-weight: bold; 556 | } 557 | 558 | .table { 559 | font-size: 20px; 560 | width: 99%; 561 | margin: auto; 562 | } 563 | 564 | .claim-label { 565 | width: 70%; 566 | font-size: 16px; 567 | font-weight: bold; 568 | } 569 | 570 | .video-style { 571 | width: 100%; 572 | } 573 | 574 | .warning-label { 575 | margin-top: 20px; 576 | font-size: 18px; 577 | width: 100%; 578 | } 579 | 580 | .stake_button { 581 | padding: 8px 20px; 582 | font-size: 16px; 583 | width: 90px; 584 | padding: 10px 0px; 585 | } 586 | 587 | .unstake_button { 588 | padding: 8px 20px; 589 | font-size: 16px; 590 | width: 90px; 591 | padding: 10px 0px; 592 | } 593 | } 594 | 595 | .button { 596 | display: inline-block; 597 | border-radius: 4px; 598 | background-color: #008CBA;; 599 | border: none; 600 | color: #FFFFFF; 601 | text-align: center; 602 | font-size: 20px; 603 | padding: 7px; 604 | width: 120px; 605 | transition: all 0.5s; 606 | cursor: pointer; 607 | margin: 5px; 608 | } 609 | 610 | .button span { 611 | cursor: pointer; 612 | display: inline-block; 613 | position: relative; 614 | transition: 0.5s; 615 | } 616 | 617 | .button span:after { 618 | content: '\00bb'; 619 | position: absolute; 620 | opacity: 0; 621 | top: 0; 622 | right: -20px; 623 | transition: 0.5s; 624 | } 625 | 626 | .button:hover span { 627 | padding-right: 25px; 628 | } 629 | 630 | .button:hover span:after { 631 | opacity: 1; 632 | right: 0; 633 | } 634 | 635 | .custom-btn { 636 | vertical-align:middle; 637 | } 638 | 639 | .unstake_button { 640 | background-color: #4CAF50; /* Green */ 641 | border: none; 642 | color: rgb(238, 16, 16); 643 | text-align: center; 644 | text-decoration: none; 645 | display: inline-block; 646 | margin: 4px 2px; 647 | transition-duration: 0.4s; 648 | cursor: pointer; 649 | background-color: #f4814d; 650 | color: black; 651 | border: 2px solid #ffffff; 652 | } 653 | 654 | .unstake_button:hover { 655 | background-color: #fccaba; 656 | color: white; 657 | } 658 | 659 | .stake_button { 660 | background-color: #4CAF50; /* Green */ 661 | border: none; 662 | color: rgb(238, 16, 16); 663 | text-align: center; 664 | text-decoration: none; 665 | display: inline-block; 666 | margin: 4px 2px; 667 | transition-duration: 0.4s; 668 | cursor: pointer; 669 | background-color: #f4814d; 670 | color: black; 671 | border: 2px solid #ffffff; 672 | } 673 | 674 | .stake_button:hover { 675 | background-color: #fccaba; 676 | color: white; 677 | } 678 | 679 | .claim-label { 680 | display: inline; 681 | color: rgb(0, 0, 0); 682 | } 683 | 684 | .winning-video { 685 | display: flex; 686 | justify-content: center; 687 | } 688 | 689 | .video-style { 690 | margin: auto; 691 | } -------------------------------------------------------------------------------- /src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render, screen } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | render(); 7 | const linkElement = screen.getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import { useMemo, useState, useEffect } from "react"; 2 | import { ConnectionProvider, WalletProvider } from '@solana/wallet-adapter-react'; 3 | import { WalletModalProvider, } from '@solana/wallet-adapter-react-ui'; 4 | import { WalletAdapterNetwork } from '@solana/wallet-adapter-base'; 5 | import { SnackbarProvider } from 'notistack'; 6 | import { 7 | getLedgerWallet, 8 | getPhantomWallet, 9 | getSlopeWallet, 10 | getSolflareWallet, 11 | getSolletExtensionWallet, 12 | getSolletWallet, 13 | getTorusWallet, 14 | } from '@solana/wallet-adapter-wallets'; 15 | import { clusterApiUrl } from '@solana/web3.js'; 16 | import {WalletConnect} from './wallet' 17 | // import Mint from './pages/mint' 18 | import Stake from './pages/stake' 19 | import './bootstrap.min.css'; 20 | import './App.css'; 21 | import '@solana/wallet-adapter-react-ui/styles.css'; 22 | import { display } from "@mui/system"; 23 | 24 | import { BsListUl } from 'react-icons/bs'; 25 | import { BsX } from 'react-icons/bs'; 26 | 27 | export default function App(){ 28 | const network = WalletAdapterNetwork.Devnet; 29 | const endpoint = useMemo(() => clusterApiUrl(network), [network]); 30 | const wallets = useMemo(() => [getPhantomWallet()], []); 31 | const [mobileLink, setMobileLink] = useState(false); 32 | 33 | const toggleMenu = () => { 34 | setMobileLink(!mobileLink); 35 | } 36 | 37 | return ( 38 | 39 | 40 | 41 | 42 |
43 |
44 |
45 | 46 | 47 | 48 |
49 |
50 | {/* */} 54 |
55 | 66 |
67 | 68 |
69 |
70 | 84 |
85 | 86 |
87 |
88 |
89 |
90 |
91 |
92 | ); 93 | } -------------------------------------------------------------------------------- /src/asset/video/drawn.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VeteranSoftDev/solana_staking_frontend/587e199ce66ac8427b9c2032792adef81f85d939/src/asset/video/drawn.mp4 -------------------------------------------------------------------------------- /src/asset/video/winhalos.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VeteranSoftDev/solana_staking_frontend/587e199ce66ac8427b9c2032792adef81f85d939/src/asset/video/winhalos.mp4 -------------------------------------------------------------------------------- /src/asset/video/winhorns.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VeteranSoftDev/solana_staking_frontend/587e199ce66ac8427b9c2032792adef81f85d939/src/asset/video/winhorns.mp4 -------------------------------------------------------------------------------- /src/declare.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.mp4'; -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | background-color: #130B3C !important; 9 | } 10 | 11 | code { 12 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 13 | monospace; 14 | } -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/pages/Loading.tsx: -------------------------------------------------------------------------------- 1 | const Loading = ({ ...restProps }) => { 2 | 3 | return ( 4 |
5 | 6 |
7 | ); 8 | }; 9 | 10 | export default Loading; 11 | -------------------------------------------------------------------------------- /src/pages/notify.tsx: -------------------------------------------------------------------------------- 1 | import { useSnackbar, VariantType } from 'notistack'; 2 | import { useCallback } from 'react'; 3 | 4 | export default function useNotify() { 5 | const { enqueueSnackbar } = useSnackbar(); 6 | 7 | return useCallback( 8 | (variant: VariantType, message: string, signature?: string) => { 9 | enqueueSnackbar( 10 | 11 | {message} 12 | {signature && ( 13 | 17 | Transaction 18 | 19 | )} 20 | , 21 | { variant }, 22 | ); 23 | }, 24 | [enqueueSnackbar], 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /src/pages/solana_anchor.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.0", 3 | "name": "solana_anchor", 4 | "instructions": [ 5 | { 6 | "name": "initPool", 7 | "accounts": [ 8 | { 9 | "name": "owner", 10 | "isMut": true, 11 | "isSigner": true 12 | }, 13 | { 14 | "name": "pool", 15 | "isMut": true, 16 | "isSigner": false 17 | }, 18 | { 19 | "name": "rand", 20 | "isMut": false, 21 | "isSigner": false 22 | }, 23 | { 24 | "name": "soulsMint", 25 | "isMut": true, 26 | "isSigner": false 27 | }, 28 | { 29 | "name": "tokenProgram", 30 | "isMut": false, 31 | "isSigner": false 32 | }, 33 | { 34 | "name": "systemProgram", 35 | "isMut": false, 36 | "isSigner": false 37 | } 38 | ], 39 | "args": [ 40 | { 41 | "name": "bump", 42 | "type": "u8" 43 | }, 44 | { 45 | "name": "stakingPeriod", 46 | "type": "i64" 47 | }, 48 | { 49 | "name": "withdrawPeriod", 50 | "type": "i64" 51 | }, 52 | { 53 | "name": "hvhPercent", 54 | "type": "u64" 55 | }, 56 | { 57 | "name": "soldierPercent", 58 | "type": "u64" 59 | }, 60 | { 61 | "name": "winPercent", 62 | "type": "u64" 63 | }, 64 | { 65 | "name": "losePercent", 66 | "type": "u64" 67 | }, 68 | { 69 | "name": "burnPercent", 70 | "type": "u64" 71 | }, 72 | { 73 | "name": "winTeamStake", 74 | "type": "u64" 75 | }, 76 | { 77 | "name": "lostTeamStake", 78 | "type": "u64" 79 | }, 80 | { 81 | "name": "tokenUnit", 82 | "type": "u64" 83 | }, 84 | { 85 | "name": "soulAmount", 86 | "type": "u64" 87 | }, 88 | { 89 | "name": "hvhSymbol", 90 | "type": "string" 91 | }, 92 | { 93 | "name": "soldierSymbol", 94 | "type": "string" 95 | }, 96 | { 97 | "name": "tokenHalos", 98 | "type": "string" 99 | }, 100 | { 101 | "name": "tokenHorns", 102 | "type": "string" 103 | }, 104 | { 105 | "name": "startTime", 106 | "type": "i64" 107 | }, 108 | { 109 | "name": "period", 110 | "type": "i64" 111 | } 112 | ] 113 | }, 114 | { 115 | "name": "initStakeState", 116 | "accounts": [ 117 | { 118 | "name": "owner", 119 | "isMut": true, 120 | "isSigner": true 121 | }, 122 | { 123 | "name": "pool", 124 | "isMut": false, 125 | "isSigner": false 126 | }, 127 | { 128 | "name": "soulsMint", 129 | "isMut": false, 130 | "isSigner": false 131 | }, 132 | { 133 | "name": "stakeState", 134 | "isMut": true, 135 | "isSigner": false 136 | }, 137 | { 138 | "name": "systemProgram", 139 | "isMut": false, 140 | "isSigner": false 141 | } 142 | ], 143 | "args": [ 144 | { 145 | "name": "bump", 146 | "type": "u8" 147 | } 148 | ] 149 | }, 150 | { 151 | "name": "initHvhData", 152 | "accounts": [ 153 | { 154 | "name": "owner", 155 | "isMut": true, 156 | "isSigner": true 157 | }, 158 | { 159 | "name": "pool", 160 | "isMut": false, 161 | "isSigner": false 162 | }, 163 | { 164 | "name": "nftMint", 165 | "isMut": false, 166 | "isSigner": false 167 | }, 168 | { 169 | "name": "hvhData", 170 | "isMut": true, 171 | "isSigner": false 172 | }, 173 | { 174 | "name": "systemProgram", 175 | "isMut": false, 176 | "isSigner": false 177 | } 178 | ], 179 | "args": [ 180 | { 181 | "name": "bump", 182 | "type": "u8" 183 | } 184 | ] 185 | }, 186 | { 187 | "name": "initSoldierData", 188 | "accounts": [ 189 | { 190 | "name": "owner", 191 | "isMut": true, 192 | "isSigner": true 193 | }, 194 | { 195 | "name": "pool", 196 | "isMut": false, 197 | "isSigner": false 198 | }, 199 | { 200 | "name": "nftMint", 201 | "isMut": false, 202 | "isSigner": false 203 | }, 204 | { 205 | "name": "soldierData", 206 | "isMut": true, 207 | "isSigner": false 208 | }, 209 | { 210 | "name": "systemProgram", 211 | "isMut": false, 212 | "isSigner": false 213 | } 214 | ], 215 | "args": [ 216 | { 217 | "name": "bump", 218 | "type": "u8" 219 | } 220 | ] 221 | }, 222 | { 223 | "name": "stakehvh", 224 | "accounts": [ 225 | { 226 | "name": "owner", 227 | "isMut": true, 228 | "isSigner": true 229 | }, 230 | { 231 | "name": "pool", 232 | "isMut": true, 233 | "isSigner": false 234 | }, 235 | { 236 | "name": "hvhData", 237 | "isMut": true, 238 | "isSigner": false 239 | }, 240 | { 241 | "name": "stakeState", 242 | "isMut": true, 243 | "isSigner": false 244 | }, 245 | { 246 | "name": "nftMint", 247 | "isMut": false, 248 | "isSigner": false 249 | }, 250 | { 251 | "name": "metadata", 252 | "isMut": true, 253 | "isSigner": false 254 | }, 255 | { 256 | "name": "sourceNftAccount", 257 | "isMut": true, 258 | "isSigner": false 259 | }, 260 | { 261 | "name": "destNftAccount", 262 | "isMut": true, 263 | "isSigner": false 264 | }, 265 | { 266 | "name": "sourceSoulsAccount", 267 | "isMut": true, 268 | "isSigner": false 269 | }, 270 | { 271 | "name": "destSoulsAccount", 272 | "isMut": true, 273 | "isSigner": false 274 | }, 275 | { 276 | "name": "tokenProgram", 277 | "isMut": false, 278 | "isSigner": false 279 | }, 280 | { 281 | "name": "systemProgram", 282 | "isMut": false, 283 | "isSigner": false 284 | }, 285 | { 286 | "name": "clock", 287 | "isMut": false, 288 | "isSigner": false 289 | } 290 | ], 291 | "args": [ 292 | { 293 | "name": "hvhIdentity", 294 | "type": "string" 295 | } 296 | ] 297 | }, 298 | { 299 | "name": "stakesoldiers", 300 | "accounts": [ 301 | { 302 | "name": "owner", 303 | "isMut": true, 304 | "isSigner": true 305 | }, 306 | { 307 | "name": "pool", 308 | "isMut": true, 309 | "isSigner": false 310 | }, 311 | { 312 | "name": "soldierData", 313 | "isMut": true, 314 | "isSigner": false 315 | }, 316 | { 317 | "name": "stakeState", 318 | "isMut": true, 319 | "isSigner": false 320 | }, 321 | { 322 | "name": "nftMint", 323 | "isMut": false, 324 | "isSigner": false 325 | }, 326 | { 327 | "name": "metadata", 328 | "isMut": true, 329 | "isSigner": false 330 | }, 331 | { 332 | "name": "sourceNftAccount", 333 | "isMut": true, 334 | "isSigner": false 335 | }, 336 | { 337 | "name": "destNftAccount", 338 | "isMut": true, 339 | "isSigner": false 340 | }, 341 | { 342 | "name": "sourceSoulsAccount", 343 | "isMut": true, 344 | "isSigner": false 345 | }, 346 | { 347 | "name": "destSoulsAccount", 348 | "isMut": true, 349 | "isSigner": false 350 | }, 351 | { 352 | "name": "tokenProgram", 353 | "isMut": false, 354 | "isSigner": false 355 | }, 356 | { 357 | "name": "systemProgram", 358 | "isMut": false, 359 | "isSigner": false 360 | }, 361 | { 362 | "name": "clock", 363 | "isMut": false, 364 | "isSigner": false 365 | } 366 | ], 367 | "args": [ 368 | { 369 | "name": "hvhIdentity", 370 | "type": "string" 371 | } 372 | ] 373 | }, 374 | { 375 | "name": "unstakehvh", 376 | "accounts": [ 377 | { 378 | "name": "owner", 379 | "isMut": true, 380 | "isSigner": true 381 | }, 382 | { 383 | "name": "pool", 384 | "isMut": true, 385 | "isSigner": false 386 | }, 387 | { 388 | "name": "hvhData", 389 | "isMut": true, 390 | "isSigner": false 391 | }, 392 | { 393 | "name": "stakeState", 394 | "isMut": true, 395 | "isSigner": false 396 | }, 397 | { 398 | "name": "nftMint", 399 | "isMut": false, 400 | "isSigner": false 401 | }, 402 | { 403 | "name": "metadata", 404 | "isMut": true, 405 | "isSigner": false 406 | }, 407 | { 408 | "name": "sourceNftAccount", 409 | "isMut": true, 410 | "isSigner": false 411 | }, 412 | { 413 | "name": "destNftAccount", 414 | "isMut": true, 415 | "isSigner": false 416 | }, 417 | { 418 | "name": "tokenProgram", 419 | "isMut": false, 420 | "isSigner": false 421 | }, 422 | { 423 | "name": "systemProgram", 424 | "isMut": false, 425 | "isSigner": false 426 | }, 427 | { 428 | "name": "clock", 429 | "isMut": false, 430 | "isSigner": false 431 | } 432 | ], 433 | "args": [ 434 | { 435 | "name": "hvhIdentity", 436 | "type": "string" 437 | } 438 | ] 439 | }, 440 | { 441 | "name": "unstakesoldier", 442 | "accounts": [ 443 | { 444 | "name": "owner", 445 | "isMut": true, 446 | "isSigner": true 447 | }, 448 | { 449 | "name": "pool", 450 | "isMut": true, 451 | "isSigner": false 452 | }, 453 | { 454 | "name": "soldierData", 455 | "isMut": true, 456 | "isSigner": false 457 | }, 458 | { 459 | "name": "stakeState", 460 | "isMut": true, 461 | "isSigner": false 462 | }, 463 | { 464 | "name": "nftMint", 465 | "isMut": false, 466 | "isSigner": false 467 | }, 468 | { 469 | "name": "metadata", 470 | "isMut": true, 471 | "isSigner": false 472 | }, 473 | { 474 | "name": "sourceNftAccount", 475 | "isMut": true, 476 | "isSigner": false 477 | }, 478 | { 479 | "name": "destNftAccount", 480 | "isMut": true, 481 | "isSigner": false 482 | }, 483 | { 484 | "name": "tokenProgram", 485 | "isMut": false, 486 | "isSigner": false 487 | }, 488 | { 489 | "name": "systemProgram", 490 | "isMut": false, 491 | "isSigner": false 492 | }, 493 | { 494 | "name": "clock", 495 | "isMut": false, 496 | "isSigner": false 497 | } 498 | ], 499 | "args": [] 500 | }, 501 | { 502 | "name": "claim", 503 | "accounts": [ 504 | { 505 | "name": "owner", 506 | "isMut": true, 507 | "isSigner": true 508 | }, 509 | { 510 | "name": "pool", 511 | "isMut": true, 512 | "isSigner": false 513 | }, 514 | { 515 | "name": "stakeState", 516 | "isMut": true, 517 | "isSigner": false 518 | }, 519 | { 520 | "name": "destSoulsAccount", 521 | "isMut": true, 522 | "isSigner": false 523 | }, 524 | { 525 | "name": "sourceSoulsAccount", 526 | "isMut": true, 527 | "isSigner": false 528 | }, 529 | { 530 | "name": "burnSoulsAccount", 531 | "isMut": true, 532 | "isSigner": false 533 | }, 534 | { 535 | "name": "tokenProgram", 536 | "isMut": false, 537 | "isSigner": false 538 | }, 539 | { 540 | "name": "systemProgram", 541 | "isMut": false, 542 | "isSigner": false 543 | }, 544 | { 545 | "name": "clock", 546 | "isMut": false, 547 | "isSigner": false 548 | } 549 | ], 550 | "args": [] 551 | } 552 | ], 553 | "accounts": [ 554 | { 555 | "name": "Pool", 556 | "type": { 557 | "kind": "struct", 558 | "fields": [ 559 | { 560 | "name": "owner", 561 | "type": "publicKey" 562 | }, 563 | { 564 | "name": "rand", 565 | "type": "publicKey" 566 | }, 567 | { 568 | "name": "soulsMint", 569 | "type": "publicKey" 570 | }, 571 | { 572 | "name": "totalSouls", 573 | "type": "u64" 574 | }, 575 | { 576 | "name": "stakingPeriod", 577 | "type": "i64" 578 | }, 579 | { 580 | "name": "withdrawPeriod", 581 | "type": "i64" 582 | }, 583 | { 584 | "name": "halosCount", 585 | "type": "u64" 586 | }, 587 | { 588 | "name": "hornsCount", 589 | "type": "u64" 590 | }, 591 | { 592 | "name": "soldierHalosCount", 593 | "type": "u64" 594 | }, 595 | { 596 | "name": "soldierHornsCount", 597 | "type": "u64" 598 | }, 599 | { 600 | "name": "prevWin", 601 | "type": "u8" 602 | }, 603 | { 604 | "name": "winTeamStake", 605 | "type": "u64" 606 | }, 607 | { 608 | "name": "lostTeamStake", 609 | "type": "u64" 610 | }, 611 | { 612 | "name": "soulAmount", 613 | "type": "u64" 614 | }, 615 | { 616 | "name": "hvhPercent", 617 | "type": "u64" 618 | }, 619 | { 620 | "name": "soldierPercent", 621 | "type": "u64" 622 | }, 623 | { 624 | "name": "burnPercent", 625 | "type": "u64" 626 | }, 627 | { 628 | "name": "winPercent", 629 | "type": "u64" 630 | }, 631 | { 632 | "name": "losePercent", 633 | "type": "u64" 634 | }, 635 | { 636 | "name": "startTime", 637 | "type": "i64" 638 | }, 639 | { 640 | "name": "tokenUnit", 641 | "type": "u64" 642 | }, 643 | { 644 | "name": "period", 645 | "type": "i64" 646 | }, 647 | { 648 | "name": "hvhSymbol", 649 | "type": "string" 650 | }, 651 | { 652 | "name": "soldierSymbol", 653 | "type": "string" 654 | }, 655 | { 656 | "name": "tokenHalos", 657 | "type": "string" 658 | }, 659 | { 660 | "name": "tokenHorns", 661 | "type": "string" 662 | }, 663 | { 664 | "name": "burned", 665 | "type": "bool" 666 | }, 667 | { 668 | "name": "bump", 669 | "type": "u8" 670 | } 671 | ] 672 | } 673 | }, 674 | { 675 | "name": "StakeState", 676 | "type": { 677 | "kind": "struct", 678 | "fields": [ 679 | { 680 | "name": "owner", 681 | "type": "publicKey" 682 | }, 683 | { 684 | "name": "pool", 685 | "type": "publicKey" 686 | }, 687 | { 688 | "name": "halosCount", 689 | "type": "u64" 690 | }, 691 | { 692 | "name": "hornsCount", 693 | "type": "u64" 694 | }, 695 | { 696 | "name": "soldierHalosCount", 697 | "type": "u64" 698 | }, 699 | { 700 | "name": "soldierHornsCount", 701 | "type": "u64" 702 | }, 703 | { 704 | "name": "lastStakeTime", 705 | "type": "i64" 706 | }, 707 | { 708 | "name": "claimed", 709 | "type": "bool" 710 | }, 711 | { 712 | "name": "bump", 713 | "type": "u8" 714 | } 715 | ] 716 | } 717 | }, 718 | { 719 | "name": "HvHData", 720 | "type": { 721 | "kind": "struct", 722 | "fields": [ 723 | { 724 | "name": "owner", 725 | "type": "publicKey" 726 | }, 727 | { 728 | "name": "pool", 729 | "type": "publicKey" 730 | }, 731 | { 732 | "name": "nftMint", 733 | "type": "publicKey" 734 | }, 735 | { 736 | "name": "nftAccount", 737 | "type": "publicKey" 738 | }, 739 | { 740 | "name": "stakeTime", 741 | "type": "i64" 742 | }, 743 | { 744 | "name": "unstaked", 745 | "type": "bool" 746 | } 747 | ] 748 | } 749 | }, 750 | { 751 | "name": "SoldierData", 752 | "type": { 753 | "kind": "struct", 754 | "fields": [ 755 | { 756 | "name": "owner", 757 | "type": "publicKey" 758 | }, 759 | { 760 | "name": "pool", 761 | "type": "publicKey" 762 | }, 763 | { 764 | "name": "nftMint", 765 | "type": "publicKey" 766 | }, 767 | { 768 | "name": "nftAccount", 769 | "type": "publicKey" 770 | }, 771 | { 772 | "name": "stakeTime", 773 | "type": "i64" 774 | }, 775 | { 776 | "name": "hvhStr", 777 | "type": "string" 778 | }, 779 | { 780 | "name": "unstaked", 781 | "type": "bool" 782 | } 783 | ] 784 | } 785 | } 786 | ], 787 | "errors": [ 788 | { 789 | "code": 6000, 790 | "name": "TokenMintToFailed", 791 | "msg": "Token mint to failed" 792 | }, 793 | { 794 | "code": 6001, 795 | "name": "TokenSetAuthorityFailed", 796 | "msg": "Token authority failed" 797 | }, 798 | { 799 | "code": 6002, 800 | "name": "TokenTransferFailed", 801 | "msg": "Token transfer failed" 802 | }, 803 | { 804 | "code": 6003, 805 | "name": "InvalidTokenAccount", 806 | "msg": "Invalid token account" 807 | }, 808 | { 809 | "code": 6004, 810 | "name": "InvalidTokenMint", 811 | "msg": "Invalid token mint" 812 | }, 813 | { 814 | "code": 6005, 815 | "name": "InvalidMetadata", 816 | "msg": "Invalid metadata" 817 | }, 818 | { 819 | "code": 6006, 820 | "name": "InvalidHvHData", 821 | "msg": "Invalid HvHData account" 822 | }, 823 | { 824 | "code": 6007, 825 | "name": "InvalidStakeState", 826 | "msg": "Invalid stakestate account" 827 | }, 828 | { 829 | "code": 6008, 830 | "name": "InvalidTime", 831 | "msg": "Invalid time" 832 | }, 833 | { 834 | "code": 6009, 835 | "name": "InvalidStakingPeriod", 836 | "msg": "Invalid Staking Period" 837 | }, 838 | { 839 | "code": 6010, 840 | "name": "InvalidWithdrawPeriod", 841 | "msg": "Invalid Withdraw Period" 842 | }, 843 | { 844 | "code": 6011, 845 | "name": "PassedStakingPeriod", 846 | "msg": "Passed Staking Period" 847 | }, 848 | { 849 | "code": 6012, 850 | "name": "WithdrawFirst", 851 | "msg": "Please withdraw first" 852 | }, 853 | { 854 | "code": 6013, 855 | "name": "PassedWithdrawPeriod", 856 | "msg": "Passed Withdraw Period" 857 | }, 858 | { 859 | "code": 6014, 860 | "name": "InvalidUnstakeTime", 861 | "msg": "Invalid Unstake Time" 862 | }, 863 | { 864 | "code": 6015, 865 | "name": "AlreadyUnstaked", 866 | "msg": "Already unstaked" 867 | }, 868 | { 869 | "code": 6016, 870 | "name": "AlreadyClaimed", 871 | "msg": "Already claimed" 872 | }, 873 | { 874 | "code": 6017, 875 | "name": "InvalidBurnAccount", 876 | "msg": "Invalid Burn Account" 877 | } 878 | ] 879 | } -------------------------------------------------------------------------------- /src/pages/stake.tsx: -------------------------------------------------------------------------------- 1 | import { Fragment, useRef, useState, useEffect } from 'react'; 2 | import { Button, Modal } from 'react-bootstrap'; 3 | import useNotify from './notify' 4 | import { useWallet, useConnection } from "@solana/wallet-adapter-react"; 5 | import * as anchor from "@project-serum/anchor"; 6 | import {AccountLayout,MintLayout,TOKEN_PROGRAM_ID,Token,ASSOCIATED_TOKEN_PROGRAM_ID} from "@solana/spl-token"; 7 | import { TokenListProvider, TokenInfo } from '@solana/spl-token-registry'; 8 | import { programs } from '@metaplex/js' 9 | import moment from 'moment'; 10 | import Loading from "./Loading"; 11 | // import win_horns from "./video/win_horns.mov"; 12 | // import winhorns from "../asset/video/winhorns.mp4"; 13 | import winhorns from "../asset/video/winhorns.mp4"; 14 | import winhalos from "../asset/video/winhalos.mp4"; 15 | import { FaDiscord } from "react-icons/fa"; 16 | import { FaTwitter } from "react-icons/fa"; 17 | // import drawn from "../asset/video/drawn.mp4"; 18 | import { 19 | Connection, 20 | Keypair, 21 | Signer, 22 | PublicKey, 23 | Transaction, 24 | TransactionInstruction, 25 | TransactionSignature, 26 | ConfirmOptions, 27 | sendAndConfirmRawTransaction, 28 | RpcResponseAndContext, 29 | SimulatedTransactionResponse, 30 | Commitment, 31 | LAMPORTS_PER_SOL, 32 | SYSVAR_RENT_PUBKEY, 33 | SYSVAR_CLOCK_PUBKEY, 34 | clusterApiUrl, 35 | StakeInstruction 36 | } from "@solana/web3.js"; 37 | import axios from "axios" 38 | import { token } from '@project-serum/anchor/dist/cjs/utils'; 39 | import { createJsxClosingElement, moveEmitHelpers, PollingWatchKind } from 'typescript'; 40 | import { clearInterval } from 'timers'; 41 | import { unstable_renderSubtreeIntoContainer } from 'react-dom'; 42 | import SelectInput from '@mui/material/Select/SelectInput'; 43 | 44 | let wallet : any 45 | // let conn = new Connection(clusterApiUrl('mainnet-beta')) 46 | let conn = new Connection("https://ssc-dao.genesysgo.net/"); 47 | let notify : any 48 | const { metadata: { Metadata } } = programs 49 | const COLLECTION_NAME = "Gorilla" 50 | const TOKEN_METADATA_PROGRAM_ID = new anchor.web3.PublicKey( 51 | "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s" 52 | ) 53 | const programId = new PublicKey('BYXYF76vQSBiiMGpkmBLtiUWsa5TDLQBPueFuPzPrj9E') 54 | const idl = require('./solana_anchor.json') 55 | const confirmOption : ConfirmOptions = { 56 | commitment : 'finalized', 57 | preflightCommitment : 'finalized', 58 | skipPreflight : false 59 | } 60 | 61 | // const REWARD_TOKEN = 'sou1ELxm3XpLWpnjP81KaoigPPCwbNUFAZ4dhqifq13' //Mainnet beta 62 | const REWARD_TOKEN = 'sou1ELxm3XpLWpnjP81KaoigPPCwbNUFAZ4dhqifq13' 63 | 64 | let POOL = new PublicKey('Dw14gB5BKLzy3SqkQRDjkKFcqrDtMgL9sUdZFXfG4aAq') // Devnet 65 | // const HVH_DATA_SIZE = 8 + 32 + 32 + 32 + 32 + 8 + 1; 66 | const HVH_DATA_SIZE = 32 * 4 + 8 + 1; 67 | const SOLDIER_DATA_SIZE = 32 * 4 + 8 + 1 + 4 + 10; 68 | 69 | const DEVNET_ID = 103; 70 | 71 | let init = true; 72 | let ownerstakedinfo: any = null; 73 | let pD : any ; 74 | // let claimAmount = 0 75 | let nfts : any[] = [] 76 | let soldiers : any[] = [] 77 | let stakedNfts : any[] = [] 78 | let stakedSoldiers : any[] = [] 79 | let catchFlag : boolean = false; 80 | let selected_soldier : any = {}; 81 | const delay_ms : Number = 30; 82 | let stakeallflag : Boolean = true; 83 | const axios_timeout : any = 2000; 84 | 85 | const getTimeZoneOffset = (date : any, timeZone : any) => { 86 | 87 | // Abuse the Intl API to get a local ISO 8601 string for a given time zone. 88 | const options = { 89 | timeZone, calendar: 'iso8601', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false, 90 | }; 91 | // @ts-ignore 92 | const dateTimeFormat = new Intl.DateTimeFormat(undefined, options); 93 | const parts = dateTimeFormat.formatToParts(date); 94 | const map = new Map(parts.map((x) => [x.type, x.value])); 95 | const year = map.get('year'); 96 | const month = map.get('month'); 97 | const day = map.get('day'); 98 | const hour = map.get('hour'); 99 | const minute = map.get('minute'); 100 | const second = map.get('second'); 101 | const ms = date.getMilliseconds().toString().padStart(3, '0'); 102 | const iso = `${year}-${month}-${day}T${hour}:${minute}:${second}.${ms}`; 103 | 104 | // Lie to the Date object constructor that it's a UTC time. 105 | const lie = new Date(`${iso}Z`); 106 | 107 | // Return the difference in timestamps, as minutes 108 | // Positive values are West of GMT, opposite of ISO 8601 109 | // this matches the output of `Date.getTimeZoneOffset` 110 | // @ts-ignore 111 | return -(lie - date) / 60 / 1000; 112 | }; 113 | 114 | function sleep(time: any){ 115 | return new Promise((resolve)=>setTimeout(resolve,time) 116 | ) 117 | } 118 | 119 | const getTimeStampOfDateInEnvTimeZone = (timeStamp:number, userTimezone: string, timezoneForTesting:string) => { 120 | 121 | const envTimeZoneOffsetInMinutes = getTimeZoneOffset(new Date(timeStamp), timezoneForTesting); 122 | const userTimeZoneOffsetInMInutes = getTimeZoneOffset(new Date(timeStamp), userTimezone); 123 | const difference = userTimeZoneOffsetInMInutes - envTimeZoneOffsetInMinutes; 124 | const diffInMilliseconds = difference * 60000; 125 | return timeStamp - diffInMilliseconds; 126 | }; 127 | 128 | const createAssociatedTokenAccountInstruction = ( 129 | associatedTokenAddress: anchor.web3.PublicKey, 130 | payer: anchor.web3.PublicKey, 131 | walletAddress: anchor.web3.PublicKey, 132 | splTokenMintAddress: anchor.web3.PublicKey 133 | ) => { 134 | const keys = [ 135 | { pubkey: payer, isSigner: true, isWritable: true }, 136 | { pubkey: associatedTokenAddress, isSigner: false, isWritable: true }, 137 | { pubkey: walletAddress, isSigner: false, isWritable: false }, 138 | { pubkey: splTokenMintAddress, isSigner: false, isWritable: false }, 139 | { 140 | pubkey: anchor.web3.SystemProgram.programId, 141 | isSigner: false, 142 | isWritable: false, 143 | }, 144 | { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, 145 | { 146 | pubkey: anchor.web3.SYSVAR_RENT_PUBKEY, 147 | isSigner: false, 148 | isWritable: false, 149 | }, 150 | ]; 151 | return new anchor.web3.TransactionInstruction({ 152 | keys, 153 | programId: ASSOCIATED_TOKEN_PROGRAM_ID, 154 | data: Buffer.from([]), 155 | }); 156 | } 157 | 158 | const getTokenListInfo = async (address:String, chainId:Number) => { 159 | const tokens: any = await new TokenListProvider().resolve(); 160 | const tokenlist: any = await tokens.filterByChainId(chainId).getList(); 161 | let tokenitem; 162 | await tokenlist.map((item: any) => { 163 | if(item.address === address) { 164 | tokenitem = item; 165 | } 166 | }); 167 | return tokenitem; 168 | } 169 | 170 | const getMasterEdition = async ( 171 | mint: anchor.web3.PublicKey 172 | ): Promise => { 173 | return ( 174 | await anchor.web3.PublicKey.findProgramAddress( 175 | [ 176 | Buffer.from("metadata"), 177 | TOKEN_METADATA_PROGRAM_ID.toBuffer(), 178 | mint.toBuffer(), 179 | Buffer.from("edition"), 180 | ], 181 | TOKEN_METADATA_PROGRAM_ID 182 | ) 183 | )[0]; 184 | }; 185 | 186 | const getMetadata = async ( 187 | mint: anchor.web3.PublicKey 188 | ): Promise => { 189 | return ( 190 | await anchor.web3.PublicKey.findProgramAddress( 191 | [ 192 | Buffer.from("metadata"), 193 | TOKEN_METADATA_PROGRAM_ID.toBuffer(), 194 | mint.toBuffer(), 195 | ], 196 | TOKEN_METADATA_PROGRAM_ID 197 | ) 198 | )[0]; 199 | }; 200 | 201 | const getTokenWallet = async ( 202 | wallet: anchor.web3.PublicKey, 203 | mint: anchor.web3.PublicKey 204 | ) => { 205 | return ( 206 | await anchor.web3.PublicKey.findProgramAddress( 207 | [wallet.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mint.toBuffer()], 208 | ASSOCIATED_TOKEN_PROGRAM_ID 209 | ) 210 | )[0]; 211 | }; 212 | 213 | const getStakeStateInfo = async (address: PublicKey) => { 214 | let wallet = new anchor.Wallet(Keypair.generate()) 215 | let provider = new anchor.Provider(conn,wallet,confirmOption) 216 | const program = new anchor.Program(idl,programId,provider) 217 | let poolData = await program.account.stakeState.fetch(address) 218 | return poolData; 219 | } 220 | 221 | const getStakeDataInfo = async (address: PublicKey) => { 222 | let wallet = new anchor.Wallet(Keypair.generate()) 223 | let provider = new anchor.Provider(conn,wallet,confirmOption) 224 | const program = new anchor.Program(idl,programId,provider) 225 | let poolData = await program.account.hvHData.fetch(address) 226 | return poolData; 227 | } 228 | 229 | const getSoldierDataInfo = async (address: PublicKey) => { 230 | let wallet = new anchor.Wallet(Keypair.generate()) 231 | let provider = new anchor.Provider(conn,wallet,confirmOption) 232 | const program = new anchor.Program(idl,programId,provider) 233 | let poolData = await program.account.soldierData.fetch(address) 234 | return poolData; 235 | } 236 | 237 | async function getTokenAccountBalance(owner: PublicKey, mint: PublicKey) { 238 | let amount = 0 239 | if( owner != null ){ 240 | const tokenAccount = await getTokenWallet(owner, mint) 241 | if(await conn.getAccountInfo(tokenAccount)){ 242 | let resp : any = (await conn.getTokenAccountBalance(tokenAccount)).value 243 | amount = Number(resp.uiAmount) 244 | } 245 | } 246 | return amount; 247 | } 248 | 249 | async function getProgramAccount(owner : PublicKey, pool: PublicKey, token: PublicKey) { 250 | // console.log(owner, pool, token); 251 | return await PublicKey.findProgramAddress([owner.toBuffer(),pool.toBuffer(), token.toBuffer()], programId) 252 | } 253 | 254 | async function getOwnerStakeStateInfo() { 255 | const reward_mint : PublicKey = new PublicKey(REWARD_TOKEN); 256 | let [stakeState] = await getProgramAccount(wallet.publicKey, POOL, reward_mint); 257 | if((await conn.getAccountInfo(stakeState)) == null) { 258 | return; 259 | } 260 | 261 | let balance = await getTokenAccountBalance(wallet.publicKey, reward_mint); 262 | 263 | let stateinfo = await getStakeStateInfo(stakeState); 264 | //halosCount hornsCount soldierHalosCount soldierHornsCount 265 | // console.log("state data", stateinfo) 266 | let halos_mul = stateinfo.halosCount.toNumber() / 10 | 0; 267 | let horns_mul = stateinfo.hornsCount.toNumber() / 10 | 0; 268 | 269 | let halos_unit = stateinfo.halosCount.toNumber() + (halos_mul + 1) * stateinfo.soldierHalosCount.toNumber(); 270 | let horns_unit = stateinfo.hornsCount.toNumber() + (horns_mul + 1) * stateinfo.soldierHornsCount.toNumber(); 271 | 272 | ownerstakedinfo = { 273 | ...stateinfo, 274 | souls : balance, 275 | halos_unit : halos_unit, 276 | horns_unit : horns_unit 277 | } 278 | } 279 | 280 | let init_flag= false; 281 | 282 | export function SelectHHModal(props : any) { 283 | 284 | return ( 285 | 292 | 293 | 294 | Select Team 295 | 296 | 297 | 298 | {pD &&
299 | {pD.win_team_stake} to Won team and {pD.lost_team_stake} to Lost team 300 |
} 301 |
302 | 303 | 304 | 305 | 306 |
307 | ); 308 | } 309 | 310 | export default function Stake(){ 311 | 312 | const [changed, setChange] = useState(true) 313 | const [rewardAmount, setRewardAmount] = useState(10) 314 | const [period, setPeriod] = useState(60) 315 | const [withdrawable, setWithdrawable] = useState(7) 316 | const [collectionName, setCollectionName] = useState(COLLECTION_NAME) 317 | const [rewardToken, setRewardToken] = useState(REWARD_TOKEN) 318 | const [todaystr, setDateTime] = useState(""); // Save the current date to be able to trigger an update 319 | const [loading, setLoading] = useState(false); 320 | const [claimableAmount, setClaimAmount] = useState(0); 321 | const [stakingPeriod, setStakingPeriod] = useState({start:"", end:""}); 322 | const [withdrawPeriod, setWithdrawPeriod] = useState({start:"", end: ""}); 323 | const [fightingFlag, setFightingFlag] = useState(0);//default halos win 324 | const [winTeam, setWinTeam] = useState(""); 325 | const [modalShow, setModalShow] = useState(false); 326 | // const [stakeallflag, setStakeAllFlag] = useState(true); 327 | // const [init, setInitFlag] = useState(false); 328 | 329 | let stakedinfo; 330 | 331 | wallet = useWallet() 332 | notify = useNotify() 333 | 334 | useEffect(() => { 335 | const timer = setInterval(() => { 336 | getTime(); 337 | },1000); 338 | 339 | return () => { 340 | clearInterval(timer); 341 | } 342 | }, []); 343 | 344 | useEffect(() => { 345 | if(wallet){ 346 | if(!wallet.disconnecting && wallet.publicKey && !init_flag) { 347 | init_flag = true; 348 | console.log("get info") 349 | getNfts() 350 | } 351 | } 352 | }, [wallet]) 353 | // useEffect(() => { 354 | // if(wallet.publicKey !== undefined) { 355 | // console.log("wallet", wallet) 356 | // getNfts() 357 | // init = false 358 | // } 359 | // }, [loading]) 360 | 361 | // const testTimezone = () => { 362 | 363 | // const timezoneOffset = (new Date()).getTimezoneOffset(); 364 | 365 | // console.log("timezone offset", timezoneOffset); 366 | 367 | // const date = new Date(); 368 | // const dateAsString = date.toString(); 369 | // console.log("date string", dateAsString) 370 | 371 | // console.log(moment().utcOffset()); // (-240, -120, -60, 0, 60, 120, 240, etc.) 372 | // // const timezone = dateAsString.match(/\(([^\)]+)\)$/)[1]; 373 | 374 | // // console.log(timezone); 375 | 376 | // } 377 | 378 | const setSelectSoldier = (nftaccount : any, nftmint : any) => { 379 | selected_soldier = {nftaccount, nftmint} 380 | stakeallflag = true; 381 | setModalShow(true) 382 | } 383 | 384 | const setSelectAllFlag = () => { 385 | stakeallflag = false; 386 | setModalShow(true); 387 | } 388 | 389 | const stakeSoldierToHalos = () => { 390 | if(stakeallflag) 391 | stakeSoldier(selected_soldier.nftaccount, selected_soldier.nftmint, pD.token_halos) 392 | else 393 | stakeSoldiersAll(pD.token_halos) 394 | setModalShow(false) 395 | } 396 | 397 | const stakeSoldierToHorns = () => { 398 | if(stakeallflag) 399 | stakeSoldier(selected_soldier.nftaccount, selected_soldier.nftmint, pD.token_horns) 400 | else 401 | stakeSoldiersAll(pD.token_horns) 402 | setModalShow(false) 403 | } 404 | 405 | const getTime = () => { 406 | // testTimezone(); 407 | const today = new Date(); 408 | setDateTime(today.toLocaleString("en-US")); 409 | 410 | if(pD) { 411 | catchClaimPeriod(); 412 | } 413 | 414 | if(pD) { 415 | if(moment().unix() > Date.parse(pD.end_withdraw) / 1000) { 416 | updateStakingPeriod(); 417 | } 418 | } 419 | } 420 | 421 | const updateStakingPeriod = async () => { 422 | 423 | let time_period = getStakingPeriod(); 424 | 425 | const time_interval = moment().unix() - time_period.withdraw_limit; 426 | 427 | let day_interval = time_interval / (time_period.total_period * pD.period); 428 | day_interval = day_interval | 0; 429 | 430 | if(time_interval < 0) 431 | day_interval--; 432 | 433 | const starttime = Date.parse(pD.abs_start_time) / 1000 + pD.period * (day_interval + 1) * time_period.total_period; 434 | const next_staking_limit = starttime + pD.period * pD.staking_period; 435 | const withdrawtime = next_staking_limit + 1; 436 | const next_withdraw_limit = withdrawtime + pD.period * pD.withdraw_period; 437 | 438 | const next_staking_start = new Date(starttime * 1000); 439 | const next_staking_end = new Date(next_staking_limit * 1000); 440 | const next_withdraw_start = new Date(withdrawtime * 1000); 441 | const next_withdraw_end = new Date(next_withdraw_limit * 1000); 442 | 443 | pD.start_time = next_staking_start; 444 | pD.end_time = next_staking_end; 445 | 446 | pD.start_withdraw = next_withdraw_start; 447 | pD.end_withdraw = next_withdraw_end; 448 | 449 | setStakingPeriod({ 450 | start: next_staking_start.toLocaleString("en-US"), 451 | end: next_staking_end.toLocaleString("en-US"), 452 | }) 453 | 454 | setWithdrawPeriod({ 455 | start: next_withdraw_start.toLocaleString("en-US"), 456 | end: next_withdraw_end.toLocaleString("en-US") 457 | }) 458 | } 459 | 460 | const catchClaimPeriod = async () => { 461 | 462 | if((moment().unix() > (Date.parse(pD.end_time) / 1000)) && (moment().unix() < (Date.parse(pD.end_withdraw) / 1000))) { 463 | if(catchFlag) 464 | return; 465 | getClaimAmount(conn, wallet.publicKey); 466 | 467 | let halos_mul = pD.halos_count / 10 | 0; 468 | let horns_mul = pD.horns_count / 10 | 0; 469 | 470 | let total_halos_soldiers = pD.halos_count + (halos_mul + 1) * pD.soldier_halos_count; 471 | let total_horns_soldiers = pD.horns_count + pD.soldier_horns_count * (horns_mul + 1); 472 | 473 | // console.log("test val", total_halos_soldiers, total_horns_soldiers) 474 | 475 | if(total_halos_soldiers > total_horns_soldiers) { 476 | setFightingFlag(0);// halos win 477 | setWinTeam("Halos"); 478 | } else if(total_halos_soldiers < total_horns_soldiers) { 479 | setFightingFlag(1);// horns win 480 | setWinTeam("Horns"); 481 | } else { 482 | setFightingFlag(2);// drawn 483 | setWinTeam("Drawn"); 484 | } 485 | 486 | catchFlag = true; 487 | } else { 488 | catchFlag = false; 489 | } 490 | } 491 | 492 | async function validateStaking( 493 | conn : Connection, 494 | owner : PublicKey 495 | ){ 496 | console.log("+ validate Staking") 497 | 498 | if(!wallet.connected) { 499 | notify('error', 'Wallet is unconnected!'); 500 | // setLoading(false); 501 | return false; 502 | } 503 | 504 | const provider = new anchor.Provider(conn, wallet, anchor.Provider.defaultOptions()); 505 | const program = new anchor.Program(idl, programId, provider); 506 | 507 | await getPoolData(); 508 | 509 | const reward_mint : PublicKey = new PublicKey(REWARD_TOKEN); 510 | 511 | let [stakeState] = await getProgramAccount(owner, POOL, reward_mint); 512 | 513 | let balance = await getTokenAccountBalance(owner, reward_mint); 514 | 515 | if(balance < pD.soulAmount) { 516 | notify('error', 'Insufficient tokens!'); 517 | // setLoading(false); 518 | return false; 519 | } 520 | 521 | // console.log(time_period.staking_limit, moment().unix(), time_period.withdraw_limit); 522 | 523 | if(moment().unix() >= Date.parse(pD.end_time) / 1000 && moment().unix() <= Date.parse(pD.end_withdraw) / 1000) { 524 | notify('error', 'Staking period has passed!'); 525 | // setLoading(false) 526 | return false; 527 | } 528 | 529 | if((await conn.getAccountInfo(stakeState)) != null) { 530 | stakedinfo = await getStakeStateInfo(stakeState) 531 | // console.log(moment().unix(), time_period.staking_limit) 532 | if(moment().unix() < Date.parse(pD.end_time) / 1000) { 533 | if(stakedinfo.lastStakeTime.toNumber() !== 0 && stakedinfo.lastStakeTime.toNumber() < (Date.parse(pD.start_time) / 1000)) { 534 | if(stakedinfo.halosCount.toNumber() != 0 || stakedinfo.hornsCount.toNumber() != 0 || stakedinfo.soldierHalosCount.toNumber() != 0 || stakedinfo.soldierHornsCount.toNumber() != 0) { 535 | // console.log("test") 536 | notify('error', 'You should claim and unstake nft tokens before stake!'); 537 | // setLoading(false) 538 | return false; 539 | } 540 | } 541 | } 542 | } 543 | 544 | // console.log(starttime, moment().unix(), next_staking_limit) 545 | if(moment().unix() > Date.parse(pD.end_withdraw) / 1000) { 546 | // console.log("test") 547 | notify('error', 'Staking period has passed!'); 548 | // setLoading(false); 549 | return false; 550 | } 551 | 552 | return true; 553 | } 554 | 555 | async function stake( 556 | nftAccount : PublicKey, 557 | nftMint : PublicKey, 558 | hvhtype : String 559 | ){ 560 | 561 | setLoading(true); 562 | 563 | if(!await validateStaking(conn, wallet.publicKey)) { 564 | setLoading(false); 565 | return; 566 | } 567 | 568 | console.log("+ stake") 569 | 570 | let provider = new anchor.Provider(conn, wallet as any, confirmOption) 571 | let program = new anchor.Program(idl,programId,provider) 572 | 573 | // const stakeData = Keypair.generate() 574 | const reward_mint : PublicKey = new PublicKey(REWARD_TOKEN); 575 | const metadata = await getMetadata(nftMint) 576 | const sourceNftAccount = nftAccount; 577 | const destNftAccount = await getTokenWallet(POOL,nftMint) 578 | const srcSoulsAccount = await getTokenWallet(wallet.publicKey, reward_mint); 579 | const destSoulsAccount = await getTokenWallet(POOL, reward_mint); 580 | 581 | const accountInfo: any = await conn.getParsedAccountInfo(metadata); 582 | let metadata1 : any = new Metadata(wallet.publicKey.toString(), accountInfo.value); 583 | 584 | let [stakeState, bump] = await getProgramAccount(wallet.publicKey, POOL, reward_mint); 585 | let [hvh_data, bump1] = await getProgramAccount(wallet.publicKey, POOL, nftMint); 586 | 587 | let transaction = new Transaction() 588 | // signers.push(stakeState) 589 | if((await conn.getAccountInfo(destNftAccount)) == null) 590 | transaction.add(createAssociatedTokenAccountInstruction(destNftAccount,wallet.publicKey,POOL,nftMint)) 591 | if((await conn.getAccountInfo(destSoulsAccount)) == null) 592 | transaction.add(createAssociatedTokenAccountInstruction(destSoulsAccount,wallet.publicKey,POOL,reward_mint)) 593 | if((await conn.getAccountInfo(hvh_data)) == null) { 594 | transaction.add( 595 | await program.instruction.initHvhData(new anchor.BN(bump1), 596 | { 597 | accounts: { 598 | owner : wallet.publicKey, 599 | pool : POOL, 600 | nftMint: nftMint, 601 | hvhData: hvh_data, 602 | systemProgram : anchor.web3.SystemProgram.programId 603 | } 604 | }) 605 | ) 606 | } 607 | 608 | if((await conn.getAccountInfo(stakeState)) == null) { 609 | transaction.add( 610 | await program.instruction.initStakeState(new anchor.BN(bump), 611 | { 612 | accounts: { 613 | owner : wallet.publicKey, 614 | pool : POOL, 615 | soulsMint: reward_mint, 616 | stakeState: stakeState, 617 | systemProgram : anchor.web3.SystemProgram.programId 618 | } 619 | }) 620 | ) 621 | } 622 | 623 | let signers : Keypair[] = [] 624 | // signers.push(stakeData) 625 | transaction.add( 626 | await program.instruction.stakehvh(hvhtype, { 627 | accounts: { 628 | owner : wallet.publicKey, 629 | pool : POOL, 630 | hvhData : hvh_data, 631 | stakeState : stakeState, 632 | nftMint : nftMint, 633 | metadata : metadata, 634 | sourceNftAccount : sourceNftAccount, 635 | destNftAccount : destNftAccount, 636 | sourceSoulsAccount:srcSoulsAccount, 637 | destSoulsAccount:destSoulsAccount, 638 | tokenProgram : TOKEN_PROGRAM_ID, 639 | systemProgram : anchor.web3.SystemProgram.programId, 640 | clock : SYSVAR_CLOCK_PUBKEY 641 | } 642 | }) 643 | ) 644 | 645 | await sendTransaction(transaction,signers) 646 | 647 | setLoading(false); 648 | await getNfts(); 649 | 650 | } 651 | 652 | async function stakeAll(hvflag : boolean){ 653 | 654 | setLoading(true); 655 | 656 | if(nfts.length <= 0) { 657 | setLoading(false); 658 | return; 659 | } 660 | 661 | console.log("+ stakeAll") 662 | 663 | let provider = new anchor.Provider(conn, wallet as any, confirmOption) 664 | let program = new anchor.Program(idl,programId,provider) 665 | const reward_mint : PublicKey = new PublicKey(REWARD_TOKEN); 666 | let [stakeState, bump] = await getProgramAccount(wallet.publicKey, POOL, reward_mint); 667 | 668 | let stakeData = null; 669 | let metadata = null; 670 | let sourceNftAccount = null; 671 | let destNftAccount = null; 672 | let srcSoulsAccount = null; 673 | let destSoulsAccount = null; 674 | 675 | let accountInfo: any = null; 676 | let metadata1 : any = null; 677 | // nft.account_address, nft.mint_address, nft.attributes[0].value 678 | 679 | // let instructions : TransactionInstruction[] = [] 680 | 681 | let transactiona = new Transaction() 682 | 683 | if((await conn.getAccountInfo(stakeState)) == null) { 684 | transactiona.add( 685 | await program.instruction.initStakeState(new anchor.BN(bump), 686 | { 687 | accounts: { 688 | owner : wallet.publicKey, 689 | pool : POOL, 690 | soulsMint: reward_mint, 691 | stakeState: stakeState, 692 | systemProgram : anchor.web3.SystemProgram.programId 693 | } 694 | }) 695 | ) 696 | await sendTransaction(transactiona, []) 697 | } 698 | 699 | let instructions : TransactionInstruction[] = [] 700 | // let transaction = new Transaction() 701 | // let signers : Keypair[] = [] 702 | let j = 0; 703 | 704 | if(!await validateStaking(conn, wallet.publicKey)) { 705 | // await getNfts(); 706 | setLoading(false); 707 | return; 708 | } 709 | 710 | let i = 0; 711 | 712 | for(let i = 0; i < nfts.length; i++) { 713 | 714 | if(hvflag && nfts[i].attributes[0].value != pD.token_halos) { 715 | // console.log("halos", nfts[i].attributes[0].value, pD.token_halos) 716 | continue; 717 | } 718 | 719 | if(!hvflag && nfts[i].attributes[0].value != pD.token_horns) { 720 | // console.log("horns", nfts[i].attributes[0].value, pD.token_horns) 721 | continue; 722 | } 723 | 724 | metadata = await getMetadata(nfts[i].mint_address) 725 | sourceNftAccount = nfts[i].account_address 726 | destNftAccount = await getTokenWallet(POOL, nfts[i].mint_address) 727 | srcSoulsAccount = await getTokenWallet(wallet.publicKey, reward_mint) 728 | destSoulsAccount = await getTokenWallet(POOL, reward_mint); 729 | 730 | accountInfo = await conn.getParsedAccountInfo(metadata); 731 | metadata1 = new Metadata(wallet.publicKey.toString(), accountInfo.value); 732 | 733 | let [hvh_data, bump1] = await getProgramAccount(wallet.publicKey, POOL, nfts[i].mint_address); 734 | 735 | if((await conn.getAccountInfo(hvh_data)) == null) { 736 | instructions.push( 737 | await program.instruction.initHvhData(new anchor.BN(bump1), 738 | { 739 | accounts: { 740 | owner : wallet.publicKey, 741 | pool : POOL, 742 | nftMint: nfts[i].mint_address, 743 | hvhData: hvh_data, 744 | systemProgram : anchor.web3.SystemProgram.programId 745 | } 746 | }) 747 | ) 748 | j++; 749 | } 750 | 751 | 752 | if((await conn.getAccountInfo(destNftAccount)) == null) { 753 | instructions.push(createAssociatedTokenAccountInstruction(destNftAccount,wallet.publicKey,POOL, nfts[i].mint_address)) 754 | j++; 755 | } 756 | if((await conn.getAccountInfo(destSoulsAccount)) == null) { 757 | instructions.push(createAssociatedTokenAccountInstruction(destSoulsAccount,wallet.publicKey,POOL,reward_mint)) 758 | j++; 759 | } 760 | 761 | instructions.push( 762 | await program.instruction.stakehvh(nfts[i].attributes[0].value, { 763 | accounts: { 764 | owner : wallet.publicKey, 765 | pool : POOL, 766 | hvhData : hvh_data, 767 | stakeState : stakeState, 768 | nftMint : nfts[i].mint_address, 769 | metadata : metadata, 770 | sourceNftAccount : sourceNftAccount, 771 | destNftAccount : destNftAccount, 772 | sourceSoulsAccount:srcSoulsAccount, 773 | destSoulsAccount:destSoulsAccount, 774 | tokenProgram : TOKEN_PROGRAM_ID, 775 | systemProgram : anchor.web3.SystemProgram.programId, 776 | clock : SYSVAR_CLOCK_PUBKEY 777 | } 778 | }) 779 | ) 780 | 781 | j++; 782 | 783 | if(j==3 || (i == nfts.length-1 && j != 0)) { 784 | let transaction = new Transaction() 785 | instructions.map(item=>transaction.add(item)) 786 | await sendTransaction(transaction,[]) 787 | j=0 788 | instructions=[] 789 | if(i == nfts.length - 1) { 790 | setLoading(false); 791 | await getNfts(); 792 | } 793 | } 794 | 795 | } 796 | } 797 | 798 | 799 | async function validateStakingSoldier( 800 | conn : Connection, 801 | owner : PublicKey, 802 | hvhtype : String 803 | ){ 804 | console.log("+ validate Staking Souldier") 805 | 806 | if(!wallet.connected) { 807 | notify('error', 'Wallet is unconnected!'); 808 | // setLoading(false); 809 | return false; 810 | } 811 | 812 | const provider = new anchor.Provider(conn, wallet, anchor.Provider.defaultOptions()); 813 | const program = new anchor.Program(idl, programId, provider); 814 | 815 | await getPoolData(); 816 | 817 | const reward_mint : PublicKey = new PublicKey(REWARD_TOKEN); 818 | 819 | let [stakeState] = await getProgramAccount(owner, POOL, reward_mint); 820 | 821 | let balance = await getTokenAccountBalance(owner, reward_mint); 822 | 823 | //halos win 824 | if(hvhtype == pD.token_halos && pD.prev_win == 0) { 825 | if(balance < pD.win_team_stake) { 826 | notify('error', 'Insufficient tokens!'); 827 | // setLoading(false); 828 | return false; 829 | } 830 | } 831 | 832 | //horns win 833 | if(hvhtype == pD.token_horns && pD.prev_win == 1) { 834 | if(balance < pD.lost_team_stake) { 835 | notify('error', 'Insufficient tokens!'); 836 | // setLoading(false); 837 | return false; 838 | } 839 | } 840 | 841 | //draw 842 | if(pD.prev_win == 2) { 843 | if(balance < pD.soulAmount) { 844 | notify('error', 'Insufficient tokens!'); 845 | // setLoading(false); 846 | return false; 847 | } 848 | } 849 | 850 | // console.log(time_period.staking_limit, moment().unix(), time_period.withdraw_limit); 851 | 852 | if(moment().unix() >= Date.parse(pD.end_time) / 1000 && moment().unix() <= Date.parse(pD.end_withdraw) / 1000) { 853 | notify('error', 'Staking period has passed!'); 854 | // setLoading(false) 855 | return false; 856 | } 857 | 858 | if((await conn.getAccountInfo(stakeState)) != null) { 859 | stakedinfo = await getStakeStateInfo(stakeState) 860 | // console.log(moment().unix(), time_period.staking_limit) 861 | if(moment().unix() < Date.parse(pD.end_time) / 1000) { 862 | if(stakedinfo.lastStakeTime.toNumber() !== 0 && stakedinfo.lastStakeTime.toNumber() < (Date.parse(pD.start_time) / 1000)) { 863 | if(stakedinfo.halosCount.toNumber() != 0 || stakedinfo.hornsCount.toNumber() != 0 || stakedinfo.soldierHalosCount.toNumber() != 0 || stakedinfo.soldierHornsCount.toNumber() != 0) { 864 | // console.log("test") 865 | notify('error', 'You should claim and unstake nft tokens before stake!'); 866 | // setLoading(false) 867 | return false; 868 | } 869 | } 870 | } 871 | } 872 | 873 | // console.log(starttime, moment().unix(), next_staking_limit) 874 | if(moment().unix() > Date.parse(pD.end_withdraw) / 1000) { 875 | // console.log("test") 876 | notify('error', 'Staking period has passed!'); 877 | // setLoading(false); 878 | return false; 879 | } 880 | 881 | return true; 882 | } 883 | 884 | async function stakeSoldier( 885 | nftAccount : PublicKey, 886 | nftMint : PublicKey, 887 | hvhtype : String 888 | ){ 889 | 890 | setLoading(true); 891 | 892 | if(!await validateStakingSoldier(conn, wallet.publicKey, hvhtype)) { 893 | setLoading(false); 894 | return; 895 | } 896 | 897 | console.log("+ stake souldiers") 898 | 899 | let provider = new anchor.Provider(conn, wallet as any, confirmOption) 900 | let program = new anchor.Program(idl,programId,provider) 901 | 902 | // const stakeData = Keypair.generate() 903 | const reward_mint : PublicKey = new PublicKey(REWARD_TOKEN); 904 | const metadata = await getMetadata(nftMint) 905 | const sourceNftAccount = nftAccount; 906 | const destNftAccount = await getTokenWallet(POOL,nftMint) 907 | const srcSoulsAccount = await getTokenWallet(wallet.publicKey, reward_mint); 908 | const destSoulsAccount = await getTokenWallet(POOL, reward_mint); 909 | 910 | const accountInfo: any = await conn.getParsedAccountInfo(metadata); 911 | let metadata1 : any = new Metadata(wallet.publicKey.toString(), accountInfo.value); 912 | 913 | let [stakeState, bump] = await getProgramAccount(wallet.publicKey, POOL, reward_mint); 914 | let [soldier_data, bump1] = await getProgramAccount(wallet.publicKey, POOL, nftMint); 915 | 916 | let transaction = new Transaction() 917 | // signers.push(stakeState) 918 | if((await conn.getAccountInfo(destNftAccount)) == null) 919 | transaction.add(createAssociatedTokenAccountInstruction(destNftAccount,wallet.publicKey,POOL,nftMint)) 920 | if((await conn.getAccountInfo(destSoulsAccount)) == null) 921 | transaction.add(createAssociatedTokenAccountInstruction(destSoulsAccount,wallet.publicKey,POOL,reward_mint)) 922 | if((await conn.getAccountInfo(soldier_data)) == null) { 923 | transaction.add( 924 | await program.instruction.initSoldierData(new anchor.BN(bump1), 925 | { 926 | accounts: { 927 | owner : wallet.publicKey, 928 | pool : POOL, 929 | nftMint: nftMint, 930 | soldierData: soldier_data, 931 | systemProgram : anchor.web3.SystemProgram.programId 932 | } 933 | }) 934 | ) 935 | } 936 | 937 | if((await conn.getAccountInfo(stakeState)) == null) { 938 | transaction.add( 939 | await program.instruction.initStakeState(new anchor.BN(bump), 940 | { 941 | accounts: { 942 | owner : wallet.publicKey, 943 | pool : POOL, 944 | soulsMint: reward_mint, 945 | stakeState: stakeState, 946 | systemProgram : anchor.web3.SystemProgram.programId 947 | } 948 | }) 949 | ) 950 | } 951 | 952 | let signers : Keypair[] = [] 953 | // signers.push(stakeData) 954 | transaction.add( 955 | await program.instruction.stakesoldiers(hvhtype, { 956 | accounts: { 957 | owner : wallet.publicKey, 958 | pool : POOL, 959 | soldierData : soldier_data, 960 | stakeState : stakeState, 961 | nftMint : nftMint, 962 | metadata : metadata, 963 | sourceNftAccount : sourceNftAccount, 964 | destNftAccount : destNftAccount, 965 | sourceSoulsAccount:srcSoulsAccount, 966 | destSoulsAccount:destSoulsAccount, 967 | tokenProgram : TOKEN_PROGRAM_ID, 968 | systemProgram : anchor.web3.SystemProgram.programId, 969 | clock : SYSVAR_CLOCK_PUBKEY 970 | } 971 | }) 972 | ) 973 | 974 | await sendTransaction(transaction,signers) 975 | 976 | setLoading(false); 977 | await getNfts(); 978 | 979 | } 980 | 981 | async function stakeSoldiersAll(hvhtype : String){ 982 | 983 | setLoading(true); 984 | 985 | if(soldiers.length <= 0) { 986 | setLoading(false); 987 | return; 988 | } 989 | 990 | console.log("+ stake souldier All") 991 | 992 | let provider = new anchor.Provider(conn, wallet as any, confirmOption) 993 | let program = new anchor.Program(idl,programId,provider) 994 | const reward_mint : PublicKey = new PublicKey(REWARD_TOKEN); 995 | let [stakeState, bump] = await getProgramAccount(wallet.publicKey, POOL, reward_mint); 996 | 997 | let stakeData = null; 998 | let metadata = null; 999 | let sourceNftAccount = null; 1000 | let destNftAccount = null; 1001 | let srcSoulsAccount = null; 1002 | let destSoulsAccount = null; 1003 | 1004 | let accountInfo: any = null; 1005 | let metadata1 : any = null; 1006 | // nft.account_address, nft.mint_address, nft.attributes[0].value 1007 | 1008 | // let instructions : TransactionInstruction[] = [] 1009 | 1010 | let transactiona = new Transaction() 1011 | 1012 | if((await conn.getAccountInfo(stakeState)) == null) { 1013 | transactiona.add( 1014 | await program.instruction.initStakeState(new anchor.BN(bump), 1015 | { 1016 | accounts: { 1017 | owner : wallet.publicKey, 1018 | pool : POOL, 1019 | soulsMint: reward_mint, 1020 | stakeState: stakeState, 1021 | systemProgram : anchor.web3.SystemProgram.programId 1022 | } 1023 | }) 1024 | ) 1025 | await sendTransaction(transactiona, []) 1026 | } 1027 | 1028 | let instructions : TransactionInstruction[] = [] 1029 | // let transaction = new Transaction() 1030 | // let signers : Keypair[] = [] 1031 | let j = 0; 1032 | 1033 | if(!await validateStakingSoldier(conn, wallet.publicKey,hvhtype)) { 1034 | // await getNfts(); 1035 | setLoading(false); 1036 | return; 1037 | } 1038 | 1039 | let i = 0; 1040 | 1041 | for(i = 0; i < soldiers.length; i++) { 1042 | 1043 | metadata = await getMetadata(soldiers[i].mint_address) 1044 | sourceNftAccount = soldiers[i].account_address 1045 | destNftAccount = await getTokenWallet(POOL, soldiers[i].mint_address) 1046 | srcSoulsAccount = await getTokenWallet(wallet.publicKey, reward_mint) 1047 | destSoulsAccount = await getTokenWallet(POOL, reward_mint); 1048 | 1049 | accountInfo = await conn.getParsedAccountInfo(metadata); 1050 | metadata1 = new Metadata(wallet.publicKey.toString(), accountInfo.value); 1051 | 1052 | let [soldier_data, bump1] = await getProgramAccount(wallet.publicKey, POOL, soldiers[i].mint_address); 1053 | 1054 | if((await conn.getAccountInfo(soldier_data)) == null) { 1055 | instructions.push( 1056 | await program.instruction.initSoldierData(new anchor.BN(bump1), 1057 | { 1058 | accounts: { 1059 | owner : wallet.publicKey, 1060 | pool : POOL, 1061 | nftMint: soldiers[i].mint_address, 1062 | soldierData: soldier_data, 1063 | systemProgram : anchor.web3.SystemProgram.programId 1064 | } 1065 | }) 1066 | ) 1067 | j++; 1068 | } 1069 | 1070 | 1071 | if((await conn.getAccountInfo(destNftAccount)) == null) { 1072 | instructions.push(createAssociatedTokenAccountInstruction(destNftAccount,wallet.publicKey,POOL, soldiers[i].mint_address)) 1073 | j++; 1074 | } 1075 | if((await conn.getAccountInfo(destSoulsAccount)) == null) { 1076 | instructions.push(createAssociatedTokenAccountInstruction(destSoulsAccount,wallet.publicKey,POOL,reward_mint)) 1077 | j++; 1078 | } 1079 | 1080 | instructions.push( 1081 | await program.instruction.stakesoldiers(hvhtype, { 1082 | accounts: { 1083 | owner : wallet.publicKey, 1084 | pool : POOL, 1085 | soldierData : soldier_data, 1086 | stakeState : stakeState, 1087 | nftMint : soldiers[i].mint_address, 1088 | metadata : metadata, 1089 | sourceNftAccount : sourceNftAccount, 1090 | destNftAccount : destNftAccount, 1091 | sourceSoulsAccount:srcSoulsAccount, 1092 | destSoulsAccount:destSoulsAccount, 1093 | tokenProgram : TOKEN_PROGRAM_ID, 1094 | systemProgram : anchor.web3.SystemProgram.programId, 1095 | clock : SYSVAR_CLOCK_PUBKEY 1096 | } 1097 | }) 1098 | ) 1099 | 1100 | j++; 1101 | 1102 | if(j==3 || (i == soldiers.length-1 && j != 0)) { 1103 | let transaction = new Transaction() 1104 | instructions.map(item=>transaction.add(item)) 1105 | await sendTransaction(transaction,[]) 1106 | 1107 | j=0 1108 | instructions=[] 1109 | 1110 | if(i == soldiers.length - 1) { 1111 | setLoading(false); 1112 | await getNfts(); 1113 | } 1114 | } 1115 | } 1116 | } 1117 | 1118 | async function validateUnStaking(stakedatainfo : any){ 1119 | console.log("+ validate UnStaking") 1120 | 1121 | if(!wallet.connected) { 1122 | notify('error', 'Wallet is unconnected!'); 1123 | // setLoading(false); 1124 | return false; 1125 | } 1126 | 1127 | if(stakedatainfo.unstaked) { 1128 | notify('error', 'Already unstaked!'); 1129 | // setLoading(false); 1130 | return false; 1131 | } 1132 | 1133 | await getPoolData(); 1134 | 1135 | if(moment().unix() <= Date.parse(pD.end_time) / 1000) { 1136 | notify('error', 'Please wait until the weekly staking competition is complete!'); 1137 | // setLoading(false); 1138 | return false; 1139 | } 1140 | 1141 | return true; 1142 | } 1143 | 1144 | async function unstake( 1145 | stakeData : PublicKey, 1146 | hvhtype : String 1147 | ){ 1148 | 1149 | setLoading(true); 1150 | 1151 | let stakedatainfo = await getStakeDataInfo(stakeData); 1152 | if(!await validateUnStaking(stakedatainfo)) { 1153 | setLoading(false) 1154 | return; 1155 | } 1156 | console.log("+ unstake") 1157 | 1158 | let provider = new anchor.Provider(conn, wallet as any, confirmOption) 1159 | let program = new anchor.Program(idl,programId,provider) 1160 | let stakedNft = await program.account.hvHData.fetch(stakeData) 1161 | let account = await conn.getAccountInfo(stakedNft.nftAccount) 1162 | let mint = new PublicKey(AccountLayout.decode(account!.data).mint) 1163 | const sourceNftAccount = await getTokenWallet(POOL, mint); 1164 | const reward_mint : PublicKey = new PublicKey(REWARD_TOKEN); 1165 | let [stakeState,] = await getProgramAccount(wallet.publicKey, POOL, reward_mint); 1166 | const metadata = await getMetadata(mint) 1167 | 1168 | let transaction = new Transaction() 1169 | 1170 | transaction.add( 1171 | await program.instruction.unstakehvh(hvhtype, 1172 | { 1173 | accounts:{ 1174 | owner : wallet.publicKey, 1175 | pool : POOL, 1176 | hvhData : stakeData, 1177 | stakeState : stakeState, 1178 | nftMint : mint, 1179 | metadata : metadata, 1180 | sourceNftAccount : sourceNftAccount, 1181 | destNftAccount : stakedNft.nftAccount, 1182 | tokenProgram : TOKEN_PROGRAM_ID, 1183 | systemProgram : anchor.web3.SystemProgram.programId, 1184 | clock : SYSVAR_CLOCK_PUBKEY 1185 | } 1186 | }) 1187 | ) 1188 | 1189 | await sendTransaction(transaction,[]) 1190 | 1191 | setLoading(false); 1192 | await getNfts(); 1193 | 1194 | } 1195 | 1196 | async function unstakeAll(){ 1197 | 1198 | setLoading(true); 1199 | 1200 | let provider = new anchor.Provider(conn, wallet as any, confirmOption) 1201 | let program = new anchor.Program(idl,programId,provider) 1202 | const reward_mint : PublicKey = new PublicKey(REWARD_TOKEN); 1203 | let [stakeState] = await getProgramAccount(wallet.publicKey, POOL, reward_mint); 1204 | let stakedNFTs = await getStakedNftsForOwner(conn,wallet.publicKey) 1205 | 1206 | console.log("+unstake all"); 1207 | 1208 | let j = 0; 1209 | let stakedNft = null; 1210 | let account = null; 1211 | let mint = null; 1212 | let sourceNftAccount = null; 1213 | let metadata = null; 1214 | let stakeData = null; 1215 | let stakedatainfo = null; 1216 | let instructions : TransactionInstruction[] = [] 1217 | 1218 | if(stakedNFTs.length <= 0) { 1219 | setLoading(false); 1220 | return; 1221 | } 1222 | 1223 | let i = 0; 1224 | 1225 | for(i = 0; i < stakedNFTs.length; i++) { 1226 | stakeData = stakedNFTs[i].stakeData; 1227 | stakedatainfo = await getStakeDataInfo(stakeData); 1228 | if(!await validateUnStaking(stakedatainfo)) { 1229 | // await getNfts(); 1230 | setLoading(false); 1231 | return; 1232 | } 1233 | 1234 | stakedNft = await program.account.hvHData.fetch(stakeData) 1235 | account = await conn.getAccountInfo(stakedNft.nftAccount) 1236 | mint = new PublicKey(AccountLayout.decode(account!.data).mint) 1237 | sourceNftAccount = await getTokenWallet(POOL, mint); 1238 | metadata = await getMetadata(mint) 1239 | 1240 | instructions.push( 1241 | await program.instruction.unstakehvh(stakedNFTs[i].type, 1242 | { 1243 | accounts:{ 1244 | owner : wallet.publicKey, 1245 | pool : POOL, 1246 | hvhData : stakeData, 1247 | stakeState : stakeState, 1248 | nftMint : mint, 1249 | metadata : metadata, 1250 | sourceNftAccount : sourceNftAccount, 1251 | destNftAccount : stakedNft.nftAccount, 1252 | tokenProgram : TOKEN_PROGRAM_ID, 1253 | systemProgram : anchor.web3.SystemProgram.programId, 1254 | clock : SYSVAR_CLOCK_PUBKEY 1255 | } 1256 | }) 1257 | ) 1258 | 1259 | j++; 1260 | 1261 | if((j === 4) || (i === stakedNFTs.length - 1 && j !== 0)) { 1262 | 1263 | let transaction = new Transaction() 1264 | 1265 | instructions.map(item=>transaction.add(item)) 1266 | 1267 | await sendTransaction(transaction, []); 1268 | 1269 | j = 0; 1270 | instructions = [] 1271 | 1272 | if (i == stakedNFTs.length - 1) { 1273 | setLoading(false); 1274 | await getNfts(); 1275 | } 1276 | 1277 | } 1278 | } 1279 | // await sendSingleTransaction(transaction,[]) 1280 | } 1281 | 1282 | async function validateUnStakingSoldier(stakedatainfo : any){ 1283 | console.log("+ validate UnStaking Souldier") 1284 | 1285 | if(!wallet.connected) { 1286 | notify('error', 'Wallet is unconnected!'); 1287 | // setLoading(false); 1288 | return false; 1289 | } 1290 | 1291 | if(stakedatainfo.unstaked) { 1292 | notify('error', 'Already unstaked!'); 1293 | // setLoading(false); 1294 | return false; 1295 | } 1296 | 1297 | await getPoolData(); 1298 | 1299 | if(moment().unix() <= Date.parse(pD.end_time) / 1000) { 1300 | notify('error', 'Please wait until the weekly staking competition is complete!'); 1301 | // setLoading(false); 1302 | return false; 1303 | } 1304 | 1305 | return true; 1306 | } 1307 | 1308 | async function unstakesoldier( 1309 | stakeData : PublicKey, 1310 | hvhtype : String 1311 | ){ 1312 | 1313 | setLoading(true); 1314 | 1315 | let stakedatainfo = await getSoldierDataInfo(stakeData); 1316 | if(!await validateUnStakingSoldier(stakedatainfo)) { 1317 | setLoading(false) 1318 | return; 1319 | } 1320 | console.log("+ unstake souldier") 1321 | 1322 | let provider = new anchor.Provider(conn, wallet as any, confirmOption) 1323 | let program = new anchor.Program(idl,programId,provider) 1324 | let stakedNft = await program.account.soldierData.fetch(stakeData) 1325 | let account = await conn.getAccountInfo(stakedNft.nftAccount) 1326 | let mint = new PublicKey(AccountLayout.decode(account!.data).mint) 1327 | const sourceNftAccount = await getTokenWallet(POOL, mint); 1328 | const reward_mint : PublicKey = new PublicKey(REWARD_TOKEN); 1329 | let [stakeState,] = await getProgramAccount(wallet.publicKey, POOL, reward_mint); 1330 | const metadata = await getMetadata(mint) 1331 | 1332 | let transaction = new Transaction() 1333 | 1334 | transaction.add( 1335 | await program.instruction.unstakesoldier( 1336 | { 1337 | accounts:{ 1338 | owner : wallet.publicKey, 1339 | pool : POOL, 1340 | soldierData : stakeData, 1341 | stakeState : stakeState, 1342 | nftMint : mint, 1343 | metadata : metadata, 1344 | sourceNftAccount : sourceNftAccount, 1345 | destNftAccount : stakedNft.nftAccount, 1346 | tokenProgram : TOKEN_PROGRAM_ID, 1347 | systemProgram : anchor.web3.SystemProgram.programId, 1348 | clock : SYSVAR_CLOCK_PUBKEY 1349 | } 1350 | }) 1351 | ) 1352 | 1353 | await sendTransaction(transaction,[]) 1354 | 1355 | setLoading(false); 1356 | await getNfts(); 1357 | 1358 | } 1359 | 1360 | async function unstakeSoldiersAll(){ 1361 | 1362 | setLoading(true); 1363 | 1364 | let provider = new anchor.Provider(conn, wallet as any, confirmOption) 1365 | let program = new anchor.Program(idl,programId,provider) 1366 | const reward_mint : PublicKey = new PublicKey(REWARD_TOKEN); 1367 | let [stakeState] = await getProgramAccount(wallet.publicKey, POOL, reward_mint); 1368 | let stakedNFTs = await getStakedSoldiersForOwner(conn,wallet.publicKey) 1369 | 1370 | console.log("+unstake souldiers all"); 1371 | 1372 | let j = 0; 1373 | let stakedNft = null; 1374 | let account = null; 1375 | let mint = null; 1376 | let sourceNftAccount = null; 1377 | let metadata = null; 1378 | let stakeData = null; 1379 | let stakedatainfo = null; 1380 | let instructions : TransactionInstruction[] = [] 1381 | 1382 | if(stakedNFTs.length <= 0) { 1383 | setLoading(false); 1384 | return; 1385 | } 1386 | 1387 | let i = 0; 1388 | 1389 | for(i = 0; i < stakedNFTs.length; i++) { 1390 | stakeData = stakedNFTs[i].stakeData; 1391 | stakedatainfo = await getSoldierDataInfo(stakeData); 1392 | if(!await validateUnStakingSoldier(stakedatainfo)) { 1393 | // await getNfts(); 1394 | setLoading(false); 1395 | return; 1396 | } 1397 | 1398 | stakedNft = await program.account.soldierData.fetch(stakeData) 1399 | account = await conn.getAccountInfo(stakedNft.nftAccount) 1400 | mint = new PublicKey(AccountLayout.decode(account!.data).mint) 1401 | sourceNftAccount = await getTokenWallet(POOL, mint); 1402 | metadata = await getMetadata(mint) 1403 | 1404 | instructions.push( 1405 | await program.instruction.unstakesoldier( 1406 | { 1407 | accounts:{ 1408 | owner : wallet.publicKey, 1409 | pool : POOL, 1410 | soldierData : stakeData, 1411 | stakeState : stakeState, 1412 | nftMint : mint, 1413 | metadata : metadata, 1414 | sourceNftAccount : sourceNftAccount, 1415 | destNftAccount : stakedNft.nftAccount, 1416 | tokenProgram : TOKEN_PROGRAM_ID, 1417 | systemProgram : anchor.web3.SystemProgram.programId, 1418 | clock : SYSVAR_CLOCK_PUBKEY 1419 | } 1420 | }) 1421 | ) 1422 | 1423 | j++; 1424 | 1425 | if((j === 4) || (i === stakedNFTs.length - 1 && j !== 0)) { 1426 | 1427 | let transaction = new Transaction() 1428 | 1429 | instructions.map(item=>transaction.add(item)) 1430 | 1431 | await sendTransaction(transaction, []); 1432 | 1433 | j = 0; 1434 | instructions = [] 1435 | 1436 | if(i === stakedNFTs.length - 1) { 1437 | await getNfts(); 1438 | setLoading(false); 1439 | } 1440 | 1441 | } 1442 | } 1443 | // await sendSingleTransaction(transaction,[]) 1444 | } 1445 | 1446 | async function validateClaim(stakestateinfo : any){ 1447 | console.log("+ validate UnStaking") 1448 | 1449 | if(!wallet.connected) { 1450 | notify('error', 'Wallet is unconnected!'); 1451 | // setLoading(false); 1452 | return false; 1453 | } 1454 | 1455 | await getPoolData(); 1456 | 1457 | if(moment().unix() <= Date.parse(pD.end_time) / 1000 || moment().unix() > Date.parse(pD.end_withdraw) / 1000) { 1458 | notify('error', 'Not withdraw period!'); 1459 | return false; 1460 | } 1461 | 1462 | if(stakestateinfo.lastStakeTime.toNumber() <= Date.parse(pD.start_time) / 1000) { 1463 | notify('error', 'You should stake again!'); 1464 | return false; 1465 | } 1466 | 1467 | if(stakestateinfo.claimed) { 1468 | notify('error', 'Already claimed!'); 1469 | return false; 1470 | } 1471 | 1472 | return true; 1473 | } 1474 | 1475 | async function claim( 1476 | ){ 1477 | console.log("+ claim") 1478 | 1479 | setLoading(true); 1480 | 1481 | let provider = new anchor.Provider(conn, wallet as any, confirmOption) 1482 | let program = new anchor.Program(idl,programId,provider) 1483 | 1484 | const reward_mint : PublicKey = new PublicKey(REWARD_TOKEN); 1485 | let [stakeState] = await getProgramAccount(wallet.publicKey, POOL, reward_mint); 1486 | // console.log("test") 1487 | if((await conn.getAccountInfo(stakeState)) === null) { 1488 | notify('error', 'Nothing staked!'); 1489 | setLoading(false); 1490 | return false; 1491 | } 1492 | 1493 | // console.log("test") 1494 | 1495 | let stakedinfo = await getStakeStateInfo(stakeState); 1496 | 1497 | if(!await validateClaim(stakedinfo)) { 1498 | setLoading(false); 1499 | return; 1500 | } 1501 | 1502 | const destSoulsAccount = await getTokenWallet(wallet.publicKey, reward_mint); 1503 | const srcSoulsAccount = await getTokenWallet(POOL, reward_mint); 1504 | 1505 | let transaction = new Transaction() 1506 | 1507 | if((await conn.getAccountInfo(destSoulsAccount)) == null) 1508 | transaction.add(createAssociatedTokenAccountInstruction(destSoulsAccount, wallet.publicKey, wallet.publicKey, reward_mint)) 1509 | 1510 | transaction.add( 1511 | await program.instruction.claim({ 1512 | accounts:{ 1513 | owner : wallet.publicKey, 1514 | pool : POOL, 1515 | stakeState : stakeState, 1516 | destSoulsAccount : destSoulsAccount, 1517 | sourceSoulsAccount : srcSoulsAccount, 1518 | burnSoulsAccount : srcSoulsAccount, 1519 | tokenProgram : TOKEN_PROGRAM_ID, 1520 | systemProgram : anchor.web3.SystemProgram.programId, 1521 | clock : SYSVAR_CLOCK_PUBKEY, 1522 | } 1523 | }) 1524 | ) 1525 | // } 1526 | 1527 | await sendTransaction(transaction,[]) 1528 | 1529 | setLoading(false); 1530 | 1531 | } 1532 | 1533 | async function getNftsForOwner( 1534 | conn : any, 1535 | owner : PublicKey 1536 | ){ 1537 | 1538 | console.log("+ getNftsForOwner") 1539 | 1540 | const verifiednfts: any = [] 1541 | 1542 | const allnfts: any = []; 1543 | 1544 | const nftaccounts : any = []; 1545 | 1546 | // const randWallet = new anchor.Wallet(Keypair.generate()) 1547 | // const provider = new anchor.Provider(conn,randWallet,confirmOption) 1548 | // const program = new anchor.Program(idl,programId,provider) 1549 | 1550 | const tokenAccounts = await conn.getParsedTokenAccountsByOwner(owner, {programId: TOKEN_PROGRAM_ID}); 1551 | 1552 | let tokenAccount, tokenAmount; 1553 | 1554 | for (let index = 0; index < tokenAccounts.value.length; index++) { 1555 | tokenAccount = tokenAccounts.value[index]; 1556 | tokenAmount = tokenAccount.account.data.parsed.info.tokenAmount; 1557 | if (tokenAmount.amount == '1' && tokenAmount.decimals == 0) { 1558 | const nftMint = new PublicKey(tokenAccount.account.data.parsed.info.mint) 1559 | let tokenmetaPubkey = await Metadata.getPDA(nftMint); 1560 | allnfts.push(tokenmetaPubkey); 1561 | nftaccounts.push(tokenAccounts.value[index].pubkey) 1562 | } 1563 | } 1564 | 1565 | let nftinfo: any[] = []; 1566 | const buffer = [...allnfts]; 1567 | let count = 100; 1568 | while(buffer.length > 0) { 1569 | if(buffer.length < 100) { 1570 | count = buffer.length; 1571 | } else { 1572 | count = 100; 1573 | } 1574 | nftinfo = [...nftinfo.concat(await conn.getMultipleAccountsInfo(buffer.splice(0, count)))]; 1575 | } 1576 | 1577 | // const nftinfo: any = await conn.getMultipleAccountsInfo(allnfts); 1578 | 1579 | // let tokenCount = nftinfo.length 1580 | 1581 | for(let i = 0; i < nftinfo.length; i++) { 1582 | 1583 | if(nftinfo[i] == null) { 1584 | continue; 1585 | } 1586 | 1587 | let metadata : any = new Metadata(owner.toString(), nftinfo[i]) 1588 | 1589 | if(metadata.data.data.symbol == pD.hvh_symbol) { 1590 | 1591 | let data: any; 1592 | 1593 | try { 1594 | data = await axios.get(metadata.data.data.uri, {timeout: axios_timeout}); 1595 | } catch(error) { 1596 | console.log(error); 1597 | continue; 1598 | } 1599 | 1600 | // console.log("data loaded", data) 1601 | 1602 | if(!data) { 1603 | // console.log("data error") 1604 | continue; 1605 | } 1606 | 1607 | const entireData = { ...data.data, id: Number(data.data.name.replace( /^\D+/g, '').split(' - ')[0])} 1608 | 1609 | let nftMint = new PublicKey(metadata.data.mint) 1610 | if(entireData.attributes.value === pD.halos || entireData.attributes.value === pD.horns) { 1611 | verifiednfts.push({account_address : nftaccounts[i], mint_address : nftMint, ...entireData}) 1612 | } 1613 | } 1614 | } 1615 | 1616 | verifiednfts.sort(function (a: any, b: any) { 1617 | if (a.name < b.name) { return -1; } 1618 | if (a.name > b.name) { return 1; } 1619 | return 0; 1620 | }) 1621 | 1622 | return verifiednfts 1623 | } 1624 | 1625 | async function getSoldiersForOwner( 1626 | conn : any, 1627 | owner : PublicKey 1628 | ){ 1629 | 1630 | console.log("+ getSouldiersForOwner") 1631 | 1632 | const verifiednfts: any = [] 1633 | 1634 | const allnfts: any = []; 1635 | 1636 | const nftaccounts: any = []; 1637 | 1638 | // const randWallet = new anchor.Wallet(Keypair.generate()) 1639 | // const provider = new anchor.Provider(conn,randWallet,confirmOption) 1640 | // const program = new anchor.Program(idl,programId,provider) 1641 | 1642 | const tokenAccounts = await conn.getParsedTokenAccountsByOwner(owner, {programId: TOKEN_PROGRAM_ID}); 1643 | 1644 | let tokenAccount, tokenAmount; 1645 | 1646 | for (let index = 0; index < tokenAccounts.value.length; index++) { 1647 | tokenAccount = tokenAccounts.value[index]; 1648 | tokenAmount = tokenAccount.account.data.parsed.info.tokenAmount; 1649 | if (tokenAmount.amount == '1' && tokenAmount.decimals == 0) { 1650 | const nftMint = new PublicKey(tokenAccount.account.data.parsed.info.mint) 1651 | let tokenmetaPubkey = await Metadata.getPDA(nftMint); 1652 | allnfts.push(tokenmetaPubkey); 1653 | nftaccounts.push(tokenAccounts.value[index].pubkey) 1654 | } 1655 | } 1656 | 1657 | let nftinfo: any[] = []; 1658 | const buffer = [...allnfts]; 1659 | let count = 100; 1660 | while(buffer.length > 0) { 1661 | if(buffer.length < 100) { 1662 | count = buffer.length; 1663 | } else { 1664 | count = 100; 1665 | } 1666 | nftinfo = [...nftinfo.concat(await conn.getMultipleAccountsInfo(buffer.splice(0, count)))]; 1667 | } 1668 | 1669 | // const nftinfo: any = await conn.getMultipleAccountsInfo(allnfts); 1670 | 1671 | // let tokenCount = nftinfo.length 1672 | 1673 | for(let i = 0; i < nftinfo.length; i++) { 1674 | 1675 | if(nftinfo[i] == null) { 1676 | continue; 1677 | } 1678 | 1679 | let metadata : any = new Metadata(owner.toString(), nftinfo[i]) 1680 | 1681 | if(metadata.data.data.symbol == pD.soldier_symbol) { 1682 | 1683 | // console.log("get data") 1684 | 1685 | let data: any; 1686 | 1687 | try { 1688 | data = await axios.get(metadata.data.data.uri, {timeout: axios_timeout}); 1689 | } catch(error) { 1690 | console.log(error); 1691 | continue; 1692 | } 1693 | 1694 | // console.log("data loaded", data) 1695 | 1696 | if(!data) { 1697 | // console.log("data error") 1698 | continue; 1699 | } 1700 | 1701 | const entireData = { ...data.data, id: Number(data.data.name.replace( /^\D+/g, '').split(' - ')[0])} 1702 | 1703 | // console.log("data", entireData); 1704 | 1705 | let nftMint = new PublicKey(metadata.data.mint) 1706 | if(entireData.attributes.value === pD.halos || entireData.attributes.value === pD.horns) { 1707 | // console.log("mint", nftaccounts[i].toBase58(), nftMint.toBase58()) 1708 | verifiednfts.push({account_address : nftaccounts[i], mint_address : nftMint, ...entireData}) 1709 | } 1710 | } 1711 | } 1712 | 1713 | verifiednfts.sort(function (a: any, b: any) { 1714 | if (a.name < b.name) { return -1; } 1715 | if (a.name > b.name) { return 1; } 1716 | return 0; 1717 | }) 1718 | 1719 | return verifiednfts 1720 | } 1721 | 1722 | async function getStakedNftsForOwner( 1723 | conn : any, 1724 | owner : PublicKey 1725 | ){ 1726 | 1727 | console.log("+ getStakedNftsForOwner") 1728 | 1729 | const verifiednfts: any = []; 1730 | 1731 | const allnfts: any = []; 1732 | 1733 | const stakedNfts: any = []; 1734 | 1735 | const randWallet = new anchor.Wallet(Keypair.generate()) 1736 | const provider = new anchor.Provider(conn,randWallet,confirmOption) 1737 | const program = new anchor.Program(idl,programId,provider) 1738 | 1739 | let resp = await conn.getProgramAccounts(programId,{ 1740 | dataSlice: {length: 0, offset: 0}, 1741 | filters: [{dataSize: 8 + HVH_DATA_SIZE},{memcmp:{offset:8,bytes:owner.toBase58()}},{memcmp:{offset:40,bytes:POOL.toBase58()}}] 1742 | }) 1743 | 1744 | let stakedNft: any; 1745 | 1746 | for (let index = 0; index < resp.length; index++) { 1747 | stakedNft = await program.account.hvHData.fetch(resp[index].pubkey); 1748 | if(stakedNft.unstaked) continue; 1749 | const nftMint = new PublicKey(stakedNft.nftMint) 1750 | let tokenmetaPubkey = await Metadata.getPDA(nftMint); 1751 | allnfts.push(tokenmetaPubkey); 1752 | stakedNfts.push({data: stakedNft, account: resp[index].pubkey}); 1753 | } 1754 | 1755 | let nftinfo: any[] = []; 1756 | const buffer = [...allnfts]; 1757 | let count = 100; 1758 | while(buffer.length > 0) { 1759 | if(buffer.length < 100) { 1760 | count = buffer.length; 1761 | } else { 1762 | count = 100; 1763 | } 1764 | nftinfo = [...nftinfo.concat(await conn.getMultipleAccountsInfo(buffer.splice(0, count)))]; 1765 | } 1766 | 1767 | // const nftinfo: any = await conn.getMultipleAccountsInfo(allnfts); 1768 | 1769 | // let tokenCount = nftinfo.length 1770 | 1771 | for(let i = 0; i < nftinfo.length; i++) { 1772 | 1773 | if(nftinfo[i] == null) { 1774 | continue; 1775 | } 1776 | 1777 | let metadata : any = new Metadata(owner.toString(), nftinfo[i]) 1778 | 1779 | // console.log("get data") 1780 | 1781 | let data: any; 1782 | 1783 | try { 1784 | data = await axios.get(metadata.data.data.uri, {timeout: axios_timeout}); 1785 | } catch(error) { 1786 | console.log(error); 1787 | continue; 1788 | } 1789 | 1790 | // console.log("data loaded", data) 1791 | 1792 | if(!data) { 1793 | // console.log("data error") 1794 | continue; 1795 | } 1796 | 1797 | const entireData = { ...data.data, id: Number(data.data.name.replace( /^\D+/g, '').split(' - ')[0])} 1798 | 1799 | // console.log("data", entireData); 1800 | 1801 | let nftMint = new PublicKey(metadata.data.mint) 1802 | 1803 | // console.log("account", stakedNfts[i].account.toBase58(), nftMint.toBase58()) 1804 | 1805 | // verifiednfts.push({account_address : tokenAccounts.value[i].pubkey, mint_address : nftMint, ...entireData}) 1806 | verifiednfts.push({ 1807 | stakeTime : stakedNft.stakeTime.toNumber(), 1808 | stakeData : stakedNfts[i].account, 1809 | name : entireData.name, 1810 | type : entireData.attributes[0].value, 1811 | ...entireData, 1812 | }) 1813 | } 1814 | 1815 | verifiednfts.sort(function (a: any, b: any) { 1816 | if (a.name < b.name) { return -1; } 1817 | if (a.name > b.name) { return 1; } 1818 | return 0; 1819 | }) 1820 | 1821 | return verifiednfts 1822 | } 1823 | 1824 | // async function getStakedNftsForOwner( 1825 | // conn : Connection, 1826 | // owner : PublicKey, 1827 | // ){ 1828 | // console.log("+ getStakedNftsForOwner") 1829 | // const wallet = new anchor.Wallet(Keypair.generate()); 1830 | // const provider = new anchor.Provider(conn, wallet, anchor.Provider.defaultOptions()); 1831 | // const program = new anchor.Program(idl, programId, provider); 1832 | // const allTokens: any = [] 1833 | // let resp = await conn.getProgramAccounts(programId,{ 1834 | // dataSlice: {length: 0, offset: 0}, 1835 | // filters: [{dataSize: 8 + HVH_DATA_SIZE},{memcmp:{offset:8,bytes:owner.toBase58()}},{memcmp:{offset:40,bytes:POOL.toBase58()}}] 1836 | // }) 1837 | 1838 | // // const tokenAccounts = await conn.getParsedTokenAccountsByOwner(owner, {programId: TOKEN_PROGRAM_ID}); 1839 | 1840 | // // const nftinfo: any = await conn.getMultipleAccountsInfo(allnfts); 1841 | 1842 | // for (let index = 0; index < resp.length; index++) { 1843 | // try { 1844 | // let stakedNft = await program.account.hvHData.fetch(resp[index].pubkey) 1845 | 1846 | // if(stakedNft.unstaked) continue; 1847 | // // let account = await conn.getAccountInfo(stakedNft.nftAccount) 1848 | 1849 | // // let mint = new PublicKey(AccountLayout.decode(account!.data).mint) 1850 | // let pda= await getMetadata(stakedNft.nftMint) 1851 | // const accountInfo: any = await conn.getParsedAccountInfo(pda); 1852 | // let metadata : any = new Metadata(owner.toString(), accountInfo.value); 1853 | // const { data }: any = await axios.get(metadata.data.data.uri, {timeout: axios_timeout}) 1854 | // const entireData = { ...data, id: Number(data.name.replace( /^\D+/g, '').split(' - ')[0])} 1855 | // // console.log(entireData); 1856 | // allTokens.push({ 1857 | // stakeTime : stakedNft.stakeTime.toNumber(), 1858 | // stakeData : resp[index].pubkey, 1859 | // name : entireData.name, 1860 | // type : entireData.attributes[0].value, 1861 | // ...entireData, 1862 | // }) 1863 | 1864 | // // if(index == resp.length - 1) { 1865 | // // console.log("test") 1866 | // // return allTokens 1867 | // // } 1868 | // } catch(error) { 1869 | // console.log(error) 1870 | // continue 1871 | // } 1872 | // } 1873 | 1874 | // return allTokens 1875 | // } 1876 | 1877 | async function getStakedSoldiersForOwner( 1878 | conn : any, 1879 | owner : PublicKey 1880 | ){ 1881 | 1882 | console.log("+ getStakedNftsForOwner") 1883 | 1884 | const verifiednfts: any = []; 1885 | 1886 | const allnfts: any = []; 1887 | 1888 | const stakedNfts: any = []; 1889 | 1890 | const randWallet = new anchor.Wallet(Keypair.generate()) 1891 | const provider = new anchor.Provider(conn,randWallet,confirmOption) 1892 | const program = new anchor.Program(idl,programId,provider) 1893 | 1894 | let resp = await conn.getProgramAccounts(programId,{ 1895 | dataSlice: {length: 0, offset: 0}, 1896 | filters: [{dataSize: 8 + SOLDIER_DATA_SIZE},{memcmp:{offset:8,bytes:owner.toBase58()}},{memcmp:{offset:40,bytes:POOL.toBase58()}}] 1897 | }) 1898 | 1899 | let stakedNft: any; 1900 | 1901 | for (let index = 0; index < resp.length; index++) { 1902 | stakedNft = await program.account.soldierData.fetch(resp[index].pubkey); 1903 | // console.log("test", resp[index].pubkey.toBase58()) 1904 | if(stakedNft.unstaked) continue; 1905 | const nftMint = new PublicKey(stakedNft.nftMint) 1906 | let tokenmetaPubkey = await Metadata.getPDA(nftMint); 1907 | // console.log("test", resp[index].pubkey.toBase58()) 1908 | allnfts.push(tokenmetaPubkey); 1909 | // console.log("test", resp[index].pubkey.toBase58()) 1910 | stakedNfts.push({data: stakedNft, account: resp[index].pubkey}); 1911 | } 1912 | 1913 | let nftinfo: any[] = []; 1914 | const buffer = [...allnfts]; 1915 | let count = 100; 1916 | while(buffer.length > 0) { 1917 | if(buffer.length < 100) { 1918 | count = buffer.length; 1919 | } else { 1920 | count = 100; 1921 | } 1922 | nftinfo = [...nftinfo.concat(await conn.getMultipleAccountsInfo(buffer.splice(0, count)))]; 1923 | } 1924 | 1925 | // const nftinfo: any = await conn.getMultipleAccountsInfo(allnfts); 1926 | 1927 | // let tokenCount = nftinfo.length 1928 | 1929 | for(let i = 0; i < nftinfo.length; i++) { 1930 | 1931 | 1932 | if(nftinfo[i] == null) { 1933 | continue; 1934 | } 1935 | 1936 | let metadata : any = new Metadata(owner.toString(), nftinfo[i]) 1937 | 1938 | // console.log("get data") 1939 | 1940 | let data: any; 1941 | 1942 | try { 1943 | data = await axios.get(metadata.data.data.uri, {timeout: axios_timeout}); 1944 | } catch(error) { 1945 | console.log(error); 1946 | continue; 1947 | } 1948 | 1949 | // console.log("data loaded", data) 1950 | 1951 | if(!data) { 1952 | // console.log("data error") 1953 | continue; 1954 | } 1955 | 1956 | const entireData = { ...data.data, id: Number(data.data.name.replace( /^\D+/g, '').split(' - ')[0])} 1957 | 1958 | // console.log("data", entireData); 1959 | 1960 | let nftMint = new PublicKey(metadata.data.mint) 1961 | 1962 | // console.log("account", stakedNfts[i].account.toBase58(), nftMint.toBase58()) 1963 | 1964 | // verifiednfts.push({account_address : tokenAccounts.value[i].pubkey, mint_address : nftMint, ...entireData}) 1965 | verifiednfts.push({ 1966 | stakeTime : stakedNft.stakeTime.toNumber(), 1967 | stakeData : stakedNfts[i].account, 1968 | stakedType : stakedNft.hvhStr, 1969 | name : entireData.name, 1970 | // type : entireData.attributes[0].value, 1971 | ...entireData, 1972 | ...entireData, 1973 | }) 1974 | } 1975 | 1976 | verifiednfts.sort(function (a: any, b: any) { 1977 | if (a.name < b.name) { return -1; } 1978 | if (a.name > b.name) { return 1; } 1979 | return 0; 1980 | }) 1981 | 1982 | return verifiednfts 1983 | } 1984 | 1985 | // async function getStakedSoldiersForOwner( 1986 | // conn : Connection, 1987 | // owner : PublicKey, 1988 | // ){ 1989 | // console.log("+ getStakedNftsForOwner") 1990 | // const wallet = new anchor.Wallet(Keypair.generate()); 1991 | // const provider = new anchor.Provider(conn, wallet, anchor.Provider.defaultOptions()); 1992 | // const program = new anchor.Program(idl, programId, provider); 1993 | // const allTokens: any = [] 1994 | // let resp = await conn.getProgramAccounts(programId,{ 1995 | // dataSlice: {length: 0, offset: 0}, 1996 | // filters: [{dataSize: 8 + SOLDIER_DATA_SIZE},{memcmp:{offset:8,bytes:owner.toBase58()}},{memcmp:{offset:40,bytes:POOL.toBase58()}}] 1997 | // }) 1998 | 1999 | // for (let index = 0; index < resp.length; index++) { 2000 | // try { 2001 | // let stakedNft = await program.account.soldierData.fetch(resp[index].pubkey) 2002 | // // console.log("test data", stakedNft) 2003 | 2004 | // if(stakedNft.unstaked) continue; 2005 | // // let account = await conn.getAccountInfo(stakedNft.nftAccount) 2006 | 2007 | // // let mint = new PublicKey(AccountLayout.decode(account!.data).mint) 2008 | // let pda= await getMetadata(stakedNft.nftMint) 2009 | // const accountInfo: any = await conn.getParsedAccountInfo(pda); 2010 | // let metadata : any = new Metadata(owner.toString(), accountInfo.value); 2011 | // const { data }: any = await axios.get(metadata.data.data.uri, {timeout: axios_timeout}) 2012 | // const entireData = { ...data, id: Number(data.name.replace( /^\D+/g, '').split(' - ')[0])} 2013 | // // console.log(entireData); 2014 | // allTokens.push({ 2015 | // stakeTime : stakedNft.stakeTime.toNumber(), 2016 | // stakeData : resp[index].pubkey, 2017 | // stakedType : stakedNft.hvhStr, 2018 | // name : entireData.name, 2019 | // // type : entireData.attributes[0].value, 2020 | // ...entireData, 2021 | // }) 2022 | 2023 | // // if(index == resp.length - 1) { 2024 | // // console.log("test") 2025 | // // return allTokens 2026 | // // } 2027 | // } catch(error) { 2028 | // console.log(error) 2029 | // continue 2030 | // } 2031 | 2032 | // } 2033 | 2034 | // return allTokens 2035 | // } 2036 | 2037 | async function getPoolData(){ 2038 | let wallet = new anchor.Wallet(Keypair.generate()) 2039 | let provider = new anchor.Provider(conn,wallet,confirmOption) 2040 | const program = new anchor.Program(idl,programId,provider) 2041 | 2042 | let poolData = await program.account.pool.fetch(POOL) 2043 | 2044 | const unixTime = poolData.startTime.toNumber(); 2045 | const date = new Date(unixTime * 1000); 2046 | 2047 | pD = { 2048 | owner : poolData.owner, 2049 | souls_mint : poolData.soulsMint, 2050 | total_souls : poolData.totalSouls.toNumber(), 2051 | halos_count : poolData.halosCount.toNumber(), 2052 | horns_count : poolData.hornsCount.toNumber(), 2053 | soldier_halos_count : poolData.soldierHalosCount.toNumber(), 2054 | soldier_horns_count : poolData.soldierHornsCount.toNumber(), 2055 | win_percent : poolData.winPercent.toNumber(), 2056 | lose_percent : poolData.losePercent.toNumber(), 2057 | burn_percent : poolData.burnPercent.toNumber(), 2058 | prev_win : poolData.prevWin, 2059 | burned : poolData.burned, 2060 | win_team_stake : poolData.winTeamStake.toNumber(), 2061 | lost_team_stake : poolData.lostTeamStake.toNumber(), 2062 | soulAmount : poolData.soulAmount.toNumber(), 2063 | hvh_percent : poolData.hvhPercent.toNumber(), 2064 | soldier_percent : poolData.soldierPercent.toNumber(), 2065 | token_unit : poolData.tokenUnit.toNumber(), 2066 | staking_period : poolData.stakingPeriod.toNumber(), 2067 | withdraw_period : poolData.withdrawPeriod.toNumber(), 2068 | hvh_symbol : poolData.hvhSymbol, 2069 | soldier_symbol : poolData.soldierSymbol, 2070 | token_halos : poolData.tokenHalos, 2071 | token_horns : poolData.tokenHorns, 2072 | start_time : date.toLocaleString("en-US"), 2073 | abs_start_time : date.toLocaleString("en-US"), 2074 | period : poolData.period.toNumber(), 2075 | } 2076 | 2077 | updateStakingPeriod(); 2078 | } 2079 | 2080 | const getStakingPeriod = () => { 2081 | const total_period = pD.staking_period + pD.withdraw_period; 2082 | const staking_limit = Date.parse(pD.abs_start_time) / 1000 + pD.period * pD.staking_period; 2083 | const withdraw_limit = Date.parse(pD.abs_start_time) / 1000 + pD.period * total_period; 2084 | 2085 | return {total_period, staking_limit, withdraw_limit}; 2086 | } 2087 | 2088 | async function getClaimAmount( 2089 | conn : Connection, 2090 | owner : PublicKey 2091 | ){ 2092 | console.log("+ getClaimAmount") 2093 | const provider = new anchor.Provider(conn, wallet, anchor.Provider.defaultOptions()); 2094 | const program = new anchor.Program(idl, programId, provider); 2095 | 2096 | await getPoolData(); 2097 | 2098 | let claimAmount = 0; 2099 | 2100 | const reward_mint : PublicKey = new PublicKey(REWARD_TOKEN); 2101 | let [stakeState,] = await getProgramAccount(owner, POOL, reward_mint); 2102 | if((await conn.getAccountInfo(stakeState)) == null) { 2103 | notify('error', 'Nothing staked!'); 2104 | setClaimAmount(0); 2105 | // catchFlag = false; 2106 | return 0; 2107 | } 2108 | 2109 | let stakedinfo = await getStakeStateInfo(stakeState) 2110 | 2111 | if(moment().unix() < Date.parse(pD.end_time) / 1000 || moment().unix() > Date.parse(pD.end_withdraw) / 1000) { 2112 | notify('error', 'Not withdraw period'); 2113 | setClaimAmount(0); 2114 | // catchFlag = false; 2115 | return 0; 2116 | } 2117 | 2118 | if(stakedinfo.lastStakeTime.toNumber() < Date.parse(pD.start_time) / 1000) { 2119 | notify('error', 'You should unstake all tokens and stake again'); 2120 | setClaimAmount(0); 2121 | // catchFlag = false; 2122 | return 0; 2123 | } 2124 | 2125 | let total_amount = pD.total_souls; 2126 | 2127 | let hvh_amount = total_amount * pD.hvh_percent / 100; 2128 | let soldier_amount = total_amount * pD.soldier_percent / 100; 2129 | let burn_amount = total_amount * pD.burn_percent / 100; 2130 | 2131 | let claim_amount = 0; 2132 | 2133 | let halos_mul = pD.halos_count / 10 | 0; 2134 | let horns_mul = pD.horns_count / 10 | 0; 2135 | 2136 | let total_halos_soldiers = pD.halos_count + (halos_mul + 1) * pD.soldier_halos_count; 2137 | let total_horns_soldiers = pD.horns_count + pD.soldier_horns_count * (horns_mul + 1); 2138 | 2139 | if (total_halos_soldiers > total_horns_soldiers) { 2140 | if (pD.halos_count != 0) { 2141 | claim_amount = hvh_amount * pD.win_percent / 100 * stakedinfo.halosCount.toNumber() / pD.halos_count; 2142 | } 2143 | if (pD.horns_count != 0) { 2144 | claim_amount += hvh_amount * pD.lose_percent / 100 * stakedinfo.hornsCount.toNumber() / pD.horns_count; 2145 | } 2146 | if (pD.soldier_halos_count != 0) { 2147 | claim_amount += soldier_amount * pD.win_percent / 100 * stakedinfo.soldierHalosCount.toNumber() / pD.soldier_halos_count; 2148 | } 2149 | if (pD.soldier_horns_count != 0) { 2150 | claim_amount += soldier_amount * pD.lose_percent / 100 * stakedinfo.soldierHornsCount.toNumber() / pD.soldier_horns_count; 2151 | } 2152 | } else if (total_halos_soldiers < total_horns_soldiers) { 2153 | if (pD.halos_count != 0) { 2154 | claim_amount = hvh_amount * pD.lose_percent / 100 * stakedinfo.halosCount.toNumber() / pD.halos_count; 2155 | } 2156 | if (pD.horns_count != 0) { 2157 | claim_amount += hvh_amount * pD.win_percent / 100 * stakedinfo.hornsCount.toNumber() / pD.horns_count; 2158 | } 2159 | if (pD.soldier_halos_count != 0) { 2160 | claim_amount += soldier_amount * pD.lose_percent / 100 * stakedinfo.soldierHalosCount.toNumber() / pD.soldier_halos_count; 2161 | } 2162 | if (pD.soldier_horns_count != 0) { 2163 | claim_amount += soldier_amount * pD.win_percent / 100 * stakedinfo.soldierHornsCount.toNumber() / pD.soldier_horns_count; 2164 | } 2165 | } else { 2166 | claim_amount = (stakedinfo.halosCount.toNumber() + stakedinfo.hornsCount.toNumber()) * pD.soulAmount * pD.token_unit; 2167 | if (pD.prev_win == 0) { 2168 | claim_amount += (stakedinfo.soldierHalosCount.toNumber() * pD.win_team_stake + stakedinfo.soldierHornsCount.toNumber() * pD.lost_team_stake) * pD.token_unit; 2169 | } else if (pD.prev_win == 1) { 2170 | claim_amount += (stakedinfo.soldierHalosCount.toNumber() * pD.lost_team_stake + stakedinfo.soldierHornsCount.toNumber() * pD.win_team_stake) * pD.token_unit; 2171 | } else { 2172 | claim_amount = (stakedinfo.soldierHalosCount.toNumber() + stakedinfo.soldierHornsCount.toNumber()) * pD.soulAmount * pD.token_unit; 2173 | } 2174 | } 2175 | 2176 | 2177 | claimAmount = claim_amount / pD.token_unit; 2178 | 2179 | if(stakedinfo.claimed) 2180 | claimAmount = 0; 2181 | 2182 | setClaimAmount(claimAmount); 2183 | } 2184 | 2185 | let sendTransaction = async function sendTransaction(transaction : Transaction,signers : Keypair[]) { 2186 | try{ 2187 | transaction.feePayer = wallet.publicKey 2188 | transaction.recentBlockhash = (await conn.getRecentBlockhash('max')).blockhash; 2189 | // await transaction.setSigners(wallet.publicKey,...signers.map(s => s.publicKey)); 2190 | // if(signers.length != 0) 2191 | // await transaction.partialSign(...signers) 2192 | const signedTransaction = await wallet.signTransaction(transaction); 2193 | let hash = await conn.sendRawTransaction(await signedTransaction.serialize()); 2194 | await conn.confirmTransaction(hash); 2195 | // await getNfts(); 2196 | // setLoading(false); 2197 | notify('success', 'Success!'); 2198 | return true; 2199 | } catch(err) { 2200 | console.log(err) 2201 | // await getNfts() 2202 | notify('error', 'Failed Instruction!'); 2203 | setLoading(false); 2204 | } 2205 | } 2206 | 2207 | async function getNfts(){ 2208 | // setLoading(true); 2209 | nfts.splice(0,nfts.length) 2210 | stakedNfts.splice(0,stakedNfts.length) 2211 | soldiers.slice(0, soldiers.length) 2212 | stakedNfts.slice(0, stakedNfts.length) 2213 | stakedSoldiers.slice(0, stakedSoldiers.length) 2214 | notify('info', 'Loading Info!'); 2215 | await getPoolData() 2216 | await getOwnerStakeStateInfo(); 2217 | notify('info', 'Loading HvH!'); 2218 | nfts = await getNftsForOwner(conn,wallet.publicKey) 2219 | // notify('success', 'HvH Loaded!'); 2220 | notify('info', 'Loading Staked HvH!'); 2221 | stakedNfts = await getStakedNftsForOwner(conn,wallet.publicKey) 2222 | // notify('success', 'Staked HvH Loaded!'); 2223 | notify('info', 'Loading Souldiers!'); 2224 | soldiers = await getSoldiersForOwner(conn, wallet.publicKey) 2225 | // notify('success', 'Soldiers Loaded!'); 2226 | notify('info', 'Loading Staked Souldiers!'); 2227 | stakedSoldiers = await getStakedSoldiersForOwner(conn, wallet.publicKey) 2228 | // notify('success', 'Staked Soldiers Loaded!'); 2229 | notify('info', 'Succesfully Loaded All!'); 2230 | // console.log(nfts, stakedNfts) 2231 | // setLoading(false); 2232 | } 2233 | 2234 | return
2235 | 2236 |
2237 |
2238 |
2239 | 2240 |
2241 |
2242 | {!catchFlag && } 2243 | { catchFlag &&
2244 |
2245 | { fightingFlag === 0 &&
, 2254 | ` }}>
2255 | } 2256 | { fightingFlag === 1 &&
, 2265 | ` }}>
2266 | } 2267 |
2268 |
2269 | { (fightingFlag === 0 || fightingFlag === 1 ) &&

The {winTeam} Are Victorious!

} 2270 | { fightingFlag === 2 &&

The Match Was a Draw!

} 2271 |

Claimable Amount: {claimableAmount}

2272 |
2273 |
2274 | } 2275 |
2276 | {pD && 2277 |
2278 |
2279 |
2280 |

Staking Period:

2281 |

{stakingPeriod.start} - {stakingPeriod.end}

2282 |
2283 |
2284 |

Withdraw Period:

2285 |

{withdrawPeriod.start} - {withdrawPeriod.end}

2286 |
2287 |
2288 |
2289 | } 2290 |
2291 |
2292 |

STAKING PLATFORM

2293 |
2294 |
2295 |
2296 | 2297 |
2298 |
2299 | 2300 |
2301 |
2302 | 2303 |
2304 |
2305 | 2306 |
2307 |
2308 | 2309 |
2310 |
2311 | 2312 |
2313 |
2314 |
2315 |
2316 |
2317 |
2318 |

YOUR WALLET NFT

2319 |
2320 |
2321 | { 2322 | nfts.length &&
2323 | { 2324 | nfts.map((nft,idx)=>{ 2325 | return
2326 |
2327 |

{nft.name}

2328 | Image Error 2329 |
{nft.attributes[0].value}
2330 |
2331 | 2334 |
2335 |
2336 |
2337 | }) 2338 | } 2339 |
2340 | } 2341 |
2342 |
2343 |
2344 |
2345 |

YOUR STAKED NFT

2346 |
2347 |
2348 | { 2349 | stakedNfts.map((nft,idx)=>{ 2350 | return
2351 |
2352 |

{nft.name}

2353 | Image Error 2354 |
{nft.type}
2355 |
{(new Date(nft.stakeTime * 1000)).toLocaleString("en-US")}
2356 |
2357 | 2360 |
2361 |
2362 |
2363 | }) 2364 | } 2365 |
2366 |
2367 |
2368 | 2369 |
2370 |
2371 |
2372 |

YOUR WALLET SOULDIERS

2373 |
2374 |
2375 | { 2376 | soldiers.length &&
2377 | { 2378 | soldiers.map((nft,idx)=>{ 2379 | return
2380 |
2381 |

{nft.name}

2382 | Image Error 2383 | {/*
{nft.attributes[0].value}
*/} 2384 |
2385 | 2389 |
2390 |
2391 |
2392 | }) 2393 | } 2394 |
2395 | } 2396 |
2397 |
2398 |
2399 |
2400 |

YOUR STAKED SOULDIERS

2401 |
2402 |
2403 | { 2404 | stakedSoldiers.map((nft,idx)=>{ 2405 | return
2406 |
2407 |

{nft.name}

2408 | Image Error 2409 |
{nft.stakedType}
2410 |
{(new Date(nft.stakeTime * 1000)).toLocaleString("en-US")}
2411 |
2412 | 2415 |
2416 |
2417 |
2418 | }) 2419 | } 2420 |
2421 |
2422 |
2423 | 2424 |
2425 |

2426 | YOU MUST UNSTAKE YOUR HORNS AND HALOS EACH WEEK AND RESTAKE THEM DURING THE STAKING PERIOD. 2427 |

2428 |

2429 | YOU WILL NOT PARTICIPATE IN COMPETITIVE STAKING IF YOU LEAVE YOUR NFTs STAKED. 2430 |

2431 |
2432 | { ownerstakedinfo &&
2433 | {/*

Your Staking State

*/} 2434 | 2435 | 2436 | 2437 | 2438 | 2439 | 2440 | 2441 | 2442 | 2443 | 2444 | 2445 | 2446 | 2447 | 2448 | 2449 | 2450 | 2451 | 2452 | 2453 | 2454 | 2455 |
StateAmount
Staked Halos Unit{ownerstakedinfo.halos_unit}
Staked Horns Unit{ownerstakedinfo.horns_unit}
Souls in wallet{ownerstakedinfo.souls}
2456 |
2457 | } 2458 |
2459 | 2460 | 2461 |
2462 |
2463 |

2464 | JOIN THE COMMUNITY 2465 |

2466 |
2467 |
2468 | 2469 | 2470 |
2471 | {/* */} 2474 | 2475 | stakeSoldierToHalos()} 2478 | OnHorns={() => stakeSoldierToHorns()} 2479 | onHide={() => setModalShow(false)} 2480 | /> 2481 | 2482 | {/*
2483 |
2484 |

Today: {todaystr}

2485 |
2486 |
2487 |
2488 |
2489 |

2490 | YOU MUST UNSTAKE YOUR HORNS AND HALOS EACH WEEK AND RESTAKE THEM DURING THE STAKING PERIOD. 2491 |

2492 |

2493 | YOU WILL NOT PARTICIPATE IN COMPETITIVE STAKING IF YOU LEAVE YOUR NFTs STAKED. 2494 |

2495 |
2496 |
2497 | {pD && 2498 |
2499 |
2500 |
2501 |

Staking Period:

2502 |

{stakingPeriod.start} - {stakingPeriod.end}

2503 |
2504 |
2505 |

Withdraw Period:

2506 |

{withdrawPeriod.start} - {withdrawPeriod.end}

2507 |
2508 |
2509 |
2510 | } 2511 |
2512 | { catchFlag &&
2513 |
2514 |
2515 | { (fightingFlag === 0 || fightingFlag === 1 ) &&

The {winTeam} Are Victorious!

} 2516 | { fightingFlag === 2 &&

The Match Was a Draw!

} 2517 |
2518 |
2519 | 2520 |
2521 | { fightingFlag === 0 &&
, 2530 | ` }}>
2531 | } 2532 | { fightingFlag === 1 &&
, 2541 | ` }}>
2542 | } 2543 |
2544 |
2545 |
2546 |

Your Claimable Amount: {claimableAmount}

2547 |
2548 |
2549 | 2550 |
2551 |
2552 |
2553 | } 2554 |
2555 | { pD &&
2556 |

Pool State

2557 | 2558 | 2559 | 2560 | 2561 | 2562 | 2563 | 2564 | 2565 | 2566 | 2567 | 2568 | 2569 | 2570 | 2571 | 2572 | 2573 | 2574 | 2575 | 2576 | 2577 | 2578 | 2579 | 2580 | 2581 | 2582 | 2583 | 2584 | 2585 | 2586 | 2587 | 2588 | 2589 | 2590 | 2591 | 2592 | 2593 | 2594 | 2595 | 2596 | 2597 | 2598 | 2599 | 2600 | 2601 | 2602 | 2603 | 2604 | 2605 | 2606 |
StateAmount
Staked souls{pD.total_souls / pD.token_unit}
Souls per NFT{pD.soulAmount}
Staked Halos{pD.halos_count}
Staked Horns{pD.horns_count}
Winning{pD.win_percent}%
Fail{pD.lose_percent}%
Burn{pD.burn_percent}%
2607 |
2608 | } 2609 |
2610 | { ownerstakedinfo &&
2611 |

Your Staking State

2612 | 2613 | 2614 | 2615 | 2616 | 2617 | 2618 | 2619 | 2620 | 2621 | 2622 | 2623 | 2624 | 2625 | 2626 | 2627 | 2628 | 2629 | 2630 | 2631 | 2632 | 2633 |
StateAmount
Staked Halos{ownerstakedinfo.halosCount.toNumber()}
Staked Horns{ownerstakedinfo.hornsCount.toNumber()}
Souls in wallet{ownerstakedinfo.souls}
2634 |
2635 | } 2636 |
2637 |
2638 |
2639 |
2640 |
2641 |
2642 |

Your Wallet NFT

2643 |
2644 |
2645 | 2648 | 2651 |
2652 |
2653 |
2654 | {nfts.length &&
2655 | { 2656 | nfts.map((nft,idx)=>{ 2657 | // console.log(nft); 2658 | return
2659 |
2660 |

{nft.name}

2661 | Image Error 2662 |
{nft.attributes[0].value}
2663 |
2664 | 2667 |
2668 |
2669 |
2670 | }) 2671 | } 2672 |
2673 | } 2674 |
2675 |
2676 |
2677 |
2678 |
2679 |
2680 |
2681 |

Your Staked NFT

2682 |
2683 |
2684 | 2687 |
2688 |
2689 |
2690 |
2691 |
2692 | { 2693 | stakedNfts.map((nft,idx)=>{ 2694 | return
2695 |
2696 |

{nft.name}

2697 | Image Error 2698 |
{nft.type}
2699 |
{(new Date(nft.stakeTime * 1000)).toLocaleString("en-US")}
2700 |
2701 | 2704 |
2705 |
2706 |
2707 | }) 2708 | } 2709 |
2710 |
2711 |
2712 |
2713 |
*/} 2714 |
2715 | } -------------------------------------------------------------------------------- /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /src/wallet/connect.tsx: -------------------------------------------------------------------------------- 1 | import { WalletMultiButton } from '@solana/wallet-adapter-react-ui'; 2 | 3 | export default function WalletConnect(): JSX.Element { 4 | return (<> 5 | 6 | 7 | ); 8 | } -------------------------------------------------------------------------------- /src/wallet/disconnect.tsx: -------------------------------------------------------------------------------- 1 | import { WalletDisconnectButton } from '@solana/wallet-adapter-react-ui'; 2 | 3 | export default function WalletConnect(): JSX.Element { 4 | return ; 5 | } 6 | -------------------------------------------------------------------------------- /src/wallet/index.ts: -------------------------------------------------------------------------------- 1 | export { default as WalletConnect } from './connect'; 2 | export { default as WalletDisconnect } from './disconnect'; 3 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "downlevelIteration": true, 5 | "lib": [ 6 | "dom", 7 | "dom.iterable", 8 | "esnext" 9 | ], 10 | "allowJs": true, 11 | "skipLibCheck": true, 12 | "esModuleInterop": true, 13 | "allowSyntheticDefaultImports": true, 14 | "strict": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "noFallthroughCasesInSwitch": true, 17 | "module": "esnext", 18 | "moduleResolution": "node", 19 | "resolveJsonModule": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx", 22 | "isolatedModules": true 23 | }, 24 | "include": [ 25 | "src", 26 | "src/declare.d.ts" 27 | ] 28 | } 29 | --------------------------------------------------------------------------------