Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some issues #174

Merged
merged 5 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/components/DeveloperIDE/Projects/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,10 @@ const Projects = observer(() => {
allProjects.onSelect(index);
w3s.showContent = 'METRICS';
} else {
const appletID = await w3s.applet.createAppletForDeveloper({
projectName: project.name
await w3s.applet.uploadWASM({
projectName: project.name,
formTitle: 'Upload WASM'
});
if (appletID) {
eventBus.emit('applet.create');
}
}
}}
>
Expand All @@ -169,15 +167,13 @@ const Projects = observer(() => {
{...defaultButtonStyle}
onClick={async (e) => {
e.stopPropagation();
const appletID = await w3s.applet.createAppletForDeveloper({
projectName: project.name
await w3s.applet.uploadWASM({
projectName: project.name,
formTitle: 'Upload WASM'
});
if (appletID) {
eventBus.emit('applet.create');
}
}}
>
Create instance
Upload WASM
</Button>
)}
</Flex>
Expand Down
25 changes: 8 additions & 17 deletions src/components/DeveloperIDE/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ const Settings = () => {
} = useStore();

const store = useLocalObservable(() => ({
get curApplet() {
return applet.allData.find((item) => item.project_name === project.curProject?.name);
},
get curInstance() {
return instances.table.dataSource.find((item) => item.project_name === project.curProject?.name);
},
Expand Down Expand Up @@ -51,10 +48,10 @@ const Settings = () => {
}, []);

useEffect(() => {
if (store.curApplet) {
applet.wasmName.call(store.curApplet.f_resource_id);
if (applet.curApplet) {
applet.wasmName.call(applet.curApplet.f_resource_id);
}
}, [store.curApplet]);
}, [applet.curApplet]);

return (
<Box w="100%" minH={'calc(100vh - 158px)'}>
Expand Down Expand Up @@ -113,19 +110,13 @@ const Settings = () => {
size="sm"
{...defaultOutlineButtonStyle}
onClick={async () => {
if (store.curApplet && store.curInstance) {
applet.form.uiSchema.projectName = {
'ui:widget': 'hidden'
};
applet.form.uiSchema.appletName = {
'ui:widget': 'hidden'
};
applet.form.value.set({
if (applet.curApplet && store.curInstance) {
await applet.uploadWASM({
projectName: project.curProject?.name,
appletName: store.curApplet.f_name
appletName: applet.curApplet.f_name,
type: 'update',
formTitle: 'Update WASM'
});
await applet.updateWASM(store.curApplet.f_applet_id, store.curApplet.f_name);
applet.wasmName.call(store.curApplet.f_resource_id);
}
}}
>
Expand Down
56 changes: 22 additions & 34 deletions src/components/IDE/EventLogs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ const poll = (fn: { (): Promise<void>; (): void; }, interval = 3000) => {

const EventLogs = observer(() => {
const {
w3s,
w3s: {
publisher,
project: { curProject }
Expand Down Expand Up @@ -197,39 +196,28 @@ const EventLogs = observer(() => {
}}
onClick={async () => {
publisher.developerPublishEventForm.afterSubmit = async ({ formData }) => {
const projectName = curProject?.f_name;
if (projectName) {
const pub = publisher.allData.find((item) => item.project_id === curProject?.f_project_id);
if (!pub) {
showNotification({ color: 'red', message: 'Please create a device account first.' });
eventBus.emit('base.formModal.abort');
setTimeout(() => {
w3s.showContent = 'CURRENT_PUBLISHERS';
}, 2000);
return;
}
publisher.records.push({
type: formData.type,
body: formData.body
publisher.records.push({
type: formData.type,
body: formData.body
});
try {
const token = await hooks.waitPublisher();
await axios.request({
method: 'post',
url: `/api/w3bapp/event/${curProject?.f_nam}`,
headers: {
Authorization: token,
'Content-Type': 'application/octet-stream'
},
params: {
eventType: formData.type || 'DEFAULT',
timestamp: Date.now()
},
data: formData.body
});
try {
const res = await axios.request({
method: 'post',
url: `/api/w3bapp/event/${projectName}`,
headers: {
Authorization: pub.f_token,
'Content-Type': 'application/octet-stream'
},
params: {
eventType: formData.type || 'DEFAULT',
timestamp: Date.now()
},
data: formData.body
});
showNotification({ color: 'green', message: 'Send event successed' });
} catch (error) {
showNotification({ color: 'red', message: 'send event failed' });
}
showNotification({ color: 'green', message: 'Send event successed' });
} catch (error) {
showNotification({ color: 'red', message: 'send event failed' });
}
};
hooks.getFormData({
Expand Down Expand Up @@ -317,7 +305,7 @@ const EventLogs = observer(() => {
const createdAt = store.logs[0]?.f_created_at;
const res = await fetchWasmLogs({
projectName,
limit: 10,
limit: 50,
lt: createdAt ? Number(createdAt) : undefined,
});
store.setData({
Expand Down
5 changes: 3 additions & 2 deletions src/components/JSONMetricsView/LineChartCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ export const LineChartCard = ({
},
yScale = {
type: 'linear',
min: 'auto',
min: 0,
max: 'auto',
stacked: true,
reverse: false
reverse: false,
nice: true,
},
axisTop = null,
axisRight = null,
Expand Down
25 changes: 25 additions & 0 deletions src/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { eventBus } from './event';
import initSqlJs from 'sql.js';
import { IndexDb } from './dexie';
import { helper } from './helper';
import { axios } from './axios';

export const hooks = {
async waitReady() {
Expand Down Expand Up @@ -73,5 +74,29 @@ export const hooks = {
res();
}, ms);
});
},
async waitPublisher() {
const allPublisher = rootStore.w3s.publisher.allData;
const curProject = rootStore.w3s.project.curProject;
const pub = allPublisher.find((item) => item.project_id === curProject?.f_project_id);
if (pub) {
return pub.f_token;
} else {
try {
const key = `default`;
const res = await axios.request({
method: 'post',
url: `/api/w3bapp/publisher/x/${curProject?.name}`,
data: {
key,
name: key
}
});
eventBus.emit('publisher.create');
return res.data?.token;
} catch (error) {
return;
}
}
}
};
Loading