Skip to content

Commit 42477da

Browse files
update challenge-base v2
2 parents f3f0f82 + 7149cb4 commit 42477da

35 files changed

+1295
-1459
lines changed

.github/workflows/demo.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: scaffold-stark-demo workflow
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches: [main]
7+
paths:
8+
- 'packages/nextjs/**'
9+
10+
jobs:
11+
version-bump-nextjs:
12+
runs-on: ubuntu-22.04
13+
steps:
14+
15+
- name: Checkout Source Repository
16+
uses: actions/checkout@v4
17+
with:
18+
repository: Quantum3-Labs/scaffold-stark-2
19+
token: ${{ secrets.ORG_GITHUB_TOKEN }}
20+
path: source_repo
21+
22+
- name: Modify scaffoldConfig in Source Repository
23+
run: |
24+
cd source_repo
25+
sed -i 's/targetNetworks: \[chains.devnet\]/targetNetworks: \[chains.sepolia\]/' packages/nextjs/scaffold.config.ts
26+
cat packages/nextjs/scaffold.config.ts
27+
28+
- name: Set up Node.js
29+
uses: actions/setup-node@v3
30+
with:
31+
node-version: 20
32+
registry-url: 'https://registry.yarnpkg.com'
33+
34+
- name: Deploy to vercel
35+
if: success()
36+
id: deploy
37+
env:
38+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
39+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
40+
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
41+
run: |
42+
cd source_repo
43+
yarn install
44+
vercel link --yes --project $VERCEL_PROJECT_ID --token $VERCEL_TOKEN --scope $VERCEL_ORG_ID
45+
vercel --build-env NEXT_PUBLIC_IGNORE_BUILD_ERROR=true --prod --token $VERCEL_TOKEN --scope $VERCEL_ORG_ID
46+
47+
- name: Notify Slack on Success
48+
if: success()
49+
uses: slackapi/[email protected]
50+
with:
51+
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
52+
slack-message: "GitHub deployed to vercel result: ${{ job.status }}\nRepository Name: ${{ github.repository }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
53+
env:
54+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
55+
56+
- name: Notify Slack on Failure
57+
if: failure()
58+
uses: slackapi/[email protected]
59+
with:
60+
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
61+
slack-message: "GitHub deployed to vercel result: ${{ job.status }}\nRepository Name: ${{ github.repository }}\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
62+
env:
63+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
64+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Version Bump and Notify
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches: [main]
7+
8+
jobs:
9+
version-bump:
10+
runs-on: ubuntu-22.04
11+
12+
steps:
13+
- name: Checkout Source Repository
14+
uses: actions/checkout@v4
15+
with:
16+
repository: Quantum3-Labs/scaffold-stark-2
17+
token: ${{ secrets.ORG_GITHUB_TOKEN }}
18+
path: source_repo
19+
20+
- name: Checkout Destination Repository
21+
uses: actions/checkout@v4
22+
with:
23+
repository: Quantum3-Labs/create-stark
24+
token: ${{ secrets.ORG_GITHUB_TOKEN }}
25+
path: destination_repo
26+
27+
- name: Determine version bump type
28+
id: version
29+
run: |
30+
cd source_repo
31+
commit_message=$(git log -1 --pretty=%B)
32+
if [[ "$commit_message" == *"[major]"* ]]; then
33+
echo "type=major" >> "$GITHUB_ENV"
34+
elif [[ "$commit_message" == *"[minor]"* ]]; then
35+
echo "type=minor" >> "$GITHUB_ENV"
36+
else
37+
echo "type=patch" >> "$GITHUB_ENV"
38+
fi
39+
40+
- name: Bump version in Source Repository
41+
id: bump-version-source
42+
run: |
43+
cd source_repo
44+
git config --global user.name 'github-actions[bot]'
45+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
46+
new_version=$(npm version ${{ env.type }} -m "chore(release): %s [skip ci]")
47+
echo "NEW_VERSION=${new_version}" >> "$GITHUB_ENV"
48+
git push origin main --follow-tags
49+
50+
- name: Copy Files to Destination Repository
51+
run: |
52+
rsync -av --delete --exclude='.git' source_repo/ destination_repo/templates/base
53+
cd destination_repo
54+
git add .
55+
git commit -m "chore: sync files from scaffold-stark-2 [skip ci]"
56+
57+
- name: Format .gitignore files
58+
run: |
59+
find destination_repo/templates/base -type f -name ".gitignore" | while read -r gitignore_file; do
60+
mjs_file="${gitignore_file%/*}/.gitignore.template.mjs"
61+
gitignore_content=$(cat "$gitignore_file")
62+
cat > "$mjs_file" <<-EOF
63+
const contents = () =>
64+
\`${gitignore_content}\`
65+
66+
export default contents;
67+
EOF
68+
rm "$gitignore_file"
69+
done
70+
cd destination_repo
71+
git add .
72+
git commit -m "Processed $gitignore_file into $mjs_file"
73+
74+
- name: Bump version in Destination Repository
75+
id: bump-version-destination
76+
run: |
77+
cd destination_repo
78+
git config --global user.name 'github-actions[bot]'
79+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
80+
new_version=$(npm version ${{ env.type }} -m "chore(release): %s [skip ci]")
81+
git push origin main --follow-tags
82+
83+
- name: Set up Node.js
84+
uses: actions/setup-node@v3
85+
with:
86+
node-version: '16'
87+
registry-url: 'https://registry.npmjs.org/'
88+
89+
- name: Publish release
90+
if: success()
91+
id: publish-release
92+
run: |
93+
cd destination_repo
94+
npm install && npm run build && npm publish
95+
env:
96+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
97+
98+
- name: Notify Slack on Success
99+
if: success()
100+
uses: slackapi/[email protected]
101+
with:
102+
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
103+
slack-message: "GitHub Action succeeded for version bump to ${{ env.NEW_VERSION }}."
104+
env:
105+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
106+
107+
- name: Notify Slack on Failure
108+
if: failure()
109+
uses: slackapi/[email protected]
110+
with:
111+
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
112+
slack-message: "GitHub Action failed for version bump."
113+
env:
114+
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

.github/workflows/test_contract.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ jobs:
1616
uses: actions/checkout@master
1717

1818
- name: Install scarb
19-
run: curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.5.4
19+
run: curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.6.5
2020

2121
- name: Install snfoundryup
2222
run: curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh
2323

2424
- name: Install snforge
25-
run: snfoundryup -v 0.25.0
25+
run: snfoundryup -v 0.27.0
2626

2727
- name: Run snforge tests
2828
run: snforge test

.gitmodules

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
[submodule "packages/snfoundry/local-devnet"]
2-
path = packages/snfoundry/local-devnet
3-
url = https://github.com/0xSpaceShard/starknet-devnet-rs
4-
branch = json-rpc-v0.5.1

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ If your changes involve updates to how users interact with Scaffold-Stark or Spe
3737

3838
## Need Help?
3939

40-
Reach out via our community channels if you encounter issues or need clarification on contributing.
40+
Reach out via our community channels if you encounter issues or need clarification on contributing [here](https://t.me/+wO3PtlRAreo4MDI9).

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Make sure you have the compatible versions otherwise refer to [Scaffold-Stark Re
3030
Then download the challenge to your computer and install dependencies by running:
3131

3232
```sh
33-
git clone https://github.com/Quantum3-Labs/speedrunstark.git --recurse-submodules {challengeName}
33+
git clone https://github.com/Quantum3-Labs/speedrunstark.git {challengeName}
3434
cd {challengeName}
3535
git checkout {challengeName}
3636
yarn install

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ss-2",
3-
"version": "0.0.2",
3+
"version": "0.2.3",
44
"author": "Q3 Labs",
55
"license": "MIT",
66
"private": true,

