Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/wonders lords cost #2384

Merged
merged 25 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c2f937e
Merge pull request #2229 from BibliothecaDAO/next
ponderingdemocritus Dec 5, 2024
b644547
Merge pull request #2231 from BibliothecaDAO/next
ponderingdemocritus Dec 5, 2024
39ddfc0
Merge pull request #2232 from BibliothecaDAO/next
ponderingdemocritus Dec 5, 2024
54f5668
Merge pull request #2235 from BibliothecaDAO/next
ponderingdemocritus Dec 5, 2024
b2900ad
Merge pull request #2237 from BibliothecaDAO/next
RedBeardEth Dec 5, 2024
f6ffa82
Merge pull request #2239 from BibliothecaDAO/next
ponderingdemocritus Dec 5, 2024
8449a59
Merge pull request #2245 from BibliothecaDAO/next
ponderingdemocritus Dec 6, 2024
fca4da9
Merge pull request #2307 from BibliothecaDAO/next
ponderingdemocritus Dec 10, 2024
15dda9a
Merge pull request #2372 from BibliothecaDAO/next
ponderingdemocritus Dec 10, 2024
042d1fd
Merge pull request #2374 from BibliothecaDAO/next
ponderingdemocritus Dec 10, 2024
735600a
Merge pull request #2376 from BibliothecaDAO/next
ponderingdemocritus Dec 10, 2024
3de49bd
Merge pull request #2377 from BibliothecaDAO/next
RedBeardEth Dec 10, 2024
2839eda
Merge pull request #2378 from BibliothecaDAO/next
RedBeardEth Dec 10, 2024
b64cc4c
Merge pull request #2380 from BibliothecaDAO/next
RedBeardEth Dec 10, 2024
800d2fc
Merge pull request #2382 from BibliothecaDAO/next
RedBeardEth Dec 10, 2024
7024782
Fix market lords input cost for wonders
bob0005 Dec 10, 2024
f681052
add countdown backdrop (#2383) (#2385)
edisontim Dec 10, 2024
50196a3
lint
bob0005 Dec 10, 2024
1ee218d
knip
bob0005 Dec 10, 2024
43654f7
dry
bob0005 Dec 10, 2024
c5f86fd
Merge branch 'next' into fix/wonders-lords-cost
bob0005 Dec 10, 2024
662d5b3
Merge branch 'main' into next
bob0005 Dec 10, 2024
3f6171c
Merge branch 'next' into fix/wonders-lords-cost
bob0005 Dec 10, 2024
e1092f3
Fix tool version
bob0005 Dec 10, 2024
e912561
update dojo version in ci
bob0005 Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
steps:
- name: Download Dojo release artifact
run: |
curl -L -o dojo-linux-x86_64.tar.gz https://github.com/dojoengine/dojo/releases/download/v1.0.3/dojo_v1.0.3_linux_amd64.tar.gz
curl -L -o dojo-linux-x86_64.tar.gz https://github.com/dojoengine/dojo/releases/download/v1.0.5/dojo_v1.0.5_linux_amd64.tar.gz
tar -xzf dojo-linux-x86_64.tar.gz
sudo mv sozo /usr/local/bin/
- name: Checkout repository
Expand Down
6 changes: 6 additions & 0 deletions .knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

"sdk/packages/eternum/global.d.ts",
"config/bank/index.ts",
"config/speed.ts",

"**/**__test__**/**",
"**/**__tests__**/**",

Expand All @@ -24,6 +26,10 @@
"landing/**",
"client/pwa-assets.config.ts",

"docs/components/**",
"docs/utils/**",
"vocs.config.ts",

"client/src/ui/modules/chat/types.tsx",
"client/src/ui/modules/chat/constants.tsx",
"client/src/ui/modules/chat/ChatTab.tsx",
Expand Down
1 change: 0 additions & 1 deletion client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@

<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image" content="https://eternum.realms.world/images/og-image.png" />

</head>
<body>
<div id="root"></div>
Expand Down
10 changes: 4 additions & 6 deletions client/src/dojo/modelManager/ResourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,11 @@ export class ResourceManager {
if (!production) return [false, 0];

let consumptionRate = Number(production.consumption_rate);

// Check if this is a Wonder producing Lords
const isWonder = getComponentValue(
this.setup.components.Realm,
getEntityIdFromKeys([BigInt(this.entityId)])
)?.has_wonder || false;

const isWonder =
getComponentValue(this.setup.components.Realm, getEntityIdFromKeys([BigInt(this.entityId)]))?.has_wonder || false;

if (isWonder && resourceId === ResourcesIds.Lords) {
consumptionRate = consumptionRate * 0.1; // 10% of normal production rate for Wonders
}
Expand Down
19 changes: 15 additions & 4 deletions client/src/ui/components/construction/SelectPreviewBuilding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Tabs } from "@/ui/elements/tab";
import { unpackResources } from "@/ui/utils/packedData";
import { hasEnoughPopulationForBuilding } from "@/ui/utils/realms";
import {
adjustWonderLordsCost,
divideByPrecision,
getEntityIdFromKeys,
gramToKg,
Expand Down Expand Up @@ -396,7 +397,12 @@ export const ResourceInfo = ({
hintModal?: boolean;
}) => {
const dojo = useDojo();
const cost = configManager.resourceInputs[resourceId];
let cost = configManager.resourceInputs[resourceId];

const realm = getComponentValue(dojo.setup.components.Realm, getEntityIdFromKeys([BigInt(entityId || 0)]));
if (resourceId == ResourcesIds.Donkey && realm?.has_wonder) {
cost = adjustWonderLordsCost(cost);
}

const buildingCost = getResourceBuildingCosts(entityId ?? 0, dojo, resourceId) ?? [];

Expand Down Expand Up @@ -528,7 +534,13 @@ export const BuildingInfo = ({
buildingId === BuildingType.Storehouse ? configManager.getCapacityConfig(CapacityConfigCategory.Storehouse) : 0;

const resourceProduced = configManager.getResourceBuildingProduced(buildingId);
const ongoingCost = resourceProduced !== undefined ? configManager.resourceInputs[resourceProduced] || 0 : 0;
let ongoingCost = resourceProduced !== undefined ? configManager.resourceInputs[resourceProduced] || [] : [];

const realm = getComponentValue(dojo.setup.components.Realm, getEntityIdFromKeys([BigInt(entityId || 0)]));

if (buildingId == BuildingType.Market && realm?.has_wonder && ongoingCost.length > 0) {
ongoingCost = adjustWonderLordsCost(ongoingCost);
}

const perTick =
resourceProduced !== undefined ? divideByPrecision(configManager.getResourceOutputs(resourceProduced)) || 0 : 0;
Expand Down Expand Up @@ -587,12 +599,11 @@ export const BuildingInfo = ({
)}
</div>

{ongoingCost && ongoingCost.length ? (
{ongoingCost.length > 0 ? (
<>
<div className="font-bold uppercase">consumed per/s</div>
<div className="grid grid-cols-2 gap-2">
{resourceProduced !== 0 &&
ongoingCost &&
Object.keys(ongoingCost).map((resourceId, index) => {
const balance = getBalance(entityId || 0, ongoingCost[Number(resourceId)].resource);
return (
Expand Down
5 changes: 5 additions & 0 deletions client/src/ui/utils/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type ID,
type Position,
type Resource,
ResourceCost,
ResourcesIds,
TickIds,
} from "@bibliothecadao/eternum";
Expand Down Expand Up @@ -494,3 +495,7 @@ export const getRandomBackgroundImage = () => {
const paddedNumber = imageNumber.toString().padStart(2, "0");
return paddedNumber;
};

export const adjustWonderLordsCost = (cost: ResourceCost[]): ResourceCost[] => {
return cost.map((item) => (item.resource === ResourcesIds.Lords ? { ...item, amount: item.amount * 0.1 } : item));
};
8 changes: 4 additions & 4 deletions common/addresses/addresses.MAINNET.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"seasonPass": "0x057675b9c0bd62b096a2e15502a37b290fa766ead21c33eda42993e48a714b80",
"realms": "0x07ae27a31bb6526e3de9cf02f081f6ce0615ac12a6d7b85ee58b8ad7947a2809",
"lords": "0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49"
}
"seasonPass": "0x057675b9c0bd62b096a2e15502a37b290fa766ead21c33eda42993e48a714b80",
"realms": "0x07ae27a31bb6526e3de9cf02f081f6ce0615ac12a6d7b85ee58b8ad7947a2809",
"lords": "0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49"
}
21 changes: 10 additions & 11 deletions config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,18 @@ const setupConfig: Config = EternumGlobalConfig;
setupConfig.vrf.vrfProviderAddress = VITE_VRF_PROVIDER_ADDRESS!;

// Bridge
setupConfig.bridge = {
(setupConfig.bridge = {
...EternumGlobalConfig.bridge,
velords_fee_recipient: BigInt('0x045c587318c9ebcf2fbe21febf288ee2e3597a21cd48676005a5770a50d433c5'), // burner
velords_fee_recipient: BigInt("0x045c587318c9ebcf2fbe21febf288ee2e3597a21cd48676005a5770a50d433c5"), // burner
season_pool_fee_recipient: BigInt(getContractByName(manifest, `${NAMESPACE}-season_systems`)),
},

// Season Pass
setupConfig.season = {
...EternumGlobalConfig.season,
seasonPassAddress: process.env.VITE_SEASON_PASS_ADDRESS!,
realmsAddress: process.env.VITE_REALMS_ADDRESS!,
lordsAddress: process.env.VITE_LORDS_ADDRESS!,
};
}),
Comment on lines +127 to +131
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid hardcoding wallet addresses in production code.

The bridge configuration uses a hardcoded burner address for velords_fee_recipient. This could be risky in production and makes the code less maintainable.

Consider using an environment variable instead:

- velords_fee_recipient: BigInt("0x045c587318c9ebcf2fbe21febf288ee2e3597a21cd48676005a5770a50d433c5"), // burner
+ velords_fee_recipient: BigInt(process.env.VITE_VELORDS_FEE_RECIPIENT!),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(setupConfig.bridge = {
...EternumGlobalConfig.bridge,
velords_fee_recipient: BigInt('0x045c587318c9ebcf2fbe21febf288ee2e3597a21cd48676005a5770a50d433c5'), // burner
velords_fee_recipient: BigInt("0x045c587318c9ebcf2fbe21febf288ee2e3597a21cd48676005a5770a50d433c5"), // burner
season_pool_fee_recipient: BigInt(getContractByName(manifest, `${NAMESPACE}-season_systems`)),
},
// Season Pass
setupConfig.season = {
...EternumGlobalConfig.season,
seasonPassAddress: process.env.VITE_SEASON_PASS_ADDRESS!,
realmsAddress: process.env.VITE_REALMS_ADDRESS!,
lordsAddress: process.env.VITE_LORDS_ADDRESS!,
};
}),
(setupConfig.bridge = {
...EternumGlobalConfig.bridge,
velords_fee_recipient: BigInt(process.env.VITE_VELORDS_FEE_RECIPIENT!),
season_pool_fee_recipient: BigInt(getContractByName(manifest, `${NAMESPACE}-season_systems`)),
}),

// Season Pass
(setupConfig.season = {
...EternumGlobalConfig.season,
seasonPassAddress: process.env.VITE_SEASON_PASS_ADDRESS!,
realmsAddress: process.env.VITE_REALMS_ADDRESS!,
lordsAddress: process.env.VITE_LORDS_ADDRESS!,
});
Comment on lines +133 to +138
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Environment variables are validated but documentation needs improvement

The environment variables are properly validated using Zod schema in both client/env.ts and landing/env.ts:

VITE_SEASON_PASS_ADDRESS: z.string().startsWith("0x"),
VITE_REALMS_ADDRESS: z.string().startsWith("0x"),
VITE_LORDS_ADDRESS: z.string().startsWith("0x"),

However, there are a few concerns:

  • The variables are populated through deployment scripts (scripts/deploy.sh and scripts/indexer.sh)
  • No sample .env file or documentation found to guide developers on setting up these required variables
  • The use of non-null assertion (!) in the config suggests these variables are required but this isn't documented
🔗 Analysis chain

Verify environment variables for season configuration.

The season configuration relies on multiple environment variables without validation.

Let's verify these environment variables are properly documented:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if these environment variables are documented
echo "Checking for environment variables documentation..."
rg -l "VITE_SEASON_PASS_ADDRESS|VITE_REALMS_ADDRESS|VITE_LORDS_ADDRESS" .env* README.md docs/

Length of output: 306


Script:

#!/bin/bash
# Let's first find any .env files and documentation files in the repository
echo "Finding environment and documentation files..."
fd -t f "^\.env" -t f "^README" -t f "\.md$"

# Let's also check for environment variable usage in the codebase
echo -e "\nChecking environment variable usage..."
rg "VITE_(SEASON_PASS|REALMS|LORDS)_ADDRESS"

# Let's check if there's any validation logic for these variables
echo -e "\nChecking for validation logic..."
rg "process\.env\.VITE_(SEASON_PASS|REALMS|LORDS)_ADDRESS" -A 2 -B 2

Length of output: 5352


export const config = new EternumConfig(setupConfig);

Expand Down
2 changes: 1 addition & 1 deletion contracts/.tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb 2.8.4
dojo 1.0.3
dojo 1.0.5
64 changes: 32 additions & 32 deletions landing/public/resource_addresses/mainnet/resource_addresses.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
{
"STONE": [1, "0x439a1c010e3e1bb2d43d43411000893c0042bd88f6c701611a0ea914d426da4"],
"COAL": [2, "0xce635e3f241b0ae78c46a929d84a9101910188f9c4024eaa7559556503c31a"],
"WOOD": [3, "0x40d8907cec0f7ae9c364dfb12485a1314d84c129bf1898d2f3d4b7fcc7d44f4"],
"COPPER": [4, "0x66ed5c928ee027a9419ace1cbea8389885161db5572a7c5c4fef2310e9bf494"],
"IRONWOOD": [5, "0x1720cf6318bff45e62acc588680ae3cd4d5f8465b1d52cb710533c9299b031a"],
"OBSIDIAN": [6, "0x3b6448d09dcd023507376402686261f5d6739455fa02f804907b066e488da66"],
"GOLD": [7, "0xdff9dca192609c4e86ab3be22c7ec1e968876c992d21986f3c542be97fa2f"],
"SILVER": [8, "0x6fe21d2d4a8a05bdb70f09c9250af9870020d5dcc35f410b4a39d6605c3e353"],
"MITHRAL": [9, "0x67ba235c569c23877064b2ac6ebd4d79f32d3c00f5fab8e28a3b5700b957f6"],
"ALCHEMICALSILVER": [10, "0x3956a5301e99522038a2e7dcb9c2a89bf087ffa79310ee0a508b5538efd8ddd"],
"COLDIRON": [11, "0x555d713e59d4ff96b7960447e9bc9e79bfdeab5b0eea74e3df81bce61cfbc77"],
"DEEPCRYSTAL": [12, "0x1d655ac834d38df7921074fc1588411e202b1af83307cbd996983aff52db3a8"],
"RUBY": [13, "0x3d9b66720959d0e7687b898292c10e62e78626f2dba5e1909961a2ce3f86612"],
"DIAMONDS": [14, "0xe03ea8ae385f64754820af5c01c36abf1b8130dd6797d3fd9d430e4114e876"],
"HARTWOOD": [15, "0x5620aa7170cd66dbcbc37d03087bfe4633ffef91d3e4d97b501de906004f79b"],
"IGNIUM": [16, "0x625c1f789b03ebebc7a9322366f38ebad1f693b84b2abd8cb8f5b2748b0cdd5"],
"TWILIGHTQUARTZ": [17, "0x35e24c02409c3cfe8d5646399a62c4d102bb782938d5f5180e92c9c62d3faf7"],
"TRUEICE": [18, "0x4485f5a6e16562e1c761cd348e63256d00389e3ddf4f5d98afe7ab44c57c481"],
"ADAMANTINE": [19, "0x367f838f85a2f5e1580d6f011e4476f581083314cff8721ba3dda9706076eed"],
"SAPPHIRE": [20, "0x2f8dd022568af8f9f718aa37707a9b858529db56910633a160456838b6cbcbc"],
"ETHEREALSILICA": [21, "0x68b6e23cbbd58a644700f55e96c83580921e9f521b6e5175396b53ba7910e7d"],
"DRAGONHIDE": [22, "0x3bf856515bece3c93f5061b7941b8645f817a0acab93c758b8c7b4bc0afa3c6"],
"DEMONHIDE": [28, "0x3b847fbef9d344ba968edc945100e6ab0258a4b1b91f8665f85a3d814c3e4d4"],
"EARTHENSHARD": [29, "0x1cd5b8dd341dc43a97b821bc3cdc524f941142397b787a977fbd14078cf12a4"],
"DONKEY": [249, "0x264be95a4a2ace20add68cb321acdccd2f9f8440ee1c7abd85da44ddab01085"],
"KNIGHT": [250, "0xac965f9e67164723c16735a9da8dbc9eb8e43b1bd0323591e87c056badf606"],
"CROSSBOWMAN": [251, "0x67e4ac00a241be06ba6afc11fa2715ec7da0c42c05a67ef6ecfcfeda725aaa8"],
"PALADIN": [252, "0x3bc86299bee061c7c8d7546ccb62b9daf9bffc653b1508facb722c6593874bc"],
"WHEAT": [254, "0x57a3f1ee475e072ce3be41785c0e889b7295d7a0dcc22b992c5b9408dbeb280"],
"FISH": [255, "0x27719173cfe10f1aa38d2aaed0a075b6077290f1e817aa3485d2b828394f4d9"],
"LORDS": [253, "0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49"]
}
"STONE": [1, "0x439a1c010e3e1bb2d43d43411000893c0042bd88f6c701611a0ea914d426da4"],
"COAL": [2, "0xce635e3f241b0ae78c46a929d84a9101910188f9c4024eaa7559556503c31a"],
"WOOD": [3, "0x40d8907cec0f7ae9c364dfb12485a1314d84c129bf1898d2f3d4b7fcc7d44f4"],
"COPPER": [4, "0x66ed5c928ee027a9419ace1cbea8389885161db5572a7c5c4fef2310e9bf494"],
"IRONWOOD": [5, "0x1720cf6318bff45e62acc588680ae3cd4d5f8465b1d52cb710533c9299b031a"],
"OBSIDIAN": [6, "0x3b6448d09dcd023507376402686261f5d6739455fa02f804907b066e488da66"],
"GOLD": [7, "0xdff9dca192609c4e86ab3be22c7ec1e968876c992d21986f3c542be97fa2f"],
"SILVER": [8, "0x6fe21d2d4a8a05bdb70f09c9250af9870020d5dcc35f410b4a39d6605c3e353"],
"MITHRAL": [9, "0x67ba235c569c23877064b2ac6ebd4d79f32d3c00f5fab8e28a3b5700b957f6"],
"ALCHEMICALSILVER": [10, "0x3956a5301e99522038a2e7dcb9c2a89bf087ffa79310ee0a508b5538efd8ddd"],
"COLDIRON": [11, "0x555d713e59d4ff96b7960447e9bc9e79bfdeab5b0eea74e3df81bce61cfbc77"],
"DEEPCRYSTAL": [12, "0x1d655ac834d38df7921074fc1588411e202b1af83307cbd996983aff52db3a8"],
"RUBY": [13, "0x3d9b66720959d0e7687b898292c10e62e78626f2dba5e1909961a2ce3f86612"],
"DIAMONDS": [14, "0xe03ea8ae385f64754820af5c01c36abf1b8130dd6797d3fd9d430e4114e876"],
"HARTWOOD": [15, "0x5620aa7170cd66dbcbc37d03087bfe4633ffef91d3e4d97b501de906004f79b"],
"IGNIUM": [16, "0x625c1f789b03ebebc7a9322366f38ebad1f693b84b2abd8cb8f5b2748b0cdd5"],
"TWILIGHTQUARTZ": [17, "0x35e24c02409c3cfe8d5646399a62c4d102bb782938d5f5180e92c9c62d3faf7"],
"TRUEICE": [18, "0x4485f5a6e16562e1c761cd348e63256d00389e3ddf4f5d98afe7ab44c57c481"],
"ADAMANTINE": [19, "0x367f838f85a2f5e1580d6f011e4476f581083314cff8721ba3dda9706076eed"],
"SAPPHIRE": [20, "0x2f8dd022568af8f9f718aa37707a9b858529db56910633a160456838b6cbcbc"],
"ETHEREALSILICA": [21, "0x68b6e23cbbd58a644700f55e96c83580921e9f521b6e5175396b53ba7910e7d"],
"DRAGONHIDE": [22, "0x3bf856515bece3c93f5061b7941b8645f817a0acab93c758b8c7b4bc0afa3c6"],
"DEMONHIDE": [28, "0x3b847fbef9d344ba968edc945100e6ab0258a4b1b91f8665f85a3d814c3e4d4"],
"EARTHENSHARD": [29, "0x1cd5b8dd341dc43a97b821bc3cdc524f941142397b787a977fbd14078cf12a4"],
"DONKEY": [249, "0x264be95a4a2ace20add68cb321acdccd2f9f8440ee1c7abd85da44ddab01085"],
"KNIGHT": [250, "0xac965f9e67164723c16735a9da8dbc9eb8e43b1bd0323591e87c056badf606"],
"CROSSBOWMAN": [251, "0x67e4ac00a241be06ba6afc11fa2715ec7da0c42c05a67ef6ecfcfeda725aaa8"],
"PALADIN": [252, "0x3bc86299bee061c7c8d7546ccb62b9daf9bffc653b1508facb722c6593874bc"],
"WHEAT": [254, "0x57a3f1ee475e072ce3be41785c0e889b7295d7a0dcc22b992c5b9408dbeb280"],
"FISH": [255, "0x27719173cfe10f1aa38d2aaed0a075b6077290f1e817aa3485d2b828394f4d9"],
"LORDS": [253, "0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49"]
}
8 changes: 2 additions & 6 deletions landing/src/components/modules/bridge-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/
import { calculateDonkeysNeeded, getSeasonAddresses, getTotalResourceWeight } from "../ui/utils/utils";
import { BridgeFees } from "./bridge-fees";


export const BridgeIn = () => {
const { address } = useAccount();
const [realmEntityId, setRealmEntityId] = useState<number>();
Expand Down Expand Up @@ -248,9 +247,7 @@ export const BridgeIn = () => {
</div>
</div>
<Button
disabled={
isLoading || !realmEntityId || donkeyBalance.balance <= donkeysNeeded
}
disabled={isLoading || !realmEntityId || donkeyBalance.balance <= donkeysNeeded}
onClick={() => onBridgeIntoRealm()}
>
{isLoading && <Loader className="animate-spin pr-2" />}
Expand All @@ -266,7 +263,7 @@ export const SelectResourceToBridge = ({
selectedResourceIds,
setSelectedResourceIds,
unselectedResources,
addResourceGive
addResourceGive,
}: {
selectedResourceAmounts: { [key: string]: number };
setSelectedResourceAmounts: (value: { [key: string]: number }) => void;
Expand All @@ -275,7 +272,6 @@ export const SelectResourceToBridge = ({
unselectedResources: Resources[];
addResourceGive: () => void;
}) => {

useEffect(() => {
if (selectedResourceIds.length === 0) {
addResourceGive();
Expand Down
6 changes: 1 addition & 5 deletions landing/src/components/modules/bridge-out-step-1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,7 @@ export const BridgeOutStep1 = () => {
}),
);
console.log(validResources);
await bridgeStartWithdrawFromRealm(
validResources,
ADMIN_BANK_ENTITY_ID,
BigInt(realmEntityId!),
);
await bridgeStartWithdrawFromRealm(validResources, ADMIN_BANK_ENTITY_ID, BigInt(realmEntityId!));

setSelectedResourceIds([]);
setSelectedResourceAmounts({});
Expand Down
30 changes: 14 additions & 16 deletions landing/src/components/modules/bridge-out-step-2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { useEntities } from "@/hooks/helpers/useEntities";
import { donkeyArrivals } from "@/hooks/helpers/useResources";
import { useBridgeAsset } from "@/hooks/useBridge";
import { displayAddress } from "@/lib/utils";
import {
ADMIN_BANK_ENTITY_ID,
RESOURCE_PRECISION,
ResourcesIds
} from "@bibliothecadao/eternum";
import { ADMIN_BANK_ENTITY_ID, RESOURCE_PRECISION, ResourcesIds } from "@bibliothecadao/eternum";
import { useAccount } from "@starknet-react/core";
import { Loader } from "lucide-react";
import { useMemo, useState } from "react";
Expand Down Expand Up @@ -38,15 +34,15 @@ export const BridgeOutStep2 = () => {
);

const [resourceFees, setResourceFees] = useState<
{
id: string;
velordsFee: string;
seasonPoolFee: string;
clientFee: string;
bankFee: string;
totalFee?: string;
}[]
>([]);
{
id: string;
velordsFee: string;
seasonPoolFee: string;
clientFee: string;
bankFee: string;
totalFee?: string;
}[]
>([]);

const { playerRealms } = useEntities();
const realmEntityIds = useMemo(() => {
Expand Down Expand Up @@ -98,7 +94,9 @@ export const BridgeOutStep2 = () => {
}
const currentDonkeyInfo = donkeyInfos?.find((donkey) => donkey.donkeyEntityId?.toString() === value);
setDonkeyEntityId(BigInt(value));
setSelectedResourceIds((currentDonkeyInfo!.donkeyResources.map((resource) => resource.resourceId as never)) ?? 0);
setSelectedResourceIds(
currentDonkeyInfo!.donkeyResources.map((resource) => resource.resourceId as never) ?? 0,
);
Comment on lines +97 to +99
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve type safety and error handling in resource selection.

The current implementation has several issues:

  1. Unsafe null assertion with currentDonkeyInfo!
  2. Type casting with as never is a code smell
  3. Missing error handling for edge cases

Consider this safer implementation:

- setSelectedResourceIds(
-   currentDonkeyInfo!.donkeyResources.map((resource) => resource.resourceId as never) ?? 0,
- );
+ if (currentDonkeyInfo?.donkeyResources) {
+   setSelectedResourceIds(
+     currentDonkeyInfo.donkeyResources.map((resource) => resource.resourceId)
+   );
+ } else {
+   setSelectedResourceIds([]);
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
setSelectedResourceIds(
currentDonkeyInfo!.donkeyResources.map((resource) => resource.resourceId as never) ?? 0,
);
if (currentDonkeyInfo?.donkeyResources) {
setSelectedResourceIds(
currentDonkeyInfo.donkeyResources.map((resource) => resource.resourceId)
);
} else {
setSelectedResourceIds([]);
}

setSelectedResourceAmounts({
[currentDonkeyInfo!.donkeyResources[0].resourceId ?? 0]:
currentDonkeyInfo!.donkeyResources[0].amount / RESOURCE_PRECISION,
Expand Down Expand Up @@ -147,7 +145,7 @@ export const BridgeOutStep2 = () => {
setResourceFees={setResourceFees}
type="withdrawal"
/>
<div className="flex justify-between font-bold mt-3">
<div className="flex justify-between font-bold mt-3">
<div>Total Amount Received</div>
</div>
{Object.entries(selectedResourceAmounts).map(([id, amount]) => {
Expand Down
2 changes: 1 addition & 1 deletion landing/src/components/modules/season-start-timer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useSeasonStart } from "@/hooks/use-season-start";

export const SeasonStartTimer = () => {
const {seasonStart, countdown, nextBlockTimestamp} = useSeasonStart();
const { seasonStart, countdown, nextBlockTimestamp } = useSeasonStart();
if (countdown < 0 || nextBlockTimestamp === 0n || seasonStart === 0n) return null;

const hours = Math.floor(Number(countdown) / 3600);
Expand Down
4 changes: 2 additions & 2 deletions landing/src/components/ui/elements/CountdownTimer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { TypeH1 } from "@/components/typography/type-h1";
import { useSeasonStart } from "@/hooks/use-season-start";

export function CountdownTimer() {
const {seasonStart, countdown,nextBlockTimestamp} = useSeasonStart();
const { seasonStart, countdown, nextBlockTimestamp } = useSeasonStart();

const days = Math.floor(Number(countdown) / (3600 * 24))
const days = Math.floor(Number(countdown) / (3600 * 24));
const hours = Math.floor((Number(countdown) % (3600 * 24)) / 3600);
const minutes = Math.floor((Number(countdown) % 3600) / 60);
const seconds = Number(countdown) % 60;
Expand Down
2 changes: 1 addition & 1 deletion landing/src/hooks/useBridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useBridgeAsset = () => {
recipientRealmEntityId: bigint,
) => {
if (account) {
return await bridge_resources_into_realm({
return await bridge_resources_into_realm({
signer: account,
resources: resources,
through_bank_id: throughBankId,
Expand Down
Loading
Loading