-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcreate-pimetaconnect.sh
More file actions
258 lines (224 loc) · 5.75 KB
/
Copy pathcreate-pimetaconnect.sh
File metadata and controls
258 lines (224 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/bin/bash
# Exit on error
set -e
# Define project structure
PROJECT_NAME="PiMetaConnect"
COMPONENTS_DIR="$PROJECT_NAME/src/components"
SERVICES_DIR="$PROJECT_NAME/src/services"
STYLES_DIR="$PROJECT_NAME/src/styles"
PUBLIC_DIR="$PROJECT_NAME/public"
# Create directories
echo "Creating project structure..."
mkdir -p "$COMPONENTS_DIR" "$SERVICES_DIR" "$STYLES_DIR" "$PUBLIC_DIR"
# Create package.json
cat <<EOL > "$PROJECT_NAME/package.json"
{
"name": "pimetaconnect",
"version": "1.0.0",
"description": "A social platform integrated with Pi Network.",
"main": "src/index.js",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1"
},
"devDependencies": {},
"keywords": [],
"author": "Ze0ro99",
"license": "MIT"
}
EOL
echo "Created package.json."
# Create README.md
cat <<EOL > "$PROJECT_NAME/README.md"
# PiMetaConnect
A social platform integrated with the Pi Network.
## Features
- **Login/Logout**: Authenticate users using a mock Pi SDK.
- **Wallet Component**: Display user wallet balance.
- **Dark Mode Support**: Includes dark mode styling.
## Structure
\`\`\`
PiMetaConnect/
├── src/
│ ├── components/
│ │ ├── LoginComponent.js
│ │ ├── WalletComponent.js
│ ├── services/
│ │ ├── mock-pi-sdk.js
│ ├── styles/
│ │ ├── dark-mode.css
│ ├── App.js
│ ├── index.js
├── public/
├── README.md
├── package.json
\`\`\`
## Installation
1. Clone the repository:
\`git clone <repo-url>\`
2. Navigate to the project directory:
\`cd PiMetaConnect\`
3. Install dependencies:
\`npm install\`
4. Start the development server:
\`npm start\`
EOL
echo "Created README.md."
# Create App.js
cat <<EOL > "$PROJECT_NAME/src/App.js"
import React, { useState } from "react";
import LoginComponent from "./components/LoginComponent";
import WalletComponent from "./components/WalletComponent";
import "./styles/dark-mode.css";
const App = () => {
const [user, setUser] = useState(null);
return (
<div>
<h1>PiMetaConnect</h1>
<LoginComponent setUser={setUser} />
<WalletComponent user={user} />
</div>
);
};
export default App;
EOL
echo "Created App.js."
# Create index.js
cat <<EOL > "$PROJECT_NAME/src/index.js"
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
);
EOL
echo "Created index.js."
# Create LoginComponent.js
cat <<EOL > "$COMPONENTS_DIR/LoginComponent.js"
import React, { useState } from "react";
import mockPiSDK from "../services/mock-pi-sdk";
const LoginComponent = ({ setUser }) => {
const [error, setError] = useState("");
const handleLogin = async () => {
try {
const user = await mockPiSDK.login();
setUser(user);
setError("");
} catch (err) {
setError("Login failed. Please try again.");
}
};
const handleLogout = () => {
setUser(null);
};
return (
<div className="login-container">
<h2>Login</h2>
<button onClick={handleLogin}>Login</button>
<button onClick={handleLogout}>Logout</button>
{error && <p className="error">{error}</p>}
</div>
);
};
export default LoginComponent;
EOL
echo "Created LoginComponent.js."
# Create WalletComponent.js
cat <<EOL > "$COMPONENTS_DIR/WalletComponent.js"
import React, { useState } from "react";
import mockPiSDK from "../services/mock-pi-sdk";
const WalletComponent = ({ user }) => {
const [balance, setBalance] = useState(null);
const [error, setError] = useState("");
const fetchWalletBalance = async () => {
if (!user) {
setError("User not logged in.");
return;
}
try {
const response = await mockPiSDK.getWalletBalance(user.userId);
if (response.success) {
setBalance(response.balance);
setError("");
} else {
setError("Failed to fetch wallet balance.");
}
} catch (err) {
setError("An error occurred while fetching wallet balance.");
}
};
return (
<div className="wallet-container">
<h2>Wallet</h2>
{user ? (
<div>
<button onClick={fetchWalletBalance}>Show Wallet Balance</button>
{balance !== null && <p>Balance: {balance} Pi</p>}
</div>
) : (
<p>Please log in to view wallet balance.</p>
)}
{error && <p className="error">{error}</p>}
</div>
);
};
export default WalletComponent;
EOL
echo "Created WalletComponent.js."
# Create mock-pi-sdk.js
cat <<EOL > "$SERVICES_DIR/mock-pi-sdk.js"
const mockPiSDK = {
login: async () => {
return new Promise((resolve) => {
setTimeout(() => resolve({ userId: "12345", username: "PiUser" }), 1000);
});
},
getWalletBalance: async (userId) => {
return new Promise((resolve) => {
setTimeout(() => resolve({ success: true, balance: 100 }), 1000);
});
},
};
export default mockPiSDK;
EOL
echo "Created mock-pi-sdk.js."
# Create dark-mode.css
cat <<EOL > "$STYLES_DIR/dark-mode.css"
body {
background-color: #121212;
color: #ffffff;
}
button {
background-color: #1e88e5;
color: #ffffff;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #1565c0;
}
.login-container, .wallet-container {
margin: 20px auto;
padding: 20px;
background-color: #1e1e1e;
border-radius: 10px;
text-align: center;
}
.error {
color: #f44336;
}
EOL
echo "Created dark-mode.css."
echo "Project setup complete. Navigate to $PROJECT_NAME and run 'npm install' to install dependencies."