Skip to content

Commit 9c9e4ef

Browse files
asanson1404willemneal
authored andcommitted
fix: correct version listing bug
feat: Possibility to choose the version to deploy refactor: deletion of unnecessary commented code style: change the shade color of SD logo and text in light mode
1 parent aef551b commit 9c9e4ef

File tree

7 files changed

+191
-32
lines changed

7 files changed

+191
-32
lines changed

components/ThemeContext.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ export const ThemeContextProvider: React.FC<ThemeContextProviderProps> = ({ chil
3636
}
3737
}, []);
3838

39-
//useEffect(() => {
40-
// localStorage.setItem("theme", activeTheme as ThemeType);
41-
//}, [activeTheme]);
42-
4339
return (
4440
<ThemeContext.Provider value={{ activeTheme, setActiveTheme, inactiveTheme }}>
4541
{children}

components/published-tab/index.tsx

Lines changed: 126 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { BsSendPlus } from 'react-icons/bs';
2+
import { IoMdArrowDropdown, IoMdArrowDropup } from 'react-icons/io'
23
import Popup from 'reactjs-popup';
34
import styles from './style.module.css';
5+
import Dropdown from 'react-dropdown';
46

57
import { smartdeploy, StateVariablesProps, UserWalletInfo, FetchDatas } from "@/pages";
68
import { isConnected } from '@stellar/freighter-api';
@@ -12,17 +14,30 @@ interface PublishedContract {
1214
index: number;
1315
name: string;
1416
author: string;
15-
version: Version;
16-
version_string: string;
17-
hash: string;
17+
versions: {
18+
version: Version,
19+
hash: string
20+
}[];
1821
}
1922

20-
type DeployIconComponentProps = {
23+
type DeployProps = {
2124
userWalletInfo: UserWalletInfo;
2225
refetchDeployedContract: FetchDatas;
2326
contract_name: string;
24-
version: Option<Version>;
25-
version_string: string;
27+
versions: {version: Version, version_string: string}[];
28+
}
29+
30+
type DeployVersionProps = {
31+
userWalletInfo: UserWalletInfo;
32+
refetchDeployedContract: FetchDatas;
33+
contract_name: string;
34+
selected_version: {version: Version, version_string: string};
35+
}
36+
37+
type VersionDropdownProps = {
38+
versions: {version: Version, version_string: string}[];
39+
selected_version: {version: Version, version_string: string};
40+
set_selected_version: Dispatch<SetStateAction<{version: Version, version_string: string}>>;
2641
}
2742

2843
type DeployArgsObj = {
@@ -48,20 +63,26 @@ async function listAllPublishedContracts() {
4863

4964
///@ts-ignore
5065
contractArray.forEach(([name, publishedContract], i) => {
51-
const version: Version = publishedContract.versions.keys().next().value;
52-
const major = version.major;
53-
const minor = version.minor;
54-
const patch = version.patch;
55-
const versionString = `v.${major}.${minor}.${patch}`;
56-
57-
const hash = publishedContract.versions.values().next().value.hash.join('');
66+
67+
let versions: {version: Version, hash: string}[] = [];
68+
69+
///@ts-ignore
70+
Array.from(publishedContract.versions).forEach((contractDatas: [Version, any]) => {
71+
72+
// Version object
73+
const version = contractDatas[0];
74+
75+
// hash
76+
const hash = contractDatas[1].hash.join('');
77+
78+
versions.push({version, hash});
79+
});
80+
5881
const parsedPublishedContract: PublishedContract = {
5982
index: i,
6083
name: name,
6184
author: publishedContract.author.toString(),
62-
version: version,
63-
version_string: versionString,
64-
hash: hash
85+
versions: versions
6586
};
6687

6788
publishedContracts.push(parsedPublishedContract);
@@ -141,7 +162,43 @@ async function deploy(
141162
}
142163
}
143164

144-
function DeployIconComponent(props: DeployIconComponentProps) {
165+
function VersionDropdownButton(props: VersionDropdownProps) {
166+
167+
const versions: string[] = [];
168+
169+
props.versions.forEach((version) => {
170+
versions.push(version.version_string);
171+
});
172+
173+
return(
174+
<div>
175+
<Dropdown
176+
className={styles.dropdownContainer}
177+
controlClassName={styles.dropdownControl}
178+
menuClassName={styles.dropdownMenu}
179+
options={versions}
180+
placeholder={versions[0]}
181+
arrowClosed={<IoMdArrowDropdown/>}
182+
arrowOpen={<IoMdArrowDropup/>}
183+
onChange={(version) => {
184+
185+
const newSelectedVersionString = version.value;
186+
187+
const [major, minor, patch] = version.value.split('.').slice(1);
188+
const newSelectedVersion: Version = {
189+
major: parseInt(major),
190+
minor: parseInt(minor),
191+
patch: parseInt(patch),
192+
}
193+
194+
props.set_selected_version({version: newSelectedVersion, version_string: newSelectedVersionString});
195+
}}
196+
/>
197+
</div>
198+
)
199+
}
200+
201+
function DeployIconComponent(props: DeployVersionProps) {
145202

146203
// Import the current Theme
147204
const { activeTheme } = useThemeContext();
@@ -173,7 +230,7 @@ function DeployIconComponent(props: DeployIconComponentProps) {
173230
<button className={styles.close} onClick={() => setWouldDeploy(false)}>
174231
&times;
175232
</button>
176-
<div className={styles.header}>Deploy <span className={styles.nameColor} data-theme={activeTheme}>{props.contract_name} ({props.version_string})</span> </div>
233+
<div className={styles.header}>Deploy <span className={styles.nameColor} data-theme={activeTheme}>{props.contract_name} ({props.selected_version.version_string})</span> </div>
177234
<div className={styles.content}>
178235
<p className={styles.mainMessage}><b>You are about to create an instance of <span className={styles.nameColor} data-theme={activeTheme}>{props.contract_name}</span> published contract where you will be the owner.</b><br/></p>
179236
<div className={styles.deployedNameDiv}>
@@ -200,7 +257,7 @@ function DeployIconComponent(props: DeployIconComponentProps) {
200257

201258
const argsObj: DeployArgsObj = {
202259
contract_name: props.contract_name,
203-
version: props.version,
260+
version: props.selected_version.version,
204261
deployed_name: deployedName,
205262
owner: props.userWalletInfo.address,
206263
salt: undefined
@@ -236,6 +293,35 @@ function DeployIconComponent(props: DeployIconComponentProps) {
236293
);
237294
}
238295

296+
function DeployVersionComponent(props: DeployProps) {
297+
298+
// The default selected version is the last one
299+
const defaultSelectedVersion = {
300+
version: props.versions[0].version,
301+
version_string: props.versions[0].version_string
302+
};
303+
304+
const [selectedVersion, setSelectedVersion] = useState<{version: Version, version_string: string}>(defaultSelectedVersion);
305+
306+
return (
307+
<>
308+
<td>
309+
<VersionDropdownButton
310+
versions={props.versions}
311+
selected_version={selectedVersion}
312+
set_selected_version={setSelectedVersion}
313+
/>
314+
</td>
315+
<DeployIconComponent
316+
userWalletInfo={props.userWalletInfo}
317+
refetchDeployedContract={props.refetchDeployedContract}
318+
contract_name={props.contract_name}
319+
selected_version={selectedVersion}
320+
/>
321+
</>
322+
)
323+
}
324+
239325

240326
export default function PublishedTab(props: StateVariablesProps) {
241327

@@ -310,17 +396,33 @@ export default function PublishedTab(props: StateVariablesProps) {
310396
const rows: JSX.Element[] = [];
311397

312398
publishedContracts.forEach((publishedContract) => {
399+
400+
const versions: {version: Version, version_string: string}[] = [];
401+
402+
publishedContract.versions.forEach((obj) => {
403+
404+
// Version obj
405+
const version = obj.version;
406+
407+
// Version string
408+
const major = version.major;
409+
const minor = version.minor;
410+
const patch = version.patch;
411+
const version_string = `v.${major}.${minor}.${patch}`;
412+
413+
versions.push({version, version_string});
414+
})
415+
versions.reverse();
416+
313417
rows.push(
314418
<tr key={publishedContract.index} data-theme={activeTheme}>
315419
<td className={styles.contractCell}>{publishedContract.name}</td>
316420
<td>{publishedContract.author}</td>
317-
<td>{publishedContract.version_string}</td>
318-
<DeployIconComponent
421+
<DeployVersionComponent
319422
userWalletInfo={props.walletInfo}
320423
refetchDeployedContract={props.fetchDeployed as FetchDatas}
321424
contract_name={publishedContract.name}
322-
version={publishedContract.version}
323-
version_string={publishedContract.version_string}
425+
versions={versions}
324426
/>
325427
</tr>
326428
);
@@ -340,7 +442,7 @@ export default function PublishedTab(props: StateVariablesProps) {
340442
<tr>
341443
<th>Contract</th>
342444
<th>Author</th>
343-
<th>Version</th>
445+
<th>Versions</th>
344446
<th>Deploy</th>
345447
</tr>
346448
</thead>

components/published-tab/style.module.css

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.publishedTabContainer {
2-
min-height: 18rem;
32
margin-bottom: 5rem;
43
border-top-left-radius: 10px;
54
border-top-right-radius: 10px;
@@ -17,7 +16,7 @@
1716

1817
.publishedTabContentContainer {
1918
max-height: 14.2rem;
20-
overflow-y: scroll;
19+
overflow-y: scroll !important;
2120
}
2221
.publishedTabContentContainer::-webkit-scrollbar {
2322
display: none;
@@ -66,6 +65,7 @@
6665
.publishedTabContent tbody tr {
6766
color: var(--tr-font-color);
6867
border-bottom: 1px solid var(--tr-border-bottom-color);
68+
position: relative;
6969
}
7070

7171
.publishedTabContent tbody tr:nth-of-type(even) {
@@ -207,4 +207,46 @@
207207
background: #ffffff;
208208
border-radius: 18px;
209209
border: 1px solid #cfcece;
210+
}
211+
212+
213+
.dropdownControl {
214+
display: flex;
215+
width: 4.8rem;
216+
justify-content: space-between;
217+
padding: 0.3rem 0.2rem 0.3rem 0.2rem;
218+
border-radius: 10px;
219+
}
220+
.dropdownControl:hover {
221+
background-color: rgba(128, 128, 128, 0.216);
222+
cursor: pointer;
223+
}
224+
225+
.dropdownMenu {
226+
position: absolute;
227+
top: 1.8rem;
228+
border-radius: 3px;
229+
z-index: 1;
230+
padding: 0.2rem 0.3rem;
231+
width: 4.8rem;
232+
background-color: rgb(187, 186, 184);
233+
font-size: 0.7rem;
234+
border: solid 1px rgb(6, 6, 6);
235+
}
236+
237+
.dropdownMenu > div {
238+
list-style: disc inside;
239+
font-weight: 600;
240+
color: black;
241+
cursor: pointer;
242+
border-bottom: 1px solid gray;
243+
padding-bottom: 0.2rem;
244+
padding-top: 0.2rem;
245+
}
246+
.dropdownMenu > div:last-child {
247+
border-bottom: none;
248+
}
249+
.dropdownMenu > div::before {
250+
content: "\2022";
251+
margin-right: 0.5rem;
210252
}

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"next": "13.5.4",
1717
"react": "^18",
1818
"react-dom": "^18",
19+
"react-dropdown": "^1.11.0",
1920
"react-icons": "^4.11.0",
2021
"reactjs-popup": "^2.0.6"
2122
},

styles/Home.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
}
229229

230230
.logoB {
231-
filter: invert(0) drop-shadow(0 0 0.3rem #22222270);
231+
filter: invert(0) drop-shadow(0 0 0.3rem #86858570);
232232
}
233233
}
234234

styles/globals.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ main[data-theme="dark"] {
9999
p,
100100
p[data-theme="light"] {
101101
--smart-deploy-message-color: rgb(32, 30, 30);
102-
--smart-deploy-message-filter-shadow: #00000070;
102+
--smart-deploy-message-filter-shadow: #89878770;
103103
--grid-doc-font-color: black;
104104
}
105105
p[data-theme="dark"] {

0 commit comments

Comments
 (0)