create-dubhe 1.2.0-pre.98 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/package.json +16 -16
- package/templates/101/sui-template/docker-compose.testnet.yml +73 -0
- package/templates/101/sui-template/packages/client/src/app/page.tsx +545 -41
- package/templates/101/sui-template/packages/client/src/app/providers.tsx +12 -4
- package/templates/101/sui-template/packages/contracts/Pub.localnet.toml +4 -4
- package/templates/101/sui-template/packages/contracts/counter.lock.json +20 -0
- package/templates/101/sui-template/packages/contracts/deployment.ts +8 -3
- package/templates/101/sui-template/packages/contracts/dubhe.config.json +59 -13
- package/templates/101/sui-template/packages/contracts/dubhe.config.ts +1 -4
- package/templates/101/sui-template/packages/contracts/metadata.json +1015 -68
- package/templates/101/sui-template/packages/contracts/package.json +7 -4
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move +45 -31
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/error.move +8 -0
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/genesis.move +30 -13
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/init_test.move +19 -14
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter2.move +198 -0
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter2withkey.move +90 -0
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/resources/value.move +30 -20
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/user_storage_init.move +26 -0
- package/templates/101/sui-template/packages/contracts/src/counter/sources/scripts/deploy_hook.move +6 -11
- package/templates/101/sui-template/packages/contracts/src/counter/sources/systems/counter.move +23 -11
- package/templates/101/sui-template/packages/contracts/src/counter/sources/tests/counter.move +15 -14
- package/templates/101/sui-template/packages/contracts/src/dubhe/Move.lock +33 -30
- package/templates/101/sui-template/packages/contracts/src/dubhe/Move.toml +8 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move +45 -31
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/error.move +170 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/genesis.move +16 -13
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/init_test.move +8 -14
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/account_key.move +1 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/dapp_service.move +1776 -137
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/data_key.move +1 -20
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/events.move +864 -25
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/scripts/deploy_hook.move +15 -16
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/scripts/migrate.move +0 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/address_system.move +25 -17
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +2802 -343
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/utils.move +1 -1
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/address.move +173 -55
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/dapp_test.move +769 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/fee_test.move +2965 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/integration_test.move +303 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/listing_test.move +1422 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/scene_session_test.move +269 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/session_test.move +624 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/storage_test.move +700 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/typed_object_test.move +177 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/typed_scene_test.move +452 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/user_storage_test.move +160 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/utils/math.move +4 -3
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/utils/type_info.move +2 -2
- package/templates/contract/sui-template/dubhe.config.ts +0 -1
- package/templates/contract/sui-template/package.json +3 -3
- package/templates/contract/sui-template/src/dubhe/Move.lock +33 -30
- package/templates/contract/sui-template/src/dubhe/Move.toml +8 -3
- package/templates/contract/sui-template/src/dubhe/sources/codegen/dapp_key.move +45 -31
- package/templates/contract/sui-template/src/dubhe/sources/codegen/error.move +170 -0
- package/templates/contract/sui-template/src/dubhe/sources/codegen/genesis.move +16 -13
- package/templates/contract/sui-template/src/dubhe/sources/codegen/init_test.move +8 -14
- package/templates/contract/sui-template/src/dubhe/sources/core/account_key.move +1 -3
- package/templates/contract/sui-template/src/dubhe/sources/core/dapp_service.move +1776 -137
- package/templates/contract/sui-template/src/dubhe/sources/core/data_key.move +1 -20
- package/templates/contract/sui-template/src/dubhe/sources/core/events.move +864 -25
- package/templates/contract/sui-template/src/dubhe/sources/scripts/deploy_hook.move +15 -16
- package/templates/contract/sui-template/src/dubhe/sources/scripts/migrate.move +0 -3
- package/templates/contract/sui-template/src/dubhe/sources/systems/address_system.move +25 -17
- package/templates/contract/sui-template/src/dubhe/sources/systems/dapp_system.move +2802 -343
- package/templates/contract/sui-template/src/dubhe/sources/systems/utils.move +1 -1
- package/templates/contract/sui-template/src/dubhe/sources/tests/address.move +173 -55
- package/templates/contract/sui-template/src/dubhe/sources/tests/dapp_test.move +769 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/fee_test.move +2965 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/integration_test.move +303 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/listing_test.move +1422 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/scene_session_test.move +269 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/session_test.move +624 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/storage_test.move +700 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/typed_object_test.move +177 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/typed_scene_test.move +452 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/user_storage_test.move +160 -0
- package/templates/contract/sui-template/src/dubhe/sources/utils/math.move +4 -3
- package/templates/contract/sui-template/src/dubhe/sources/utils/type_info.move +2 -2
- package/templates/contract/sui-template/src/template/Move.toml +12 -0
- package/templates/contract/sui-template/src/template/sources/codegen/dapp_key.move +47 -0
- package/templates/contract/sui-template/src/template/sources/codegen/genesis.move +34 -0
- package/templates/contract/sui-template/src/template/sources/codegen/init_test.move +23 -0
- package/templates/contract/sui-template/src/template/sources/codegen/user_storage_init.move +27 -0
- package/templates/contract/sui-template/src/template/sources/scripts/deploy_hook.move +13 -0
- package/templates/contract/sui-template/src/template/sources/scripts/migrate.move +7 -0
- package/templates/nextjs/sui-card-duel/.gitignore_ +51 -0
- package/templates/nextjs/sui-card-duel/README.md +213 -0
- package/templates/nextjs/sui-card-duel/docker-compose.yml +34 -0
- package/templates/nextjs/sui-card-duel/mprocs.yaml +17 -0
- package/templates/nextjs/sui-card-duel/package.json +43 -0
- package/templates/nextjs/sui-card-duel/packages/client/.gitignore_ +48 -0
- package/templates/nextjs/sui-card-duel/packages/client/.prettierignore +1 -0
- package/templates/nextjs/sui-card-duel/packages/client/.prettierrc.json +8 -0
- package/templates/nextjs/sui-card-duel/packages/client/eslint.config.mjs +22 -0
- package/templates/nextjs/sui-card-duel/packages/client/next.config.mjs +8 -0
- package/templates/nextjs/sui-card-duel/packages/client/package.json +47 -0
- package/templates/nextjs/sui-card-duel/packages/client/postcss.config.mjs +8 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/admin/ArenaPanel.tsx +307 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/admin/page.tsx +622 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/brawl/[id]/page.tsx +559 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/collection/page.tsx +202 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/components/CardView.tsx +66 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/components/GameShell.tsx +294 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/components/icons.tsx +101 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/duel/[id]/page.tsx +477 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/favicon.ico +0 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/globals.css +85 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/hooks/useGame.ts +313 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/layout.tsx +24 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/leaderboard/page.tsx +123 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/lib/game.ts +77 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/lib/scenes.ts +226 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/market/page.tsx +418 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/page.tsx +427 -0
- package/templates/nextjs/sui-card-duel/packages/client/src/app/providers.tsx +69 -0
- package/templates/nextjs/sui-card-duel/packages/client/tailwind.config.ts +21 -0
- package/templates/nextjs/sui-card-duel/packages/client/tsconfig.json +30 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/.gitignore_ +51 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/.prettierignore +1 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/.prettierrc.json +8 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/Dockerfile +5 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/Pub.localnet.toml +13 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/card_duel.lock.json +66 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/docker-compose.yml +34 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/dubhe.config.ts +150 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/logs/combined.log +31383 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/package.json +49 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/config.ts +17 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-brawl.ts +270 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-duel.ts +272 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-lobby.ts +177 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-market.ts +219 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/e2e-session.ts +342 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/query-dapp-revenue.ts +95 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/seed.ts +92 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/scripts/withdraw-dapp-revenue.ts +56 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/Move.toml +15 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/dapp_key.move +46 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/enums/card_kind.move +47 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/enums/match_state.move +37 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/enums/rarity.move +37 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/error.move +126 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/genesis.move +33 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/init_test.move +23 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/objects/arena.move +137 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/permits/brawl_permit.move +125 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/permits/duel_permit.move +125 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/battle_state.move +255 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/card.move +282 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/deck.move +64 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/game_config.move +267 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/gold.move +205 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/resources/profile.move +255 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/scenes/brawl.move +313 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/scenes/duel.move +313 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/codegen/user_storage_init.move +26 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/scripts/deploy_hook.move +32 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/scripts/migrate.move +7 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/arena_system.move +57 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/brawl_system.move +559 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/card_system.move +146 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/duel_system.move +515 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/market_system.move +115 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/systems/player_system.move +37 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/tests/brawl_tests.move +385 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/tests/duel_tests.move +656 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/src/card_duel/sources/tests/test_helpers.move +31 -0
- package/templates/nextjs/sui-card-duel/packages/contracts/sui-indexer-schema.graphql +5973 -0
- package/templates/nextjs/sui-card-duel/pnpm-workspace.yaml +2 -0
- package/templates/nextjs/sui-farm/.gitignore_ +51 -0
- package/templates/nextjs/sui-farm/README.md +15 -0
- package/templates/nextjs/sui-farm/UPGRADE_NOTES.md +97 -0
- package/templates/nextjs/sui-farm/docker-compose.yml +34 -0
- package/templates/nextjs/sui-farm/mprocs.yaml +17 -0
- package/templates/nextjs/sui-farm/package.json +43 -0
- package/templates/nextjs/sui-farm/packages/client/.gitignore_ +48 -0
- package/templates/nextjs/sui-farm/packages/client/.prettierignore +1 -0
- package/templates/nextjs/sui-farm/packages/client/.prettierrc.json +8 -0
- package/templates/nextjs/sui-farm/packages/client/eslint.config.mjs +22 -0
- package/templates/nextjs/sui-farm/packages/client/next.config.mjs +8 -0
- package/templates/nextjs/sui-farm/packages/client/package.json +47 -0
- package/templates/nextjs/sui-farm/packages/client/postcss.config.mjs +8 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/admin/page.tsx +618 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/FarmLand.tsx +526 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/FarmPlotCard.tsx +215 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/PetAvatar.tsx +868 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/PetPanel.tsx +1360 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/PlantModal.tsx +147 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/ProxyCard.tsx +684 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/RanchLand.tsx +822 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/ResourceHUD.tsx +125 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/ShopPanel.tsx +232 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/icons/GameIcons.tsx +574 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/favicon.ico +0 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/globals.css +423 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/hooks/useWorldPermitId.ts +66 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/layout.tsx +23 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/leaderboard/page.tsx +185 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/lib/crops.ts +97 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/market/page.tsx +763 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/page.tsx +1173 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/providers.tsx +69 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/state/index.tsx +5 -0
- package/templates/nextjs/sui-farm/packages/client/tailwind.config.ts +25 -0
- package/templates/nextjs/sui-farm/packages/client/tsconfig.json +30 -0
- package/templates/nextjs/sui-farm/packages/contracts/.gitignore_ +51 -0
- package/templates/nextjs/sui-farm/packages/contracts/.prettierignore +1 -0
- package/templates/nextjs/sui-farm/packages/contracts/.prettierrc.json +8 -0
- package/templates/nextjs/sui-farm/packages/contracts/Dockerfile +5 -0
- package/templates/nextjs/sui-farm/packages/contracts/Pub.localnet.toml +13 -0
- package/templates/nextjs/sui-farm/packages/contracts/counter.lock.json +14 -0
- package/templates/nextjs/sui-farm/packages/contracts/docker-compose.yml +34 -0
- package/templates/nextjs/sui-farm/packages/contracts/dubhe.config.ts +178 -0
- package/templates/nextjs/sui-farm/packages/contracts/harvest.lock.json +120 -0
- package/templates/nextjs/sui-farm/packages/contracts/package.json +48 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/config.ts +17 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/query-dapp-revenue.ts +95 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/read-permit.ts +72 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/seed.ts +85 -0
- package/templates/nextjs/sui-farm/packages/contracts/scripts/withdraw-dapp-revenue.ts +56 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/Move.toml +14 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/dapp_key.move +31 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/error.move +10 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/genesis.move +33 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/init_test.move +23 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/resources/counter1.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/resources/counter2.move +70 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/user_storage_init.move +26 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/scripts/deploy_hook.move +8 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/scripts/migrate.move +8 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/systems/counter.move +13 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/tests/counter.move +28 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/Move.toml +14 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/dapp_key.move +46 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/crop_type.move +47 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/egg_type.move +42 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/pet_rarity.move +37 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/enums/pet_species.move +52 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/error.move +110 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/genesis.move +33 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/init_test.move +23 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/permits/world.move +125 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/carrot.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/carrot_seed.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/common_egg.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/corn.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/corn_seed.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/crow_charges.move +162 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/crow_damage.move +207 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/farm_plot.move +261 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/gold.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet.move +467 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_config.move +372 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_hatch.move +162 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_slot_index.move +83 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pet_slots.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/profile.move +162 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pumpkin.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/pumpkin_seed.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/rare_egg.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/scarecrow.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/season_config.move +197 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/season_stats.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/seasonal_egg.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/shop_config.move +267 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/trophy.move +245 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/wheat.move +136 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/wheat_seed.move +80 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/resources/world_permit_id.move +64 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/user_storage_init.move +26 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/scripts/deploy_hook.move +45 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/scripts/migrate.move +7 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/crow_system.move +96 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/farm_system.move +182 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/market_system.move +172 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/pet_system.move +495 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/season_system.move +70 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/shop_system.move +112 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/world_system.move +34 -0
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/tests/farm_tests.move +1192 -0
- package/templates/nextjs/sui-farm/pnpm-workspace.yaml +2 -0
- package/templates/nextjs/sui-template/packages/client/src/app/components/ProxyCard.tsx +683 -0
- package/templates/nextjs/sui-template/packages/client/src/app/page.tsx +510 -5
- package/templates/nextjs/sui-template/packages/client/src/app/providers.tsx +13 -5
- package/templates/nextjs/sui-template/packages/contracts/Pub.localnet.toml +4 -4
- package/templates/nextjs/sui-template/packages/contracts/counter.lock.json +14 -0
- package/templates/nextjs/sui-template/packages/contracts/deployment.ts +8 -3
- package/templates/nextjs/sui-template/packages/contracts/dubhe.config.json +9 -9
- package/templates/nextjs/sui-template/packages/contracts/dubhe.config.ts +0 -4
- package/templates/nextjs/sui-template/packages/contracts/metadata.json +180 -124
- package/templates/nextjs/sui-template/packages/contracts/package.json +8 -4
- package/templates/nextjs/sui-template/packages/contracts/src/counter/Move.toml +4 -0
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move +45 -31
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/error.move +10 -0
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/genesis.move +30 -13
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/init_test.move +19 -14
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter1.move +30 -20
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/resources/counter2.move +35 -24
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/user_storage_init.move +26 -0
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/scripts/deploy_hook.move +6 -10
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/systems/counter.move +7 -20
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/tests/counter.move +14 -27
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/Move.lock +33 -30
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/Move.toml +8 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move +45 -31
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/error.move +170 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/genesis.move +16 -13
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/init_test.move +8 -14
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/account_key.move +1 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/dapp_service.move +1776 -137
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/data_key.move +1 -20
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/events.move +864 -25
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/scripts/deploy_hook.move +15 -16
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/scripts/migrate.move +0 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/address_system.move +25 -17
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +2802 -343
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/utils.move +1 -1
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/address.move +173 -55
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/dapp_test.move +769 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/fee_test.move +2965 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/integration_test.move +303 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/listing_test.move +1422 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/scene_session_test.move +269 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/session_test.move +624 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/storage_test.move +700 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/typed_object_test.move +177 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/typed_scene_test.move +452 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/user_storage_test.move +160 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/utils/math.move +4 -3
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/utils/type_info.move +2 -2
- package/templates/101/sui-template/packages/contracts/src/counter/Move.lock +0 -41
- package/templates/101/sui-template/packages/contracts/src/counter/Published.toml +0 -9
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/errors.move +0 -12
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/errors.move +0 -140
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_config.move +0 -186
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_state.move +0 -306
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_metadata.move +0 -396
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dubhe_config.move +0 -246
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/core/dapp_store.move +0 -29
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/session_system.move +0 -44
- package/templates/contract/sui-template/src/dubhe/sources/codegen/errors.move +0 -140
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_fee_config.move +0 -186
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_fee_state.move +0 -306
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dapp_metadata.move +0 -396
- package/templates/contract/sui-template/src/dubhe/sources/codegen/resources/dubhe_config.move +0 -246
- package/templates/contract/sui-template/src/dubhe/sources/core/dapp_store.move +0 -29
- package/templates/contract/sui-template/src/dubhe/sources/systems/session_system.move +0 -44
- package/templates/nextjs/sui-template/packages/contracts/src/counter/Move.lock +0 -47
- package/templates/nextjs/sui-template/packages/contracts/src/counter/Published.toml +0 -9
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/errors.move +0 -12
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/errors.move +0 -140
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_config.move +0 -186
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_fee_state.move +0 -306
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dapp_metadata.move +0 -396
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/resources/dubhe_config.move +0 -246
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/dapp_store.move +0 -29
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/session_system.move +0 -44
|
@@ -0,0 +1,763 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
4
|
+
import { ConnectButton, useCurrentAccount, useSignAndExecuteTransaction } from '@mysten/dapp-kit';
|
|
5
|
+
import { useDubhe } from '@0xobelisk/react/sui';
|
|
6
|
+
import { Transaction } from '@0xobelisk/sui-client';
|
|
7
|
+
import { decodeU64, parseRecordData } from '@0xobelisk/graphql-client';
|
|
8
|
+
import { toast } from 'sonner';
|
|
9
|
+
import { motion } from 'framer-motion';
|
|
10
|
+
import { CROP_LIST } from '../lib/crops';
|
|
11
|
+
import { DappHubId, DappStorageId, PackageId, Network } from 'contracts/deployment';
|
|
12
|
+
import {
|
|
13
|
+
SPECIES_NAME,
|
|
14
|
+
RARITY_LABEL,
|
|
15
|
+
RARITY_COLOR,
|
|
16
|
+
FAVORITE_FOOD,
|
|
17
|
+
type PetData
|
|
18
|
+
} from '../components/PetPanel';
|
|
19
|
+
import { PetAvatar, EggIcon, IconShop } from '../components/PetAvatar';
|
|
20
|
+
import { IconGold } from '../components/icons/GameIcons';
|
|
21
|
+
|
|
22
|
+
// ── BCS helpers ──────────────────────────────────────────────────────────────
|
|
23
|
+
|
|
24
|
+
// recordDataRaw is a JSON array of per-field hex strings; the fungible
|
|
25
|
+
// listings here carry a single u64 amount as the first field.
|
|
26
|
+
function decodeBcsU64(raw: string): bigint {
|
|
27
|
+
return decodeU64(parseRecordData(raw)[0] ?? '0x00');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ── Types ─────────────────────────────────────────────────────────────────────
|
|
31
|
+
|
|
32
|
+
interface CropListing {
|
|
33
|
+
id: string;
|
|
34
|
+
seller: string;
|
|
35
|
+
cropType: number;
|
|
36
|
+
cropName: string;
|
|
37
|
+
amount: bigint;
|
|
38
|
+
price: bigint;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface EggListing {
|
|
42
|
+
id: string;
|
|
43
|
+
seller: string;
|
|
44
|
+
eggType: number; // 1=common 2=rare 3=seasonal
|
|
45
|
+
amount: bigint;
|
|
46
|
+
price: bigint;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface PetListing {
|
|
50
|
+
id: string;
|
|
51
|
+
seller: string;
|
|
52
|
+
pet: PetData;
|
|
53
|
+
price: bigint;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const CROP_NAMES: Record<number, string> = { 1: 'wheat', 2: 'corn', 3: 'carrot', 4: 'pumpkin' };
|
|
57
|
+
const CROP_BY_NAME: Record<string, number> = { wheat: 1, corn: 2, carrot: 3, pumpkin: 4 };
|
|
58
|
+
const EGG_NAMES: Record<number, string> = { 1: 'common_egg', 2: 'rare_egg', 3: 'seasonal_egg' };
|
|
59
|
+
const EGG_BY_NAME: Record<string, number> = { common_egg: 1, rare_egg: 2, seasonal_egg: 3 };
|
|
60
|
+
const EGG_LABEL: Record<number, string> = { 1: 'Common', 2: 'Rare', 3: 'Seasonal' };
|
|
61
|
+
|
|
62
|
+
// ── Component ─────────────────────────────────────────────────────────────────
|
|
63
|
+
|
|
64
|
+
export default function MarketPage() {
|
|
65
|
+
const account = useCurrentAccount();
|
|
66
|
+
const { mutateAsync: signAndExecuteTransaction } = useSignAndExecuteTransaction();
|
|
67
|
+
const {
|
|
68
|
+
contract: dubhe,
|
|
69
|
+
graphqlClient,
|
|
70
|
+
dappStorageId,
|
|
71
|
+
dappHubId,
|
|
72
|
+
network,
|
|
73
|
+
packageId
|
|
74
|
+
} = useDubhe();
|
|
75
|
+
const storageId = dappStorageId ?? DappStorageId;
|
|
76
|
+
const hubId = dappHubId ?? DappHubId;
|
|
77
|
+
const pkg = packageId ?? PackageId;
|
|
78
|
+
|
|
79
|
+
const [activeTab, setActiveTab] = useState<'crops' | 'eggs' | 'pets'>('crops');
|
|
80
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
81
|
+
const [userStorageId, setUserStorageId] = useState<string | null>(null);
|
|
82
|
+
|
|
83
|
+
// Crops
|
|
84
|
+
const [cropListings, setCropListings] = useState<CropListing[]>([]);
|
|
85
|
+
const [cropInv, setCropInv] = useState<Record<number, bigint>>({});
|
|
86
|
+
const [listForm, setListForm] = useState({ cropType: 1, amount: 1, pricePerUnit: 10_000_000 });
|
|
87
|
+
|
|
88
|
+
// Eggs
|
|
89
|
+
const [eggListings, setEggListings] = useState<EggListing[]>([]);
|
|
90
|
+
const [eggInv, setEggInv] = useState<Record<number, bigint>>({});
|
|
91
|
+
const [eggListForm, setEggListForm] = useState({ eggType: 1, amount: 1, price: 0 });
|
|
92
|
+
|
|
93
|
+
// Pets
|
|
94
|
+
const [petListings, setPetListings] = useState<PetListing[]>([]);
|
|
95
|
+
|
|
96
|
+
// ── Fetch ──────────────────────────────────────────────────────────────────
|
|
97
|
+
|
|
98
|
+
const fetchAll = useCallback(async () => {
|
|
99
|
+
if (!graphqlClient) return;
|
|
100
|
+
try {
|
|
101
|
+
const result = await graphqlClient.getMarketplaceListings({ status: 'listed' });
|
|
102
|
+
|
|
103
|
+
const crops: CropListing[] = [];
|
|
104
|
+
const eggs: EggListing[] = [];
|
|
105
|
+
const pets: PetListing[] = [];
|
|
106
|
+
|
|
107
|
+
result.edges.forEach(({ node }) => {
|
|
108
|
+
const { recordType, listingId, seller, price, recordDataRaw } = node;
|
|
109
|
+
|
|
110
|
+
if (recordType in CROP_BY_NAME) {
|
|
111
|
+
const amount = decodeBcsU64(recordDataRaw);
|
|
112
|
+
crops.push({
|
|
113
|
+
id: listingId,
|
|
114
|
+
seller,
|
|
115
|
+
cropType: CROP_BY_NAME[recordType],
|
|
116
|
+
cropName: recordType,
|
|
117
|
+
amount,
|
|
118
|
+
price: BigInt(price)
|
|
119
|
+
});
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (recordType in EGG_BY_NAME) {
|
|
123
|
+
const amount = decodeBcsU64(recordDataRaw);
|
|
124
|
+
eggs.push({
|
|
125
|
+
id: listingId,
|
|
126
|
+
seller,
|
|
127
|
+
eggType: EGG_BY_NAME[recordType],
|
|
128
|
+
amount,
|
|
129
|
+
price: BigInt(price)
|
|
130
|
+
});
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (recordType === 'pet') {
|
|
134
|
+
try {
|
|
135
|
+
// recordDataRaw fields (no slot field): species, rarity, level, xp, happiness, satiety, fed_at, born_at
|
|
136
|
+
const raw = JSON.parse(recordDataRaw) as string[];
|
|
137
|
+
const petData: PetData = {
|
|
138
|
+
petId: listingId, // use listing id as display key; real pet_id is in record_key
|
|
139
|
+
species: parseInt(raw[0] ?? '0x00', 16),
|
|
140
|
+
rarity: parseInt(raw[1] ?? '0x00', 16),
|
|
141
|
+
level: parseInt(raw[2] ?? '0x00', 16),
|
|
142
|
+
xp: 0,
|
|
143
|
+
happiness: parseInt(raw[4] ?? '0x00', 16),
|
|
144
|
+
satiety: parseInt(raw[5] ?? '0x00', 16),
|
|
145
|
+
fedAt: 0,
|
|
146
|
+
bornAt: 0
|
|
147
|
+
};
|
|
148
|
+
pets.push({ id: listingId, seller, pet: petData, price: BigInt(price) });
|
|
149
|
+
} catch {
|
|
150
|
+
/* skip malformed */
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
setCropListings(crops);
|
|
156
|
+
setEggListings(eggs);
|
|
157
|
+
setPetListings(pets);
|
|
158
|
+
} catch (err) {
|
|
159
|
+
console.error('[market] fetchAll error:', err);
|
|
160
|
+
}
|
|
161
|
+
}, [graphqlClient]);
|
|
162
|
+
|
|
163
|
+
const fetchInventory = useCallback(async () => {
|
|
164
|
+
if (!graphqlClient || !account?.address) return;
|
|
165
|
+
const addr = account.address;
|
|
166
|
+
try {
|
|
167
|
+
const [w, c, ca, p, ce, re, se] = await Promise.all([
|
|
168
|
+
graphqlClient.getTableByCondition<any>('wheat', { entityId: addr }).catch(() => null),
|
|
169
|
+
graphqlClient.getTableByCondition<any>('corn', { entityId: addr }).catch(() => null),
|
|
170
|
+
graphqlClient.getTableByCondition<any>('carrot', { entityId: addr }).catch(() => null),
|
|
171
|
+
graphqlClient.getTableByCondition<any>('pumpkin', { entityId: addr }).catch(() => null),
|
|
172
|
+
graphqlClient.getTableByCondition<any>('common_egg', { entityId: addr }).catch(() => null),
|
|
173
|
+
graphqlClient.getTableByCondition<any>('rare_egg', { entityId: addr }).catch(() => null),
|
|
174
|
+
graphqlClient.getTableByCondition<any>('seasonal_egg', { entityId: addr }).catch(() => null)
|
|
175
|
+
]);
|
|
176
|
+
setCropInv({
|
|
177
|
+
1: BigInt(w?.amount ?? 0),
|
|
178
|
+
2: BigInt(c?.amount ?? 0),
|
|
179
|
+
3: BigInt(ca?.amount ?? 0),
|
|
180
|
+
4: BigInt(p?.amount ?? 0)
|
|
181
|
+
});
|
|
182
|
+
setEggInv({
|
|
183
|
+
1: BigInt(ce?.amount ?? 0),
|
|
184
|
+
2: BigInt(re?.amount ?? 0),
|
|
185
|
+
3: BigInt(se?.amount ?? 0)
|
|
186
|
+
});
|
|
187
|
+
} catch (err) {
|
|
188
|
+
console.error('[market] fetchInventory error:', err);
|
|
189
|
+
}
|
|
190
|
+
}, [graphqlClient, account?.address]);
|
|
191
|
+
|
|
192
|
+
const fetchUserStorageId = useCallback(async () => {
|
|
193
|
+
if (!dubhe || !account?.address) return;
|
|
194
|
+
try {
|
|
195
|
+
setUserStorageId(await dubhe.getUserStorageId(account.address));
|
|
196
|
+
} catch {}
|
|
197
|
+
}, [dubhe, account?.address]);
|
|
198
|
+
|
|
199
|
+
useEffect(() => {
|
|
200
|
+
if (account && graphqlClient) {
|
|
201
|
+
fetchAll();
|
|
202
|
+
fetchInventory();
|
|
203
|
+
}
|
|
204
|
+
if (account && dubhe) fetchUserStorageId();
|
|
205
|
+
}, [account, dubhe, graphqlClient, fetchAll, fetchInventory, fetchUserStorageId]);
|
|
206
|
+
|
|
207
|
+
// ── Transaction helper ────────────────────────────────────────────────────
|
|
208
|
+
|
|
209
|
+
const exec = async (buildFn: (tx: Transaction) => void, successMsg: string) => {
|
|
210
|
+
if (!account) {
|
|
211
|
+
toast.error('Connect wallet first');
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
setIsLoading(true);
|
|
215
|
+
try {
|
|
216
|
+
const tx = new Transaction();
|
|
217
|
+
buildFn(tx);
|
|
218
|
+
await signAndExecuteTransaction(
|
|
219
|
+
{ transaction: tx.serialize() as any, chain: `sui:${network ?? 'localnet'}` },
|
|
220
|
+
{
|
|
221
|
+
onSuccess: () => {
|
|
222
|
+
toast.success(successMsg);
|
|
223
|
+
setTimeout(() => {
|
|
224
|
+
fetchAll();
|
|
225
|
+
fetchInventory();
|
|
226
|
+
}, 1500);
|
|
227
|
+
},
|
|
228
|
+
onError: (err) => toast.error(`Transaction failed: ${err.message}`)
|
|
229
|
+
}
|
|
230
|
+
);
|
|
231
|
+
} catch (err: any) {
|
|
232
|
+
toast.error(`Error: ${err?.message ?? err}`);
|
|
233
|
+
} finally {
|
|
234
|
+
setIsLoading(false);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// ── Crop actions ──────────────────────────────────────────────────────────
|
|
239
|
+
|
|
240
|
+
const handleListCrop = () => {
|
|
241
|
+
if (!userStorageId) {
|
|
242
|
+
toast.error('UserStorage not found');
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const name = CROP_NAMES[listForm.cropType];
|
|
246
|
+
const totalMist = BigInt(listForm.pricePerUnit) * BigInt(listForm.amount);
|
|
247
|
+
exec(
|
|
248
|
+
(tx) =>
|
|
249
|
+
tx.moveCall({
|
|
250
|
+
target: `${pkg}::market_system::list_${name}`,
|
|
251
|
+
arguments: [
|
|
252
|
+
tx.object(storageId),
|
|
253
|
+
tx.object(userStorageId!),
|
|
254
|
+
tx.pure.u64(listForm.amount),
|
|
255
|
+
tx.pure.u64(totalMist)
|
|
256
|
+
]
|
|
257
|
+
}),
|
|
258
|
+
`Listed ${listForm.amount} ${name}`
|
|
259
|
+
);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const handleBuyCrop = (l: CropListing) => {
|
|
263
|
+
if (!userStorageId) {
|
|
264
|
+
toast.error('UserStorage not found');
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
exec((tx) => {
|
|
268
|
+
const [payment] = tx.splitCoins(tx.gas, [tx.pure.u64(l.price)]);
|
|
269
|
+
tx.moveCall({
|
|
270
|
+
target: `${pkg}::market_system::buy_${l.cropName}`,
|
|
271
|
+
arguments: [
|
|
272
|
+
tx.object(hubId),
|
|
273
|
+
tx.object(storageId),
|
|
274
|
+
tx.object(l.id),
|
|
275
|
+
tx.object(userStorageId!),
|
|
276
|
+
payment
|
|
277
|
+
]
|
|
278
|
+
});
|
|
279
|
+
}, `Bought ${l.amount} ${l.cropName}!`);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const handleCancelCrop = (l: CropListing) => {
|
|
283
|
+
if (!userStorageId) return;
|
|
284
|
+
exec(
|
|
285
|
+
(tx) =>
|
|
286
|
+
tx.moveCall({
|
|
287
|
+
target: `${pkg}::market_system::cancel_${l.cropName}`,
|
|
288
|
+
arguments: [tx.object(l.id), tx.object(userStorageId!)]
|
|
289
|
+
}),
|
|
290
|
+
'Listing cancelled'
|
|
291
|
+
);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// ── Egg actions ───────────────────────────────────────────────────────────
|
|
295
|
+
|
|
296
|
+
const handleListEgg = () => {
|
|
297
|
+
if (!userStorageId) {
|
|
298
|
+
toast.error('UserStorage not found');
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const name = EGG_NAMES[eggListForm.eggType];
|
|
302
|
+
exec(
|
|
303
|
+
(tx) =>
|
|
304
|
+
tx.moveCall({
|
|
305
|
+
target: `${pkg}::market_system::list_${name}`,
|
|
306
|
+
arguments: [
|
|
307
|
+
tx.object(storageId),
|
|
308
|
+
tx.object(userStorageId!),
|
|
309
|
+
tx.pure.u64(eggListForm.amount),
|
|
310
|
+
tx.pure.u64(eggListForm.price)
|
|
311
|
+
]
|
|
312
|
+
}),
|
|
313
|
+
`Listed ${eggListForm.amount} ${EGG_LABEL[eggListForm.eggType]} eggs`
|
|
314
|
+
);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const handleBuyEgg = (l: EggListing) => {
|
|
318
|
+
if (!userStorageId) {
|
|
319
|
+
toast.error('UserStorage not found');
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const name = EGG_NAMES[l.eggType];
|
|
323
|
+
exec((tx) => {
|
|
324
|
+
const [payment] = tx.splitCoins(tx.gas, [tx.pure.u64(l.price)]);
|
|
325
|
+
tx.moveCall({
|
|
326
|
+
target: `${pkg}::market_system::buy_${name}`,
|
|
327
|
+
arguments: [
|
|
328
|
+
tx.object(hubId),
|
|
329
|
+
tx.object(storageId),
|
|
330
|
+
tx.object(l.id),
|
|
331
|
+
tx.object(userStorageId!),
|
|
332
|
+
payment
|
|
333
|
+
]
|
|
334
|
+
});
|
|
335
|
+
}, `Bought ${l.amount} ${EGG_LABEL[l.eggType]} egg(s)!`);
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
const handleCancelEgg = (l: EggListing) => {
|
|
339
|
+
if (!userStorageId) return;
|
|
340
|
+
const name = EGG_NAMES[l.eggType];
|
|
341
|
+
exec(
|
|
342
|
+
(tx) =>
|
|
343
|
+
tx.moveCall({
|
|
344
|
+
target: `${pkg}::market_system::cancel_${name}`,
|
|
345
|
+
arguments: [tx.object(l.id), tx.object(userStorageId!)]
|
|
346
|
+
}),
|
|
347
|
+
'Egg listing cancelled'
|
|
348
|
+
);
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
// ── Pet actions ───────────────────────────────────────────────────────────
|
|
352
|
+
|
|
353
|
+
const handleBuyPet = (l: PetListing) => {
|
|
354
|
+
if (!userStorageId) {
|
|
355
|
+
toast.error('UserStorage not found');
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
exec((tx) => {
|
|
359
|
+
const [payment] = tx.splitCoins(tx.gas, [tx.pure.u64(l.price)]);
|
|
360
|
+
tx.moveCall({
|
|
361
|
+
target: `${pkg}::pet_system::buy_pet`,
|
|
362
|
+
arguments: [
|
|
363
|
+
tx.object(hubId),
|
|
364
|
+
tx.object(storageId),
|
|
365
|
+
tx.object(userStorageId!),
|
|
366
|
+
tx.object(l.id),
|
|
367
|
+
payment
|
|
368
|
+
]
|
|
369
|
+
});
|
|
370
|
+
}, `${SPECIES_NAME[l.pet.species]} arrived in your ranch!`);
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
const handleCancelPetListing = (l: PetListing) => {
|
|
374
|
+
if (!userStorageId) return;
|
|
375
|
+
exec(
|
|
376
|
+
(tx) =>
|
|
377
|
+
tx.moveCall({
|
|
378
|
+
target: `${pkg}::pet_system::cancel_pet_listing`,
|
|
379
|
+
arguments: [tx.object(userStorageId!), tx.object(l.id)]
|
|
380
|
+
}),
|
|
381
|
+
'Pet listing cancelled'
|
|
382
|
+
);
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
if (!account) {
|
|
386
|
+
return (
|
|
387
|
+
<div className="min-h-screen flex items-center justify-center">
|
|
388
|
+
<ConnectButton />
|
|
389
|
+
</div>
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// ── Render ────────────────────────────────────────────────────────────────
|
|
394
|
+
|
|
395
|
+
const tabs = [
|
|
396
|
+
{ key: 'crops', label: 'Crops' },
|
|
397
|
+
{ key: 'eggs', label: 'Eggs' },
|
|
398
|
+
{ key: 'pets', label: 'Pets' }
|
|
399
|
+
] as const;
|
|
400
|
+
|
|
401
|
+
return (
|
|
402
|
+
<div
|
|
403
|
+
className="min-h-screen p-4 md:p-6"
|
|
404
|
+
style={{ background: 'radial-gradient(ellipse at top, #1a3a1a 0%, #0a1a0a 100%)' }}
|
|
405
|
+
>
|
|
406
|
+
{/* Header */}
|
|
407
|
+
<div className="flex items-center justify-between mb-6 flex-wrap gap-3">
|
|
408
|
+
<div className="flex items-center gap-2">
|
|
409
|
+
<IconShop size={24} />
|
|
410
|
+
<h1 className="font-pixel text-amber-300 text-sm">MARKET</h1>
|
|
411
|
+
</div>
|
|
412
|
+
<ConnectButton />
|
|
413
|
+
</div>
|
|
414
|
+
|
|
415
|
+
{/* Nav */}
|
|
416
|
+
<div className="flex gap-2 mb-6">
|
|
417
|
+
{['Farm', 'Market', 'Leaderboard'].map((t) => (
|
|
418
|
+
<a
|
|
419
|
+
key={t}
|
|
420
|
+
href={t === 'Farm' ? '/' : `/${t.toLowerCase()}`}
|
|
421
|
+
className={`px-4 py-2 text-xs font-pixel rounded-lg transition-colors border ${
|
|
422
|
+
t === 'Market'
|
|
423
|
+
? 'bg-amber-700 text-amber-100 border-amber-600'
|
|
424
|
+
: 'bg-amber-900/40 hover:bg-amber-800/40 text-amber-400 border-amber-700/30'
|
|
425
|
+
}`}
|
|
426
|
+
>
|
|
427
|
+
{t}
|
|
428
|
+
</a>
|
|
429
|
+
))}
|
|
430
|
+
</div>
|
|
431
|
+
|
|
432
|
+
<p className="mb-4 text-xs text-amber-700/60 font-pixel px-1">
|
|
433
|
+
Market requires main wallet signature (session key not permitted by the framework)
|
|
434
|
+
</p>
|
|
435
|
+
|
|
436
|
+
{/* Asset tabs */}
|
|
437
|
+
<div className="flex gap-1 mb-6">
|
|
438
|
+
{tabs.map(({ key, label }) => (
|
|
439
|
+
<button
|
|
440
|
+
key={key}
|
|
441
|
+
onClick={() => setActiveTab(key)}
|
|
442
|
+
className={`flex-1 py-2 text-xs font-pixel rounded-xl transition-colors border
|
|
443
|
+
${
|
|
444
|
+
activeTab === key
|
|
445
|
+
? 'bg-amber-700 text-amber-100 border-amber-600'
|
|
446
|
+
: 'bg-amber-900/40 text-amber-500 border-amber-800/40 hover:bg-amber-800/40'
|
|
447
|
+
}`}
|
|
448
|
+
>
|
|
449
|
+
{label}
|
|
450
|
+
</button>
|
|
451
|
+
))}
|
|
452
|
+
</div>
|
|
453
|
+
|
|
454
|
+
{/* ── Crops tab ── */}
|
|
455
|
+
{activeTab === 'crops' && (
|
|
456
|
+
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
|
457
|
+
<div className="lg:col-span-1">
|
|
458
|
+
<div className="bg-amber-950/80 border-2 border-amber-700 rounded-2xl p-4 space-y-3">
|
|
459
|
+
<h2 className="font-pixel text-amber-300 text-xs">List Crops</h2>
|
|
460
|
+
<select
|
|
461
|
+
value={listForm.cropType}
|
|
462
|
+
onChange={(e) => setListForm((f) => ({ ...f, cropType: Number(e.target.value) }))}
|
|
463
|
+
className="w-full bg-amber-900/40 border border-amber-700 text-amber-200 rounded-lg px-3 py-2 text-sm"
|
|
464
|
+
>
|
|
465
|
+
{CROP_LIST.map((c) => (
|
|
466
|
+
<option key={c.type} value={c.type}>
|
|
467
|
+
{c.name} (owned: {Number(cropInv[c.type] ?? 0n)})
|
|
468
|
+
</option>
|
|
469
|
+
))}
|
|
470
|
+
</select>
|
|
471
|
+
<input
|
|
472
|
+
type="number"
|
|
473
|
+
min={1}
|
|
474
|
+
value={listForm.amount}
|
|
475
|
+
onChange={(e) => setListForm((f) => ({ ...f, amount: Number(e.target.value) }))}
|
|
476
|
+
placeholder="Amount"
|
|
477
|
+
className="w-full bg-amber-900/40 border border-amber-700 text-amber-200 rounded-lg px-3 py-2 text-sm"
|
|
478
|
+
/>
|
|
479
|
+
<div>
|
|
480
|
+
<input
|
|
481
|
+
type="number"
|
|
482
|
+
min={0.001}
|
|
483
|
+
step={0.001}
|
|
484
|
+
value={listForm.pricePerUnit / 1e9}
|
|
485
|
+
onChange={(e) =>
|
|
486
|
+
setListForm((f) => ({
|
|
487
|
+
...f,
|
|
488
|
+
pricePerUnit: Math.round(Number(e.target.value) * 1e9)
|
|
489
|
+
}))
|
|
490
|
+
}
|
|
491
|
+
placeholder="Price per unit (SUI)"
|
|
492
|
+
className="w-full bg-amber-900/40 border border-amber-700 text-amber-200 rounded-lg px-3 py-2 text-sm"
|
|
493
|
+
/>
|
|
494
|
+
<p className="text-amber-700 text-xs mt-1">
|
|
495
|
+
Total: {((listForm.pricePerUnit * listForm.amount) / 1e9).toFixed(4)} SUI
|
|
496
|
+
</p>
|
|
497
|
+
</div>
|
|
498
|
+
<button
|
|
499
|
+
onClick={handleListCrop}
|
|
500
|
+
disabled={isLoading || (cropInv[listForm.cropType] ?? 0n) < BigInt(listForm.amount)}
|
|
501
|
+
className="w-full py-2 bg-green-700 hover:bg-green-600 text-white text-xs font-pixel rounded-lg disabled:opacity-40 transition-colors"
|
|
502
|
+
>
|
|
503
|
+
{isLoading ? 'Wait...' : 'List Crops'}
|
|
504
|
+
</button>
|
|
505
|
+
</div>
|
|
506
|
+
</div>
|
|
507
|
+
<div className="lg:col-span-2 space-y-2">
|
|
508
|
+
<h2 className="font-pixel text-amber-400 text-xs mb-2">Active Listings</h2>
|
|
509
|
+
{cropListings.length === 0 ? (
|
|
510
|
+
<EmptyState text="No crop listings yet." />
|
|
511
|
+
) : (
|
|
512
|
+
cropListings.map((l) => (
|
|
513
|
+
<ListingRow
|
|
514
|
+
key={l.id}
|
|
515
|
+
left={
|
|
516
|
+
<>
|
|
517
|
+
<span className="font-pixel text-amber-200 text-xs capitalize">
|
|
518
|
+
{l.cropName} ×{Number(l.amount)}
|
|
519
|
+
</span>
|
|
520
|
+
<span className="text-amber-700 text-xs block">
|
|
521
|
+
{shortAddr(l.seller)}
|
|
522
|
+
{l.seller === account.address && (
|
|
523
|
+
<span className="text-amber-500 ml-1">(you)</span>
|
|
524
|
+
)}
|
|
525
|
+
</span>
|
|
526
|
+
</>
|
|
527
|
+
}
|
|
528
|
+
right={
|
|
529
|
+
<span className="text-amber-400 text-xs">
|
|
530
|
+
{(Number(l.price) / 1e9).toFixed(4)} SUI
|
|
531
|
+
</span>
|
|
532
|
+
}
|
|
533
|
+
isMine={l.seller === account.address}
|
|
534
|
+
isLoading={isLoading}
|
|
535
|
+
onBuy={() => handleBuyCrop(l)}
|
|
536
|
+
onCancel={() => handleCancelCrop(l)}
|
|
537
|
+
/>
|
|
538
|
+
))
|
|
539
|
+
)}
|
|
540
|
+
</div>
|
|
541
|
+
</div>
|
|
542
|
+
)}
|
|
543
|
+
|
|
544
|
+
{/* ── Eggs tab ── */}
|
|
545
|
+
{activeTab === 'eggs' && (
|
|
546
|
+
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
|
547
|
+
<div className="lg:col-span-1">
|
|
548
|
+
<div className="bg-amber-950/80 border-2 border-amber-700 rounded-2xl p-4 space-y-3">
|
|
549
|
+
<h2 className="font-pixel text-amber-300 text-xs">List Eggs</h2>
|
|
550
|
+
<select
|
|
551
|
+
value={eggListForm.eggType}
|
|
552
|
+
onChange={(e) => setEggListForm((f) => ({ ...f, eggType: Number(e.target.value) }))}
|
|
553
|
+
className="w-full bg-amber-900/40 border border-amber-700 text-amber-200 rounded-lg px-3 py-2 text-sm"
|
|
554
|
+
>
|
|
555
|
+
{[1, 2, 3].map((t) => (
|
|
556
|
+
<option key={t} value={t}>
|
|
557
|
+
{EGG_LABEL[t]} (owned: {Number(eggInv[t] ?? 0n)})
|
|
558
|
+
</option>
|
|
559
|
+
))}
|
|
560
|
+
</select>
|
|
561
|
+
<input
|
|
562
|
+
type="number"
|
|
563
|
+
min={1}
|
|
564
|
+
value={eggListForm.amount}
|
|
565
|
+
onChange={(e) => setEggListForm((f) => ({ ...f, amount: Number(e.target.value) }))}
|
|
566
|
+
placeholder="Amount"
|
|
567
|
+
className="w-full bg-amber-900/40 border border-amber-700 text-amber-200 rounded-lg px-3 py-2 text-sm"
|
|
568
|
+
/>
|
|
569
|
+
<input
|
|
570
|
+
type="number"
|
|
571
|
+
min={0.001}
|
|
572
|
+
step={0.001}
|
|
573
|
+
value={eggListForm.price / 1e9}
|
|
574
|
+
onChange={(e) =>
|
|
575
|
+
setEggListForm((f) => ({ ...f, price: Math.round(Number(e.target.value) * 1e9) }))
|
|
576
|
+
}
|
|
577
|
+
placeholder="Total price (SUI)"
|
|
578
|
+
className="w-full bg-amber-900/40 border border-amber-700 text-amber-200 rounded-lg px-3 py-2 text-sm"
|
|
579
|
+
/>
|
|
580
|
+
<button
|
|
581
|
+
onClick={handleListEgg}
|
|
582
|
+
disabled={
|
|
583
|
+
isLoading || (eggInv[eggListForm.eggType] ?? 0n) < BigInt(eggListForm.amount)
|
|
584
|
+
}
|
|
585
|
+
className="w-full py-2 bg-green-700 hover:bg-green-600 text-white text-xs font-pixel rounded-lg disabled:opacity-40 transition-colors"
|
|
586
|
+
>
|
|
587
|
+
{isLoading ? 'Wait...' : 'List Eggs'}
|
|
588
|
+
</button>
|
|
589
|
+
</div>
|
|
590
|
+
</div>
|
|
591
|
+
<div className="lg:col-span-2 space-y-2">
|
|
592
|
+
<h2 className="font-pixel text-amber-400 text-xs mb-2">Egg Listings</h2>
|
|
593
|
+
{eggListings.length === 0 ? (
|
|
594
|
+
<EmptyState text="No egg listings." />
|
|
595
|
+
) : (
|
|
596
|
+
eggListings.map((l) => (
|
|
597
|
+
<ListingRow
|
|
598
|
+
key={l.id}
|
|
599
|
+
left={
|
|
600
|
+
<div className="flex items-center gap-2">
|
|
601
|
+
<EggIcon eggType={l.eggType} size={20} />
|
|
602
|
+
<div>
|
|
603
|
+
<span className="font-pixel text-amber-200 text-xs">
|
|
604
|
+
{EGG_LABEL[l.eggType]} Egg x{Number(l.amount)}
|
|
605
|
+
</span>
|
|
606
|
+
<span className="text-amber-700 text-xs block">
|
|
607
|
+
{shortAddr(l.seller)}
|
|
608
|
+
{l.seller === account.address && (
|
|
609
|
+
<span className="text-amber-500 ml-1">(you)</span>
|
|
610
|
+
)}
|
|
611
|
+
</span>
|
|
612
|
+
</div>
|
|
613
|
+
</div>
|
|
614
|
+
}
|
|
615
|
+
right={
|
|
616
|
+
<span className="text-amber-400 text-xs">
|
|
617
|
+
{(Number(l.price) / 1e9).toFixed(4)} SUI
|
|
618
|
+
</span>
|
|
619
|
+
}
|
|
620
|
+
isMine={l.seller === account.address}
|
|
621
|
+
isLoading={isLoading}
|
|
622
|
+
onBuy={() => handleBuyEgg(l)}
|
|
623
|
+
onCancel={() => handleCancelEgg(l)}
|
|
624
|
+
/>
|
|
625
|
+
))
|
|
626
|
+
)}
|
|
627
|
+
</div>
|
|
628
|
+
</div>
|
|
629
|
+
)}
|
|
630
|
+
|
|
631
|
+
{/* ── Pets tab ── */}
|
|
632
|
+
{activeTab === 'pets' && (
|
|
633
|
+
<div className="space-y-4">
|
|
634
|
+
<p className="text-xs text-amber-600 font-pixel px-1">
|
|
635
|
+
Purchased pets go directly to your ranch. Use Assign on the farm page to activate them.
|
|
636
|
+
</p>
|
|
637
|
+
|
|
638
|
+
{petListings.length === 0 ? (
|
|
639
|
+
<EmptyState text="No pet listings yet." />
|
|
640
|
+
) : (
|
|
641
|
+
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3">
|
|
642
|
+
{petListings.map((l) => {
|
|
643
|
+
const p = l.pet;
|
|
644
|
+
const isMine = l.seller === account.address;
|
|
645
|
+
return (
|
|
646
|
+
<motion.div
|
|
647
|
+
key={l.id}
|
|
648
|
+
initial={{ opacity: 0, scale: 0.97 }}
|
|
649
|
+
animate={{ opacity: 1, scale: 1 }}
|
|
650
|
+
className="bg-amber-950/60 border border-amber-700/40 rounded-xl p-3 space-y-2"
|
|
651
|
+
>
|
|
652
|
+
<div className="flex items-center gap-2">
|
|
653
|
+
<PetAvatar species={p.species} level={p.level} size={40} />
|
|
654
|
+
<div>
|
|
655
|
+
<p className="font-pixel text-amber-200 text-xs">
|
|
656
|
+
{SPECIES_NAME[p.species]}
|
|
657
|
+
</p>
|
|
658
|
+
<p className={`text-xs ${RARITY_COLOR[p.rarity]}`}>
|
|
659
|
+
{RARITY_LABEL[p.rarity]} · Lv.{p.level}
|
|
660
|
+
</p>
|
|
661
|
+
</div>
|
|
662
|
+
<div className="ml-auto text-right">
|
|
663
|
+
<p className="font-pixel text-amber-400 text-xs">
|
|
664
|
+
{(Number(l.price) / 1e9).toFixed(4)} SUI
|
|
665
|
+
</p>
|
|
666
|
+
<p className="text-amber-700 text-xs">
|
|
667
|
+
{shortAddr(l.seller)}
|
|
668
|
+
{isMine && <span className="text-amber-500"> (you)</span>}
|
|
669
|
+
</p>
|
|
670
|
+
</div>
|
|
671
|
+
</div>
|
|
672
|
+
<div className="grid grid-cols-2 gap-1 text-xs text-amber-500">
|
|
673
|
+
<span>Satiety: {p.satiety}%</span>
|
|
674
|
+
<span>Happy: {p.happiness}%</span>
|
|
675
|
+
<span>Fav: {FAVORITE_FOOD[p.species]}</span>
|
|
676
|
+
</div>
|
|
677
|
+
{isMine ? (
|
|
678
|
+
<button
|
|
679
|
+
onClick={() => handleCancelPetListing(l)}
|
|
680
|
+
disabled={isLoading}
|
|
681
|
+
className="w-full py-1.5 bg-red-900/60 hover:bg-red-800 text-red-300 text-xs font-pixel rounded-lg disabled:opacity-40 transition-colors"
|
|
682
|
+
>
|
|
683
|
+
Cancel
|
|
684
|
+
</button>
|
|
685
|
+
) : (
|
|
686
|
+
<button
|
|
687
|
+
onClick={() => handleBuyPet(l)}
|
|
688
|
+
disabled={isLoading}
|
|
689
|
+
className="w-full py-1.5 bg-amber-700 hover:bg-amber-600 text-white text-xs font-pixel rounded-lg disabled:opacity-40 transition-colors"
|
|
690
|
+
>
|
|
691
|
+
Buy → Ranch
|
|
692
|
+
</button>
|
|
693
|
+
)}
|
|
694
|
+
</motion.div>
|
|
695
|
+
);
|
|
696
|
+
})}
|
|
697
|
+
</div>
|
|
698
|
+
)}
|
|
699
|
+
</div>
|
|
700
|
+
)}
|
|
701
|
+
</div>
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// ── Shared mini-components ────────────────────────────────────────────────────
|
|
706
|
+
|
|
707
|
+
function EmptyState({ text }: { text: string }) {
|
|
708
|
+
return (
|
|
709
|
+
<div className="bg-amber-950/40 border border-amber-800/40 rounded-xl p-8 text-center">
|
|
710
|
+
<p className="text-amber-600 font-pixel text-xs">{text}</p>
|
|
711
|
+
</div>
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
function ListingRow({
|
|
716
|
+
left,
|
|
717
|
+
right,
|
|
718
|
+
isMine,
|
|
719
|
+
isLoading,
|
|
720
|
+
onBuy,
|
|
721
|
+
onCancel
|
|
722
|
+
}: {
|
|
723
|
+
left: React.ReactNode;
|
|
724
|
+
right: React.ReactNode;
|
|
725
|
+
isMine: boolean;
|
|
726
|
+
isLoading: boolean;
|
|
727
|
+
onBuy: () => void;
|
|
728
|
+
onCancel: () => void;
|
|
729
|
+
}) {
|
|
730
|
+
return (
|
|
731
|
+
<motion.div
|
|
732
|
+
initial={{ opacity: 0, y: 6 }}
|
|
733
|
+
animate={{ opacity: 1, y: 0 }}
|
|
734
|
+
className="flex items-center justify-between bg-amber-900/30 border border-amber-800/40 rounded-xl px-4 py-3"
|
|
735
|
+
>
|
|
736
|
+
<div>{left}</div>
|
|
737
|
+
<div className="flex items-center gap-3">
|
|
738
|
+
{right}
|
|
739
|
+
{isMine ? (
|
|
740
|
+
<button
|
|
741
|
+
disabled={isLoading}
|
|
742
|
+
onClick={onCancel}
|
|
743
|
+
className="px-3 py-1.5 bg-red-800 hover:bg-red-700 text-white text-xs font-pixel rounded-lg disabled:opacity-40 transition-colors"
|
|
744
|
+
>
|
|
745
|
+
Cancel
|
|
746
|
+
</button>
|
|
747
|
+
) : (
|
|
748
|
+
<button
|
|
749
|
+
disabled={isLoading}
|
|
750
|
+
onClick={onBuy}
|
|
751
|
+
className="px-4 py-1.5 bg-amber-700 hover:bg-amber-600 text-white text-xs font-pixel rounded-lg disabled:opacity-40 transition-colors"
|
|
752
|
+
>
|
|
753
|
+
Buy
|
|
754
|
+
</button>
|
|
755
|
+
)}
|
|
756
|
+
</div>
|
|
757
|
+
</motion.div>
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
function shortAddr(addr: string) {
|
|
762
|
+
return `${addr.slice(0, 6)}...${addr.slice(-4)}`;
|
|
763
|
+
}
|