packages/nextjs/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
NEXT_PUBLIC_PROVIDER_URL=https://starknet-sepolia.infura.io/v3/c45bd0ce3e584ba4a5e6a5928c9c0b0f
1+
NEXT_PUBLIC_PROVIDER_URL=https://starknet-sepolia.public.blastapi.io/rpc/v0_7
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { Dispatch, SetStateAction, useEffect, useMemo, useState } from "react";
2+
import { getFunctionInputKey, getInitialTupleFormState } from "./utilsContract";
3+
import {
4+
AbiEnum,
5+
AbiParameter,
6+
AbiStruct,
7+
} from "~~/utils/scaffold-stark/contract";
8+
import { replacer } from "~~/utils/scaffold-stark/common";
9+
import { ContractInput } from "./ContractInput";
10+
import { Abi } from "abi-wan-kanabi";
11+
import { parseGenericType } from "~~/utils/scaffold-stark";
12+
13+
type ArrayProps = {
14+
abi: Abi;
15+
abiParameter: AbiParameter;
16+
parentForm: Record<string, any> | undefined;
17+
setParentForm: (form: Record<string, any>) => void;
18+
parentStateObjectKey: string;
19+
setFormErrorMessage: Dispatch<SetStateAction<string | null>>;
20+
};
21+
22+
export const ArrayInput = ({
23+
abi,
24+
parentForm,
25+
setParentForm,
26+
parentStateObjectKey,
27+
abiParameter,
28+
setFormErrorMessage,
29+
}: ArrayProps) => {
30+
// array in object representation
31+
const [inputArr, setInputArr] = useState<any>({});
32+
const [arrLength, setArrLength] = useState<number>(-1);
33+
34+
const elementType = useMemo(() => {
35+
const parsed = parseGenericType(abiParameter.type);
36+
return Array.isArray(parsed) ? parsed[0] : parsed;
37+
}, [abiParameter.type]);
38+
39+
// side effect to transform data before setState
40+
useEffect(() => {
41+
// non empty objects only
42+
setParentForm({
43+
...parentForm,
44+
[parentStateObjectKey]: Object.values(inputArr).filter(
45+
(item) => item !== null,
46+
),
47+
});
48+
// eslint-disable-next-line react-hooks/exhaustive-deps
49+
}, [JSON.stringify(inputArr, replacer)]);
50+
51+
return (
52+
<div>
53+
<div className="collapse bg-base-200 pl-4 pt-1.5 pb-2 border-2 border-secondary custom-after">
54+
<input type="checkbox" className="min-h-fit peer" />
55+
<div className="collapse-title p-0 min-h-fit peer-checked:mb-2 text-primary-content/50">
56+
<p className="m-0 p-0 text-[1rem]">array (length: {arrLength + 1})</p>
57+
</div>
58+
<div className="ml-3 flex-col space-y-4 border-secondary/80 border-l-2 pl-4 collapse-content">
59+
{/* do note here that the "index" are basically array keys */}
60+
{Object.keys(inputArr).map((index) => {
61+
return (
62+
<ContractInput
63+
abi={abi}
64+
key={index}
65+
setForm={(
66+
nextInputRecipe:
67+
| Record<string, any>
68+
| ((arg: Record<string, any>) => void),
69+
) => {
70+
let nextInputObject: Record<string, any> = nextInputRecipe;
71+
72+
// set state recipe function, handle
73+
if (typeof nextInputRecipe === "function") {
74+
nextInputObject = nextInputRecipe(parentForm!);
75+
}
76+
77+
const currentInputArray = { ...inputArr };
78+
79+
// we do some nasty workaround
80+
currentInputArray[index] =
81+
nextInputObject?.[`input_${index}`] || null;
82+
83+
setInputArr(currentInputArray);
84+
}}
85+
form={inputArr[index]}
86+
stateObjectKey={`input_${index}`}
87+
paramType={
88+
{
89+
name: `${abiParameter.name}[${index}]`,
90+
type: elementType,
91+
} as AbiParameter
92+
}
93+
setFormErrorMessage={setFormErrorMessage}
94+
/>
95+
);
96+
})}
97+
<div className="flex gap-3">
98+
<button
99+
onClick={() => {
100+
const nextLength = arrLength + 1;
101+
setInputArr((prev: any) => ({
102+
...prev,
103+
[nextLength]: null,
104+
}));
105+
setArrLength(nextLength);
106+
}}
107+
className="btn btn-sm shadow-none border border-success text-white"
108+
>
109+
+ Add (push)
110+
</button>
111+
<button
112+
className="btn btn-sm shadow-none border border-error text-white"
113+
onClick={() => {
114+
if (arrLength > -1) {
115+
const nextInputArr = { ...inputArr };
116+
delete nextInputArr[arrLength];
117+
setInputArr(nextInputArr);
118+
setArrLength((prev) => prev - 1);
119+
}
120+
}}
121+
>
122+
- Remove (pop)
123+
</button>
124+
</div>
125+
</div>
126+
</div>
127+
</div>
128+
);
129+
};

0 commit comments

Comments
 (0)