Skip to content

Commit

Permalink
Merge pull request #168 from BibliothecaDAO/fix-bugs
Browse files Browse the repository at this point in the history
fix: use date.now in prod + upgrade to 0.2.3
  • Loading branch information
r0man1337 authored Oct 12, 2023
2 parents 491a948 + c49de6c commit c884d97
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Download Dojo release artifact
run: |
curl -L -o dojo-linux-x86_64.tar.gz https://github.com/dojoengine/dojo/releases/download/v0.2.2/dojo_v0.2.2_linux_amd64.tar.gz
curl -L -o dojo-linux-x86_64.tar.gz https://github.com/dojoengine/dojo/releases/download/v0.2.3/dojo_v0.2.3_linux_amd64.tar.gz
tar -xzf dojo-linux-x86_64.tar.gz
sudo mv sozo /usr/local/bin/
Expand Down
1 change: 1 addition & 0 deletions client/src/components/cityview/realm/labor/LaborBuild.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const LaborBuildPopup = ({ resourceId, setBuildLoadingStates, onClose }:
optimisticBuildLabor(
nextBlockTimestamp || 0,
costResources,
laborAuctionAverageCoefficient,
buildLabor,
)({
signer: account,
Expand Down
4 changes: 3 additions & 1 deletion client/src/dojo/createOptimisticSystemCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export function createOptimisticSystemCalls({
function optimisticBuildLabor(
ts: number,
costResources: LaborCostInterface[],
laborAuctionAverageCoefficient: number,
systemCall: (args: BuildLaborProps) => Promise<void>,
) {
return async function (this: any, args: BuildLaborProps) {
Expand All @@ -217,7 +218,8 @@ export function createOptimisticSystemCalls({
balance: 0,
};
let balance =
currentResource.balance - (laborUnits as number) * (multiplier as number) * costResources[i].amount;
currentResource.balance -
(laborUnits as number) * (multiplier as number) * costResources[i].amount * laborAuctionAverageCoefficient;
Resource.addOverride(overrideId, {
entity: costId,
value: {
Expand Down
21 changes: 6 additions & 15 deletions client/src/hooks/store/useBlockchainStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useFetchBlockchainData = () => {

fetchBlockchainTimestamp(); // Initial fetch

const intervalId = setInterval(fetchBlockchainTimestamp, 5000); // Fetch every 5 seconds
const intervalId = setInterval(fetchBlockchainTimestamp, 10000); // Fetch every 10 seconds

return () => {
clearInterval(intervalId); // Clear interval on component unmount
Expand Down Expand Up @@ -58,20 +58,11 @@ const fetchBlockTimestamp = async (): Promise<number | undefined> => {
const data = await response.json();
return data.result;
} else {
const reponse = await fetch(import.meta.env.VITE_KATANA_URL!, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
method: "starknet_getBlockWithTxs",
params: { blockId: "latest" },
id: 1,
}),
});
const data = await reponse.json();
return data.result.timestamp;
// NOTE: if we are using Katana in dev, we should use next block timestmamp because
// it allows us to advance time. But current issue with next_block_timestamp is that
// it does not get updated in katana until someone mints a new block. Since in prod we should
// not be able to use advance time, we should use current block timestamp
return Date.now() / 1000;
}
} catch (error) {
console.error("Error fetching block timestamp:", error);
Expand Down
2 changes: 1 addition & 1 deletion contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "0.1.0"
sierra-replace-ids = true

[dependencies]
dojo = { git = "https://github.com/dojoengine/dojo", rev = "47c0cbcfa4ebd4d4b504ec959fdbcfd3e4271e8a" }
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v0.2.3" }
alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "e1aa42853815f04ff00e4ed3507cfd74d7b0c644" }
cubit = { git = "https://github.com/influenceth/cubit" }
# TODO: use dojo_defi when works with latest nightly
Expand Down

0 comments on commit c884d97

Please sign in to comment.