feat(scripting): connect give_item to wallet rewards, add [E] Interact prompt and toast feedback
checkpoint / checkpoint (push) Failing after 6m2s

This commit is contained in:
2026-09-18 01:04:36 +00:00
parent 370395f1b6
commit f93e99f042
3 changed files with 144 additions and 1 deletions
+35
View File
@@ -76,3 +76,38 @@ async def get_wallet_transactions(
limit=limit,
offset=offset,
)
class RewardRequest(BaseModel):
amount: int = Field(..., gt=0, le=10000, description="Amount of Buffalo Chips to reward")
reason: str | None = Field(default="in_game_reward", description="Reward source or reason")
class RewardResponse(BaseModel):
success: bool
amount: int
new_balance: int
@router.post("/reward", response_model=RewardResponse)
async def reward_chips(
payload: RewardRequest,
current_user: CurrentUser,
db: DbDep,
):
"""Credit in-game Buffalo Chips reward directly to the player's wallet."""
wallet, tx = await wallet_service.credit(
db,
user_id=current_user.id,
amount=payload.amount,
tx_type=TransactionType.admin_adjustment,
reference_type="gameplay_reward",
reference_id=payload.reason or "in_game_reward",
metadata={"reason": payload.reason or "in_game_reward"},
)
return RewardResponse(
success=True,
amount=payload.amount,
new_balance=wallet.balance,
)
+27
View File
@@ -133,3 +133,30 @@ async def test_wallet_service_credit_and_debit_flow():
# Newest first: debit (-400) first, then credit (+1000)
assert tx_data["transactions"][0]["amount"] == -400
assert tx_data["transactions"][1]["amount"] == 1000
def test_wallet_reward_endpoint():
client = TestClient(app)
uid, headers = _register(client, "wallet_reward_user")
# Initial balance is 0
resp = client.get("/api/wallet", headers=headers)
assert resp.status_code == 200
assert resp.json()["balance"] == 0
# Reward 25 Buffalo Chips
reward_resp = client.post(
"/api/wallet/reward",
json={"amount": 25, "reason": "found_chest"},
headers=headers,
)
assert reward_resp.status_code == 200
data = reward_resp.json()
assert data["success"] is True
assert data["amount"] == 25
assert data["new_balance"] == 25
# Check updated wallet
resp = client.get("/api/wallet", headers=headers)
assert resp.json()["balance"] == 25