Skip to content

Commit

Permalink
Clean up some items around contracts
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Richardson <[email protected]>
  • Loading branch information
awrichar committed Apr 13, 2022
1 parent 2be19a5 commit 064b027
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 20 deletions.
4 changes: 4 additions & 0 deletions server/src/controllers/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ export class ContractsController {
location: api.location,
});
return listeners.map((l) => ({
id: l.id,
name: l.name,
topic: l.topic,
address: l.location.address,
eventName: l.event.name,
}));
}

Expand All @@ -132,9 +134,11 @@ export class ContractsController {
name: body.name,
});
return {
id: listener.id,
name: listener.name,
topic: listener.topic,
address: listener.location.address,
eventName: listener.event.name,
};
}
}
Expand Down
6 changes: 6 additions & 0 deletions server/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ export class ContractListener {
}

export class ContractListenerLookup {
@IsString()
id: string;

@IsString()
name?: string;

Expand All @@ -239,6 +242,9 @@ export class ContractListenerLookup {

@IsString()
address: string;

@IsString()
eventName: string;
}

export class Transaction {
Expand Down
12 changes: 8 additions & 4 deletions server/test/contracts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ describe('Smart Contracts', () => {
},
} as FireFlyContractAPI;
const listener = {
name: 'listener1',
id: 'listener1',
topic: 'my-app',
location: { address: '0x123' },
event: { name: 'event1' },
} as FireFlyContractListener;

mockFireFly.getContractAPI.mockResolvedValueOnce(api);
Expand All @@ -181,9 +182,10 @@ describe('Smart Contracts', () => {
.expect(200)
.expect([
{
name: 'listener1',
id: 'listener1',
topic: 'my-app',
address: '0x123',
eventName: 'event1',
},
]);

Expand All @@ -197,17 +199,19 @@ describe('Smart Contracts', () => {
topic: 'my-app',
};
const listener = {
name: 'listener1',
id: 'listener1',
topic: 'my-app',
location: { address: '0x123' },
event: { name: 'Changed' },
} as FireFlyContractListener;

mockFireFly.createContractAPIListener.mockResolvedValueOnce(listener);

await request(server).post('/api/contracts/listener').send(req).expect(200).expect({
name: 'listener1',
id: 'listener1',
topic: 'my-app',
address: '0x123',
eventName: 'Changed',
});

expect(mockFireFly.createContractAPIListener).toHaveBeenCalledWith('my-api', 'Changed', {
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/Accordion/ContractStateAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const ContractStateAccordion: React.FC = () => {
<Grid container>
{contractListeners
?.filter((l) => l.address === api.address)
.map((l, idx) => {
.map((l) => {
return (
<Grid
item
Expand All @@ -137,11 +137,11 @@ export const ContractStateAccordion: React.FC = () => {
direction="row"
justifyContent="space-between"
alignItems="flex-start"
key={idx}
key={l.id}
>
<Grid item>
<FFAccordionText
text={`${t('listener')}: ${l.name}; ${t(
text={`${t('listener')}: ${l.eventName}; ${t(
'topic'
)}:${l.topic}`}
color="secondary"
Expand Down
11 changes: 7 additions & 4 deletions ui/src/components/Buttons/RunButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ export const RunButton: React.FC<Props> = ({ endpoint, payload, disabled }) => {
status: response.status,
statusText: response.statusText,
});
return response.json();
return Promise.all([response, response.json()]);
})
.then((data) => {
.then((result) => {
const [response, data] = result;
setShowSnackbar(true);
setApiResponse(data);
setJustSubmitted(true);
addAwaitedEventID(data);
if (response.status === 202) {
setJustSubmitted(true);
addAwaitedEventID(data);
}
})
.catch((err) => {
setShowSnackbar(true);
Expand Down
6 changes: 0 additions & 6 deletions ui/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import React, { useContext, useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import ReconnectingWebSocket from 'reconnecting-websocket';
import { EventContext } from '../contexts/EventContext';
import { SnackbarContext } from '../contexts/SnackbarContext';
import { FF_EVENTS } from '../ff_models/eventTypes';
import { FFColors } from '../theme';
import { MenuLogo } from './Logos/MenuLogo';
Expand All @@ -37,7 +36,6 @@ const WS_URL = `ws://${window.location.host}/api/ws`;

export const Header: React.FC = () => {
const { t } = useTranslation();
const { setMessage } = useContext(SnackbarContext);
const { addLogToHistory } = useContext(EventContext);
const [wsConnected, setWsConnected] = useState<boolean>(false);
const webSocket = useRef<ReconnectingWebSocket | null>(null);
Expand All @@ -54,10 +52,6 @@ export const Header: React.FC = () => {
webSocket.current.onopen = function () {
setWsConnected(true);
};
// On Error
webSocket.current.onerror = function () {
setMessage(t('websocketConnectionFailure'));
};
// On Message
webSocket.current.onmessage = (message: any) => {
const eventData = JSON.parse(message.data);
Expand Down
4 changes: 3 additions & 1 deletion ui/src/interfaces/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ export interface IContractApi {
}

export interface IContractListener {
id: string;
address: string;
name: string;
name?: string;
topic: string;
eventName: string;
}

export interface IDatatype {
Expand Down
3 changes: 1 addition & 2 deletions ui/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,5 @@
"typescriptSDK": "Typescript SDK",
"uploadFile": "Upload File",
"version": "Version",
"waitingForTxEventsToFinish": "Waiting for Events to Finish...",
"websocketConnectionFailure": "Failed to connect to websocket. Please try again."
"waitingForTxEventsToFinish": "Waiting for Events to Finish..."
}

0 comments on commit 064b027

Please sign in to comment.