Skip to content

Commit 09049ef

Browse files
ericglaumakiopen
andauthored
Update UI design (#441)
Co-authored-by: makiopen <[email protected]>
1 parent 8ba4b75 commit 09049ef

26 files changed

+301
-160
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Contracts Wizard is a web application to interactively build a contract out of c
1212

1313
Install dependencies with `yarn install`.
1414

15-
`packages/core` contains the code generation logic for Solidity and Cairo under separately named subfolders.
15+
`packages/core` contains the code generation logic for each language under separately named subfolders.
1616

17-
`packages/ui` is the interface built in Svelte. `yarn dev` spins up a local server to develop the UI.
17+
`packages/ui` is the interface built in Svelte. From the `packages/ui` directory, run `yarn dev` to spin up a local server to develop the UI.
1818

1919
You'll need to supply your own environment variables if you want to enable Wizard AI Assistant (OPENAI_API_KEY) and/or logging (REDIS_URL, REDIS_TOKEN).
2020

@@ -30,7 +30,7 @@ Then place `<oz-wizard></oz-wizard>` in the body where you want Contracts Wizard
3030

3131
Optionally focus on specific tab with the `data-tab` attribute as in `<oz-wizard data-tab="ERC721"></oz-wizard>`.
3232

33-
For Cairo, use the `data-lang` attribute: `<oz-wizard data-lang="cairo"></oz-wizard>`.
33+
For languages other than Solidity, use the `data-lang` attribute, for example: `<oz-wizard data-lang="cairo"></oz-wizard>`.
3434

3535
## API
3636

packages/core/cairo/src/contract.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,14 @@ test('contract with standalone import', t => {
110110
t.snapshot(printContract(Foo));
111111
});
112112

113+
test('contract with sorted use clauses', t => {
114+
const Foo = new ContractBuilder('Foo');
115+
Foo.addComponent(
116+
FOO_COMPONENT,
117+
);
118+
Foo.addUseClause('some::library', 'SomeLibrary');
119+
Foo.addUseClause('another::library', 'AnotherLibrary');
120+
Foo.addUseClause('another::library', 'Foo', { alias: 'Custom2' });
121+
Foo.addUseClause('another::library', 'Foo', { alias: 'Custom1' });
122+
t.snapshot(printContract(Foo));
123+
});

packages/core/cairo/src/contract.test.ts.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,45 @@ Generated by [AVA](https://avajs.dev).
189189
}␊
190190
}␊
191191
`
192+
193+
## contract with sorted use clauses
194+
195+
> Snapshot 1
196+
197+
`// SPDX-License-Identifier: MIT␊
198+
// Compatible with OpenZeppelin Contracts for Cairo ^0.20.0␊
199+
200+
#[starknet::contract]␊
201+
mod Foo {␊
202+
use another::library::{AnotherLibrary, Foo as Custom1, Foo as Custom2};␊
203+
use some::library::SomeLibrary;␊
204+
use some::path::FooComponent;␊
205+
206+
component!(path: FooComponent, storage: foo, event: FooEvent);␊
207+
208+
// External␊
209+
#[abi(embed_v0)]␊
210+
impl FooImpl = FooComponent::FooImpl<ContractState>;␊
211+
212+
// Internal␊
213+
impl FooInternalImpl = FooComponent::InternalImpl<ContractState>;␊
214+
215+
#[storage]␊
216+
struct Storage {␊
217+
#[substorage(v0)]␊
218+
foo: FooComponent::Storage,␊
219+
}␊
220+
221+
#[event]␊
222+
#[derive(Drop, starknet::Event)]␊
223+
enum Event {␊
224+
#[flat]␊
225+
FooEvent: FooComponent::Event,␊
226+
}␊
227+
228+
#[constructor]␊
229+
fn constructor(ref self: ContractState) {␊
230+
self.foo.initializer();␊
231+
}␊
232+
}␊
233+
`
59 Bytes
Binary file not shown.

packages/core/cairo/src/print.ts

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,40 +67,23 @@ function getLinesFromUseClausesGroup(group: UseClause[], groupName: string): Lin
6767
const lines = [];
6868
if (groupName === STANDALONE_IMPORTS_GROUP) {
6969
for (const useClause of group) {
70-
const alias = useClause.alias ?? '';
71-
if (alias.length > 0) {
72-
lines.push(`use ${useClause.containerPath}::${useClause.name} as ${alias};`);
73-
} else {
74-
lines.push(`use ${useClause.containerPath}::${useClause.name};`);
75-
}
70+
lines.push(`use ${useClause.containerPath}::${nameWithAlias(useClause)};`);
7671
}
7772
} else {
7873
if (group.length == 1) {
79-
const alias = group[0]!.alias ?? '';
80-
if (alias.length > 0) {
81-
lines.push(`use ${groupName}::${group[0]!.name} as ${alias};`);
82-
} else {
83-
lines.push(`use ${groupName}::${group[0]!.name};`);
84-
}
85-
74+
lines.push(`use ${groupName}::${nameWithAlias(group[0]!)};`);
8675
} else if (group.length > 1) {
87-
let clauses = group.reduce((clauses, useClause) => {
88-
const alias = useClause.alias ?? '';
89-
if (alias.length > 0) {
90-
clauses += `${useClause.name} as ${useClause.alias}, `;
91-
} else {
92-
clauses += `${useClause.name}, `;
93-
}
94-
return clauses;
95-
}, '');
96-
clauses = clauses.slice(0, -2);
97-
98-
lines.push(`use ${groupName}::{${clauses}};`);
76+
let names = group.map((useClause) => nameWithAlias(useClause)).join(', ');
77+
lines.push(`use ${groupName}::{${names}};`);
9978
}
10079
}
10180
return lines;
10281
}
10382

83+
function nameWithAlias(useClause: UseClause): string {
84+
return useClause.alias ? `${useClause.name} as ${useClause.alias}` : useClause.name;
85+
}
86+
10487
// TODO: remove this when we can use a formatting js library
10588
function splitLongUseClauseLine(line: string): Lines[] {
10689
const lines = [];
@@ -136,8 +119,8 @@ function splitLongLineInner(line: string): Lines[] {
136119

137120
function sortUseClauses(contract: Contract): UseClause[] {
138121
return contract.useClauses.sort((a, b) => {
139-
const aFullPath = `${a.containerPath}::${a.name}`;
140-
const bFullPath = `${b.containerPath}::${b.name}`;
122+
const aFullPath = `${a.containerPath}::${nameWithAlias(a)}`;
123+
const bFullPath = `${b.containerPath}::${nameWithAlias(b)}`;
141124
return aFullPath.localeCompare(bFullPath);
142125
});
143126
}

packages/ui/public/cairo.html

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<head>
44
<meta charset='utf-8'>
55
<meta name='viewport' content='width=device-width,initial-scale=1'>
6-
<title>OpenZeppelin Contracts Wizard for Cairo</title>
6+
<title>OpenZeppelin Contracts Wizard</title>
77

88
<!-- Twitter card -->
99
<meta name="twitter:card" content="summary_large_image">
1010
<meta name="twitter:creator" content="@OpenZeppelin">
11-
<meta name="twitter:title" content="OpenZeppelin Contracts Wizard for Cairo">
12-
<meta name="twitter:description" content="An interactive smart contract generator based on OpenZeppelin Contracts for Cairo.">
11+
<meta name="twitter:title" content="OpenZeppelin Contracts Wizard">
12+
<meta name="twitter:description" content="An interactive smart contract generator based on OpenZeppelin Contracts.">
1313
<meta name="twitter:image" content="https://wizard.openzeppelin.com/tw-card.png">
1414

1515
<!-- Favicons -->
@@ -32,37 +32,49 @@
3232
<meta name="theme-color" content="#ffffff">
3333

3434
<!-- Scripts and CSS -->
35-
<link rel="preload" href="/fonts/silka-regular-webfont.woff2" as="font" type="font/woff2" crossorigin>
36-
<link rel="preload" href="/fonts/silka-semibold-webfont.woff2" as="font" type="font/woff2" crossorigin>
35+
<link rel="preload" href="/fonts/Inter-VariableFont_opsz,wght.ttf" as="font" type="font/woff2" crossorigin>
3736
<link rel='stylesheet' href='/build/standalone.css'>
3837
<script async src='/build/embed.js'></script>
3938
</head>
4039
<body>
4140

42-
<div class="header container flex flex-row justify-between overflow-auto">
43-
<div class="flex flex-row">
44-
<img src="/logo.svg" alt="OpenZeppelin" width="300px">
45-
<a class="switch switch-solidity switch-off" href="/">Solidity Wizard</a>
46-
<a class="switch switch-cairo" href="#">Cairo Wizard</a>
41+
<div class="header container flex flex-row justify-between items-center overflow-auto">
42+
<div class="flex flex-row items-center">
43+
<a href="https://www.openzeppelin.com/" target="_blank" rel="noopener noreferrer"><img src="/logo.svg" alt="OpenZeppelin" class="logo" width="160"></a>
4744
</div>
48-
<div class="flex flex-row">
45+
<div class="flex flex-row items-center">
4946
<a class="link" href="https://forum.openzeppelin.com/" target="_blank" rel="noopener noreferrer">Forum</a>
5047
<a class="link" href="https://docs.openzeppelin.com/" target="_blank" rel="noopener noreferrer">Docs</a>
51-
<a class="link" href="https://github.com/OpenZeppelin/cairo-contracts" target="_blank" rel="noopener noreferrer">GitHub</a>
52-
<a class="link" href="https://twitter.com/OpenZeppelin" target="_blank" rel="noopener noreferrer">Twitter</a>
48+
<a class="link" href="https://github.com/OpenZeppelin/" target="_blank" rel="noopener noreferrer"><img src="/icons/github-mark.svg" width="20" alt="GitHub OpenZeppelin"></a>
49+
<a class="link" href="https://x.com/OpenZeppelin" target="_blank" rel="noopener noreferrer"><img src="/icons/x-logo.svg" width="20" alt="Twitter/X"></a>
5350
</div>
5451
</div>
55-
52+
<div class="nav">
53+
<a class="switch switch-solidity" href="/"><img src="/icons/solidity.svg" alt="solidity">Solidity</a>
54+
<a class="switch switch-cairo active" href="#"><img src="/icons/cairo.svg" alt="cairo">Cairo</a>
55+
</div>
5656
<div class="wizard-container">
57+
5758
<oz-wizard class="wizard" data-sync-url="fragment" data-lang="cairo"></oz-wizard>
5859
</div>
5960

6061
<footer>
61-
<p>© <a href="https://openzeppelin.com" target="_blank" rel="noopener noreferrer">OpenZeppelin</a> 2022-2025 |&nbsp;<a href="https://openzeppelin.com/privacy" target="_blank" rel="noopener noreferrer">Privacy</a> |&nbsp;<a href="https://openzeppelin.com/tos" target="_blank" rel="noopener noreferrer">Terms of Service</a></p>
62+
<p>© <a href="https://openzeppelin.com" target="_blank" rel="noopener noreferrer">OpenZeppelin</a> 2017-2025 |&nbsp;<a href="https://openzeppelin.com/privacy" target="_blank" rel="noopener noreferrer">Privacy</a> |&nbsp;<a href="https://openzeppelin.com/tos" target="_blank" rel="noopener noreferrer">Terms of Service</a></p>
6263
</footer>
6364

6465
<!-- Start of HubSpot Embed Code -->
6566
<script type="text/javascript" id="hs-script-loader" async defer src="//js.hs-scripts.com/7795250.js"></script>
6667
<!-- End of HubSpot Embed Code -->
68+
<!-- Hotjar Tracking Code for OpenZeppelinWizard -->
69+
<script>
70+
(function(h,o,t,j,a,r){
71+
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
72+
h._hjSettings={hjid:5302135,hjsv:6};
73+
a=o.getElementsByTagName('head')[0];
74+
r=o.createElement('script');r.async=1;
75+
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
76+
a.appendChild(r);
77+
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
78+
</script>
6779
</body>
6880
</html>
Binary file not shown.

packages/ui/public/icons/cairo.svg

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

packages/ui/public/icons/solidity.svg

Lines changed: 8 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)