Skip to content

Commit

Permalink
feat: chat msgs fix (#1583)
Browse files Browse the repository at this point in the history
* First attempt at fixing chat msgs

* Working chat message on slot from local client

* switch dojojs to alpha13

* change from local torii-client to alpha.13

* fix knip

* Fix build
  • Loading branch information
edisontim authored Sep 14, 2024
1 parent cf0531c commit 0201769
Show file tree
Hide file tree
Showing 20 changed files with 4,015 additions and 4,935 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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.0-alpha.11/dojo_v1.0.0-alpha.11_linux_amd64.tar.gz
curl -L -o dojo-linux-x86_64.tar.gz https://github.com/dojoengine/dojo/releases/download/v1.0.0-alpha.9/dojo_v1.0.0-alpha.9_linux_amd64.tar.gz
tar -xzf dojo-linux-x86_64.tar.gz
sudo mv sozo /usr/local/bin/
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb 2.7.0
dojo 1.0.0-alpha.11
dojo 1.0.0-alpha.9
8 changes: 4 additions & 4 deletions client/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ VITE_PUBLIC_MASTER_PRIVATE_KEY="0x78a5bf59b234910abf592a3e923093c5afe0db6e5d10d6
VITE_PUBLIC_WORLD_ADDRESS="0x6918fe8c1ba16bdc83b9790cd9168d730aa98a22c65164578ef99af1c8cbc76"
VITE_PUBLIC_ACCOUNT_CLASS_HASH="0x05400e90f7e0ae78bd02c77cd75527280470e2fe19c54970dd79dc37a9d3645c"
VITE_EVENT_KEY="0x1a2f334228cee715f1f0f54053bb6b5eac54fa336e0bc1aacf7516decb0471d"
VITE_PUBLIC_TORII="https://api.cartridge.gg/x/eternum-37/torii"
VITE_PUBLIC_NODE_URL="https://api.cartridge.gg/x/eternum-37/katana/"
VITE_PUBLIC_DEV=false
VITE_PUBLIC_TORII="https://api.cartridge.gg/x/eternum-chat/torii"
VITE_PUBLIC_NODE_URL="https://api.cartridge.gg/x/eternum-chat/katana/"
VITE_PUBLIC_DEV=true
VITE_PUBLIC_GAME_VERSION="v0.5.9"

VITE_PUBLIC_TORII_RELAY="/ip4/127.0.0.1/udp/9091/webrtc-direct/certhash/uEiB7Y_3R7E0VhbvODVQB4HulZlm1ZLEHHtVhoOMd827G5Q"
VITE_PUBLIC_TORII_RELAY="/dns4/api.cartridge.gg/tcp/443/x-parity-wss/%2Fx%2Feternum-chat%2Ftorii%2Fwss"
12 changes: 6 additions & 6 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
},
"dependencies": {
"@bibliothecadao/eternum": "workspace:^",
"@dojoengine/core": "1.0.0-alpha.12",
"@dojoengine/create-burner": "1.0.0-alpha.12",
"@dojoengine/react": "1.0.0-alpha.12",
"@dojoengine/core": "1.0.0-alpha.13",
"@dojoengine/create-burner": "1.0.0-alpha.13",
"@dojoengine/react": "1.0.0-alpha.13",
"@dojoengine/recs": "^2.0.13",
"@dojoengine/state": "1.0.0-alpha.12",
"@dojoengine/torii-client": "1.0.0-alpha.12",
"@dojoengine/utils": "1.0.0-alpha.12",
"@dojoengine/state": "1.0.0-alpha.13",
"@dojoengine/torii-client": "1.0.0-alpha.13",
"@dojoengine/utils": "1.0.0-alpha.13",
"@headlessui/react": "^1.7.18",
"@latticexyz/utils": "^2.0.0-next.12",
"@radix-ui/react-select": "^2.0.0",
Expand Down
1 change: 0 additions & 1 deletion client/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { DojoProvider } from "./hooks/context/DojoContext";
import "./index.css";
import GameRenderer from "./three/GameRenderer";
import { LoadingScreen } from "./ui/modules/LoadingScreen";
import { ACCOUNT_CHANGE_EVENT } from "./ui/modules/onboarding/Steps";

declare global {
interface Window {
Expand Down
31 changes: 13 additions & 18 deletions client/src/ui/modules/chat/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useDojo } from "@/hooks/context/DojoContext";
import { useCallback, useEffect, useState } from "react";
import { useGetAllPlayers } from "@/hooks/helpers/useEntities";
import TextInput from "@/ui/elements/TextInput";
import { useEntityQuery } from "@dojoengine/react";
import { getComponentValue, Has, HasValue } from "@dojoengine/recs";
import { shortString, TypedData } from "starknet";
import TextInput from "@/ui/elements/TextInput";
import { getEntityIdFromKeys } from "@dojoengine/utils";
import { useGetAllPlayers } from "@/hooks/helpers/useEntities";
import { useCallback, useEffect, useState } from "react";
import { shortString, TypedData } from "starknet";

import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/ui/elements/Select";

Expand All @@ -20,32 +20,25 @@ function generateMessageTypedData(identity: string, channel: string, content: st
{ name: "chainId", type: "shortstring" },
{ name: "revision", type: "shortstring" },
],
OffchainMessage: [
{ name: "model", type: "shortstring" },
{ name: "eternum-Message", type: "Model" },
],
Model: [
"eternum-Message": [
{ name: "identity", type: "ContractAddress" },
{ name: "channel", type: "shortstring" },
{ name: "content", type: "string" },
{ name: "salt", type: "felt" },
],
},
primaryType: "OffchainMessage",
primaryType: "eternum-Message",
domain: {
name: "Eternum",
version: "1",
chainId: "1",
revision: "1",
},
message: {
model: "eternum-Message",
"eternum-Message": {
identity,
channel,
content,
salt,
},
identity,
channel,
content,
salt,
},
};
}
Expand Down Expand Up @@ -126,6 +119,7 @@ export const Chat = () => {
};

