Skip to content

Commit

Permalink
update sandbox to work with different namespaces
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Shorsher <[email protected]>
  • Loading branch information
shorsher committed Sep 2, 2022
1 parent 9a97abd commit 86176f5
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions server/src/clients/firefly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { InternalServerError } from 'routing-controllers';

export const firefly = new FireFly({
host: process.env.FF_ENDPOINT || 'http://localhost:5000',
namespace: process.env.FF_DEFAULT_NAMESPACE || 'default',
});

firefly.onError((err) => {
Expand Down
10 changes: 6 additions & 4 deletions server/src/controllers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Get, InternalServerError, JsonController, Param, QueryParam } from 'rou
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { firefly } from '../clients/firefly';
import { FFStatus, Organization, Plugin, Plugins, Transaction, Verifier } from '../interfaces';

const DEFAULT_NAMESPACE = process.env.FF_DEFAULT_NAMESPACE || 'default';
/**
* Common Operations - API Server
*/
Expand Down Expand Up @@ -35,7 +35,7 @@ export class CommonController {
async verifiers(): Promise<Verifier[]> {
try {
const orgs = await firefly.getOrganizations();
let verifiers = await firefly.getVerifiers('default');
let verifiers = await firefly.getVerifiers(DEFAULT_NAMESPACE);
if (verifiers.length === 0) {
// attempt to query legacy ff_system verifiers
verifiers = await firefly.getVerifiers('ff_system');
Expand All @@ -61,7 +61,7 @@ export class CommonController {
@OpenAPI({ summary: 'List verifiers (such as Ethereum keys) for local organization' })
async verifierSelf(): Promise<Verifier[]> {
const status = await firefly.getStatus();
const verifiers = await firefly.getVerifiers('default');
const verifiers = await firefly.getVerifiers(DEFAULT_NAMESPACE);
const result: Verifier[] = [];
for (const v of verifiers) {
if (status.org?.id === v.identity) {
Expand Down Expand Up @@ -101,11 +101,13 @@ export class CommonController {
if ("multiparty" in status) {
return {
multiparty: status.multiparty?.enabled,
namespace: DEFAULT_NAMESPACE,
};
} else {
// Assume multiparty mode if `multiparty` key is missing from status
return {
multiparty: true
multiparty: true,
namespace: DEFAULT_NAMESPACE,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions server/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,7 @@ export class DatatypeInterface {
export class FFStatus {
@IsBoolean()
multiparty: boolean;

@IsString()
namespace: string;
}
3 changes: 3 additions & 0 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function App() {
type: '',
id: '',
});
const [namespace, setNamespace] = useState('');
const [tokensDisabled, setTokensDisabled] = useState(false);
const [blockchainPlugin, setBlockchainPlugin] = useState('');
const [tutorialSections, setTutorialSections] = useState<ITutorialSection[]>(
Expand All @@ -66,6 +67,7 @@ function App() {
);
const ffStatus = statusResponse as IFireflyStatus;
setMultiparty(ffStatus.multiparty);
setNamespace(ffStatus.namespace);
if (ffStatus.multiparty === true) {
setTutorialSections(TutorialSections);
fetchCatcher(SDK_PATHS.verifiers)
Expand Down Expand Up @@ -122,6 +124,7 @@ function App() {
blockchainPlugin,
multiparty,
tutorialSections,
namespace,
}}
>
<StyledEngineProvider injectFirst>
Expand Down
7 changes: 7 additions & 0 deletions ui/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import ReconnectingWebSocket from 'reconnecting-websocket';
import { ReactComponent as DiscordLogo } from '../assets/Discord-Logo-White.svg';
import { ResourceUrls } from '../constants/ResourceUrls';
import { EventContext } from '../contexts/EventContext';
import { ApplicationContext } from '../contexts/ApplicationContext';
import { FF_EVENTS } from '../ff_models/eventTypes';
import { DEFAULT_BORDER_RADIUS, DEFAULT_PADDING, FFColors } from '../theme';
import { MenuLogo } from './Logos/MenuLogo';
Expand All @@ -52,6 +53,7 @@ export const Header: React.FC = () => {
const { t } = useTranslation();
const theme = useTheme();
const { addLogToHistory } = useContext(EventContext);
const { namespace } = useContext(ApplicationContext);
const [wsConnected, setWsConnected] = useState<boolean>(false);
const webSocket = useRef<ReconnectingWebSocket | null>(null);
const [isModalOpen, setIsModalOpen] = useState(false);
Expand Down Expand Up @@ -201,6 +203,11 @@ export const Header: React.FC = () => {
onClick={connectToWS}
/>
</Tooltip>
<Grid item paddingLeft={1}>
<Typography>
{t('namespaceX', { namespace: namespace })}
</Typography>
</Grid>
<IconButton
color="inherit"
onClick={() => setIsModalOpen(true)}
Expand Down
1 change: 1 addition & 0 deletions ui/src/contexts/ApplicationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface IApplicationContext {
blockchainPlugin: string;
multiparty: boolean;
tutorialSections: ITutorialSection[];
namespace: string;
}

export const ApplicationContext = createContext({} as IApplicationContext);
1 change: 1 addition & 0 deletions ui/src/interfaces/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface IApiStatus {

export interface IFireflyStatus {
multiparty: boolean;
namespace: string;
}

export interface IBatch {
Expand Down
1 change: 1 addition & 0 deletions ui/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"name": "Name",
"namespaceConfirmed": "Namespace Confirmed",
"namespaceID": "Namespace ID",
"namespaceX": "Namespace: {{namespace}}",
"noAPIsRegisteredWithFireFly": "No APIs Registered with FireFly",
"noBalancesForWallet": "No Balances for Wallet",
"noConnectors": "No Token Connectors",
Expand Down

0 comments on commit 86176f5

Please sign in to comment.