Skip to content

Commit

Permalink
feat: update public deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Sep 25, 2023
1 parent 77bb2e1 commit 01424a6
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 65 deletions.
38 changes: 30 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ jobs:
tag: ${{ steps.setup_tags.outputs.tag }}
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c

- name: Setup tags for docker image
id: setup_tags
run: echo "tag=sha-$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Use Node.js
uses: actions/setup-node@7c29869aec4da703a571b27bcd84d4f15af0b56e
with:
Expand All @@ -128,24 +128,46 @@ jobs:
- name: Dump context
uses: crazy-max/ghaction-dump-context@v2

setup-build-args:
runs-on: ubuntu-latest
name: Setup build argument values for docker
outputs:
network: ${{ steps.network_name_step.outputs.network_name }}
is_public: ${{ steps.network_name_step.outputs.is_public }}
steps:
- name: Dump context
uses: crazy-max/ghaction-dump-context@v2
- name: Info
run: |
echo "This is triggered by: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
- name: Define network name
id: network_name_step
run: |
if [ "${{ github.event_name}}" = 'release' ] && [${{!github.event.release.prerelease}}] || [ ${{github.event.inputs.ENVIRONMENT_NAME}} = 'Stokenet' ] && [ ${{github.event_name }} = 'workflow_dispatch' ]; then
echo "network_name="${{ github.event.inputs.ENVIRONMENT_NAME }}", is_public="true"" >> $GITHUB_OUTPUT
fi
push-docker-image:
name: (PRIVATE) Docker AMD
needs:
- build
uses: radixdlt/public-iac-resuable-artifacts/.github/workflows/docker-build.yml@main
with:
runs_on: ubuntu-latest
image_registry: "docker.io"
image_organization: "radixdlt"
image_name: "private-radix-dapp-toolkit"
image_registry: 'docker.io'
image_organization: 'radixdlt'
image_name: 'private-radix-dapp-toolkit'
tag: ${{ needs.build.outputs.tag }}
tags: |
type=semver,pattern={{version}}
context: "./"
dockerfile: "./Dockerfile"
platforms: "linux/amd64"
context: './'
dockerfile: './Dockerfile'
platforms: 'linux/amd64'
scan_image: true
snyk_target_ref: ${{ github.ref_name }}
build-args: |
NETWORK_NAME=${{needs.setup-build-args.outputs.network}}
IS_PUBLIC=${{needs.setup-build-args.outputs.is_public}}
snyk-monitor:
runs-on: ubuntu-latest
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ COPY package.json ./
COPY package-lock.json ./
RUN npm install

ARG NETWORK_NAME
ENV VITE_NETWORK_NAME=$NETWORK_NAME

ARG IS_PUBLIC
ENV VITE_IS_PUBLIC=$IS_PUBLIC

RUN echo "The VITE_IS_PUBLIC variable value is $VITE_IS_PUBLIC"
RUN echo "The VITE_NETWORK_NAME variable value is $VITE_NETWORK_NAME"

# Copy rest of the files
COPY . .

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
set -e

# Build the docker image
docker build -t sandbox:latest .
docker build -t sandbox:latest . --build-arg NETWORK_NAME=Stokenet --build-arg IS_PUBLIC=false
2 changes: 2 additions & 0 deletions examples/.env.public
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_NETWORK_NAME=Stokenet
VITE_IS_PUBLIC=true
4 changes: 4 additions & 0 deletions examples/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// <reference types="vite/client" />

export const IS_PUBLIC = import.meta.env.VITE_IS_PUBLIC === 'true'
export const ENV_NETWORK_NAME = import.meta.env.VITE_NETWORK_NAME
11 changes: 9 additions & 2 deletions examples/helpers/get-network-id.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { RadixNetwork } from '@radixdlt/babylon-gateway-api-sdk'
import {
RadixNetwork,
RadixNetworkConfig,
} from '@radixdlt/babylon-gateway-api-sdk'
import { ENV_NETWORK_NAME } from '../config'

export const DEFAULT_NETWORK_ID = RadixNetwork.RCnetV3.toString()
const networkId = RadixNetworkConfig?.[ENV_NETWORK_NAME]?.networkId

export const DEFAULT_NETWORK_ID =
String(networkId) || RadixNetwork.Stokenet.toString()