const allMessageEntities = useEntityQuery([Has(Message)]);

const selfMessageEntities = useEntityQuery([Has(Message), HasValue(Message, { identity: BigInt(account.address) })]);
const receivedMessageEntities = useEntityQuery([
Has(Message),
Expand Down Expand Up @@ -184,7 +178,8 @@ export const Chat = () => {
const channel = !!recipientAddress ? `0x${recipientAddress.toString(16)}` : GLOBAL_CHANNEL;
const data = generateMessageTypedData(account.address, channel, message, `0x${salt?.toString(16)}`);
const signature: any = await account.signMessage(data as TypedData);
toriiClient.publishMessage(JSON.stringify(data), [

await toriiClient.publishMessage(JSON.stringify(data), [
`0x${signature.r.toString(16)}`,
`0x${signature.s.toString(16)}`,
]);
Expand Down
2 changes: 1 addition & 1 deletion client/src/ui/modules/onboarding/Steps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { LucideArrowRight } from "lucide-react";
import { useEffect, useState } from "react";
import { shortString } from "starknet";

export const ACCOUNT_CHANGE_EVENT = "addressChanged";
const ACCOUNT_CHANGE_EVENT = "addressChanged";

const StepContainer = ({ children }: { children: React.ReactNode }) => {
return (
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.7.0
dojo 1.0.0-alpha.11
dojo 1.0.0-alpha.9
2 changes: 1 addition & 1 deletion contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ source = "git+https://github.com/dojoengine/cubit?branch=cairo_2.7#53020b6320a10
[[package]]
name = "dojo"
version = "1.0.0-alpha.4"
source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0-alpha.11#e42ce0c220a59d75c5b08e87a81de12cfdc27a55"
source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0-alpha.9#e42ce0c220a59d75c5b08e87a81de12cfdc27a55"
dependencies = [
"dojo_plugin",
]
Expand Down
2 changes: 1 addition & 1 deletion contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version = "1.0.0"
sierra-replace-ids = true

[dependencies]
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.11" }
dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.9" }
alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "e1b080577aaa6889116fc8be5dde72b2fd21e397" }
alexandria_data_structures = { git = "https://github.com/keep-starknet-strange/alexandria.git", rev = "e1b080577aaa6889116fc8be5dde72b2fd21e397" }
cubit = { git = "https://github.com/dojoengine/cubit", branch = "cairo_2.7" }
Expand Down
6 changes: 3 additions & 3 deletions contracts/dojo_prod.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
default = "eternum"

[env]
account_address = "0xac5b6dcf77ccf3412c5161c095b3db80b703461c71f66637c830786b0600da"
private_key = "0x78a5bf59b234910abf592a3e923093c5afe0db6e5d10d6ff32e32d4d2a890f9"
rpc_url = "https://api.cartridge.gg/x/eternum-37/katana"
account_address = "0x8da9668c371967fed1218e0682ba9c7a84fbac8ed5ddcd6e7f7ac020644acd"
private_key = "0x62d981a8e5f9e51e0e189b8385c6312fe9ac07f7ce421ffed70aa2240a7159"
rpc_url = "https://api.cartridge.gg/x/eternum-chat/katana"

[world]
seed = "eternum"
Expand Down
Loading

0 comments on commit 0201769

Please sign in to comment.