export const getNetworkId = () => {
const urlParams = new URLSearchParams(window.location.search)
Expand Down
34 changes: 24 additions & 10 deletions examples/layouts/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Select from '@mui/joy/Select'
import Option from '@mui/joy/Option'
import { setNetworkId, useNetworkId } from '../network/state'
import { RadixNetworkConfig } from '@radixdlt/babylon-gateway-api-sdk'
import { IS_PUBLIC } from '../config'

declare global {
namespace JSX {
Expand Down Expand Up @@ -50,12 +51,14 @@ export const Header = ({
>
<MenuIcon />
</IconButton>
<img
src={radixLogo}
className="logo"
style={{ maxHeight: '50px' }}
alt="Radix logo"
/>
<a href="/">
<img
src={radixLogo}
className="logo"
style={{ maxHeight: '50px' }}
alt="Radix logo"
/>
</a>
</Box>

<Box
Expand All @@ -73,11 +76,22 @@ export const Header = ({
setNetworkId(value as number)
}}
>
{Object.values(RadixNetworkConfig).map(
({ networkId, networkName }) => (
<Option key={networkName} value={networkId}>
{networkName} ({networkId})
{IS_PUBLIC ? (
<>
<Option key="Mainnet" value={1}>
Mainnet ({1})
</Option>
<Option key="Stokenet" value={2}>
Stokenet ({2})
</Option>
</>
) : (
Object.values(RadixNetworkConfig).map(
({ networkId, networkName }) => (
<Option key={networkName} value={networkId}>
{networkName} ({networkId})
</Option>
)
)
)}
</Select>
Expand Down
54 changes: 34 additions & 20 deletions examples/layouts/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ListItemButton from '@mui/joy/ListItemButton'
import ListItemContent from '@mui/joy/ListItemContent'
import KeyboardArrowDownRoundedIcon from '@mui/icons-material/KeyboardArrowDownRounded'
import { NavLink } from 'react-router-dom'
import { IS_PUBLIC } from '../config'

export const Sidebar = () => (
<List size="sm" sx={{ '--ListItem-radius': '8px', '--List-gap': '4px' }}>
Expand All @@ -29,39 +30,52 @@ export const Sidebar = () => (
}}
>
{[
{ path: 'data-request', label: 'Data Requests' },
{ path: 'one-time-data-request', label: 'One Time Data Requests' },
{ path: 'create-token', label: 'Create Token' },
{ path: 'pools', label: 'Pools' },
{ path: 'standard-metadata', label: 'Standard Metadata' },
{ path: 'data-request', label: 'Data Requests', hidePublic: false },
{
path: 'one-time-data-request',
label: 'One Time Data Requests',
hidePublic: false,
},
{ path: 'create-token', label: 'Create Token', hidePublic: true },
{ path: 'pools', label: 'Pools', hidePublic: true },
{
path: 'standard-metadata',
label: 'Standard Metadata',
hidePublic: true,
},
{
path: 'send-transaction',
label: 'Send Transaction',
hidePublic: true,
},
{
path: 'rola',
label: 'ROLA',
hidePublic: true,
},
{
path: 'integration-tests',
label: 'Integration Tests',
hidePublic: true,
},

{ path: 'settings', label: 'Settings' },
].map((item) => (
<NavLink key={item.path} to={item.path}>
{({ isActive }) => (
<ListItem>
<ListItemButton
variant={isActive ? 'soft' : 'plain'}
color="primary"
>
<ListItemContent>{item.label}</ListItemContent>
</ListItemButton>
</ListItem>
)}
</NavLink>
))}
{ path: 'settings', label: 'Settings', hidePublic: false },
]
.filter((item) => !item.hidePublic || !IS_PUBLIC)
.map((item) => (
<NavLink key={item.path} to={item.path}>
{({ isActive }) => (
<ListItem>
<ListItemButton
variant={isActive ? 'soft' : 'plain'}
color="primary"
>
<ListItemContent>{item.label}</ListItemContent>
</ListItemButton>
</ListItem>
)}
</NavLink>
))}
</List>
</ListItem>
</List>
Expand Down
3 changes: 2 additions & 1 deletion examples/network/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
RadixNetwork,
RadixNetworkConfigById,
} from '@radixdlt/babylon-gateway-api-sdk'
import { DEFAULT_NETWORK_ID } from '../helpers/get-network-id'

export const bootstrapNetwork = (networkId: number) => {
const gatewayApi = GatewayApiClient.initialize({
Expand Down Expand Up @@ -39,7 +40,7 @@ const getNetworkIdDefault = () => {
const networkId = parseInt(
urlParams.get('networkId') ||
localStorage.getItem('networkId') ||
RadixNetwork.Stokenet.toString(),
DEFAULT_NETWORK_ID,
10
)
return networkId
Expand Down
22 changes: 20 additions & 2 deletions examples/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,67 @@ import { RolaPage } from './rola/RolaPage'
import { OneTimeDataRequestsPage } from './one-time-data-request/OneTimeDataRequestsPage'
import { PoolsPage } from './pools/PoolsPage'
import { StandardMetadataPage } from './standard-metadata/StandardMetadataPage'
import { IS_PUBLIC } from './config'

export const router = createBrowserRouter([
{
path: '/',
element: <Page />,
children: [
{ index: true, element: <Navigate to="/data-request" replace /> },
{
index: true,
element: <Navigate to="/data-request" replace />,
hidePublic: false,
},
{
path: 'data-request',
element: <DataRequestsPage />,
hidePublic: false,
},
{
path: 'one-time-data-request',
element: <OneTimeDataRequestsPage />,
hidePublic: false,
},
{
path: 'create-token',
element: <CreateTokenPage />,
hidePublic: true,
},
{
path: 'integration-tests',
element: <IntegrationTestsPage />,
hidePublic: true,
},
{
path: 'standard-metadata',
element: <StandardMetadataPage />,
hidePublic: true,
},
{
path: 'send-transaction',
element: <SendTransactionPage />,
hidePublic: true,
},
{
path: 'pools',
element: <PoolsPage />,
hidePublic: true,
},
{
path: 'settings',
element: <SettingsPage />,
hidePublic: false,
},
{
path: 'rola',
element: <RolaPage />,
hidePublic: true,
},
],
]
.filter((route) => {
return !IS_PUBLIC || !route.hidePublic
})
.map(({ path, element }) => ({ path, element })),
},
])
Loading

0 comments on commit 01424a6

Please sign in to comment.