Skip to content

Commit

Permalink
Merge pull request #7 from fabianbormann/feature/network_selector
Browse files Browse the repository at this point in the history
Feature/network selector
  • Loading branch information
fabianbormann authored Apr 12, 2023
2 parents a7a8fee + 458291f commit 2ee778c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 34 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
release: ${{ startsWith(github.ref, 'refs/tags/v') }}

- name: 👀 Compute versions
run: |
echo "PREVIOUS_VERSION=$(perl -ne 'print $1 if /📦 Cardano Node Ui v([^\s]+)/' README.md)" >> $GITHUB_ENV
echo "VERSION=$(echo "${{ github.ref }}" | sed 's/refs\/tags\/v//')" >> $GITHUB_ENV
- name: 📝 Update Readme with Version
run: |
PREVIOUS_VERSION=$(perl -ne 'print $1 if /📦 Cardano Node Ui v([^\s]+)/' README.md)
VERSION=$(echo "${{ github.ref }}" | sed 's/refs\/tags\/v//')
sed -i "s/fabianbormann\/cardano-node-ui\/releases\/download\/v$PREVIOUS_VERSION\/cardano-node-ui-$PREVIOUS_VERSION.dmg/fabianbormann\/cardano-node-ui\/releases\/download\/v$VERSION\/cardano-node-ui-$VERSION.dmg/g" README.md
sed -i "s/fabianbormann\/cardano-node-ui\/releases\/download\/v$PREVIOUS_VERSION\/cardano-node-ui-$PREVIOUS_VERSION.AppImage/fabianbormann\/cardano-node-ui\/releases\/download\/v$VERSION\/cardano-node-ui-$VERSION.AppImage/g" README.md
sed -i "s/fabianbormann\/cardano-node-ui\/releases\/download\/v$PREVIOUS_VERSION\/cardano-node-ui-Setup-$PREVIOUS_VERSION.exe/fabianbormann\/cardano-node-ui\/releases\/download\/v$VERSION\/cardano-node-ui-Setup-$VERSION.exe/g" README.md
sed -i "s/📦 Cardano Node Ui v$VERSION/📦 Cardano Node Ui v${{ github.ref.replace('refs/tags/v', '') }}/g" README.md
sed -i "s/fabianbormann\/cardano-node-ui\/releases\/download\/v${{ env.PREVIOUS_VERSION }}\/cardano-node-ui-${{ env.PREVIOUS_VERSION }}.dmg/fabianbormann\/cardano-node-ui\/releases\/download\/v${{ env.VERSION }}\/cardano-node-ui-${{ env.VERSION }}.dmg/g" README.md
sed -i "s/fabianbormann\/cardano-node-ui\/releases\/download\/v${{ env.PREVIOUS_VERSION }}\/cardano-node-ui-${{ env.PREVIOUS_VERSION }}.AppImage/fabianbormann\/cardano-node-ui\/releases\/download\/v${{ env.VERSION }}\/cardano-node-ui-${{ env.VERSION }}.AppImage/g" README.md
sed -i "s/fabianbormann\/cardano-node-ui\/releases\/download\/v${{ env.PREVIOUS_VERSION }}\/cardano-node-ui-Setup-${{ env.PREVIOUS_VERSION }}.exe/fabianbormann\/cardano-node-ui\/releases\/download\/v${{ env.VERSION }}\/cardano-node-ui-Setup-${{ env.VERSION }}.exe/g" README.md
sed -i "s/📦 Cardano Node Ui v${{ env.VERSION }}/📦 Cardano Node Ui v${{ env.VERSION }}/g" README.md
- name: 📬 Commit Changes
uses: EndBug/add-and-commit@v7
with:
author_name: GitHub Actions
author_email: [email protected]
message: "chore: update README.md with version ${{ github.ref.replace('refs/tags/v', '') }}"
message: 'chore: update README.md with version ${{ env.VERSION }}'
40 changes: 19 additions & 21 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const networks = {
};

const nodeBinaries = {
darwin: 'cardano-node-1.35.5-macos.tar.gz',
win32: 'cardano-node-1.35.5-win64.zip',
linux: 'cardano-node-1.35.5-linux.tar.gz',
darwin: 'cardano-node-1.35.7-macos.tar.gz',
win32: 'cardano-node-1.35.7-win64.zip',
linux: 'cardano-node-1.35.7-linux.tar.gz',
};

const nodeBaseUrl =
Expand Down Expand Up @@ -177,6 +177,8 @@ function createWindow() {
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
minWidth: 760,
minHeight: 500,
title: 'Cardano Node UI',
frame: false,
icon: image,
Expand Down Expand Up @@ -298,24 +300,20 @@ app.whenReady().then(() => {

const getCurrentTip = () => {
const databaseDirectory = path.join(directory, `${network}-db`);
const child = spawn(
path.join(binaryPath, 'cardano-cli'),
[
'query',
'tip',
network === 'mainnet'
? '--mainnet'
: `--testnet-magic ${networks[network].protocolMagic}`,
],
{
env: {
CARDANO_NODE_SOCKET_PATH: path.join(
databaseDirectory,
'node.socket'
),
},
}
);
const args = ['query', 'tip'];

if (network === 'mainnet') {
args.push('--mainnet');
} else {
args.push('--testnet-magic');
args.push(networks[network].protocolMagic);
}

const child = spawn(path.join(binaryPath, 'cardano-cli'), args, {
env: {
CARDANO_NODE_SOCKET_PATH: path.join(databaseDirectory, 'node.socket'),
},
});

child.stdout.on('data', (data) => {
try {
Expand Down
3 changes: 2 additions & 1 deletion public/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ contextBridge.exposeInMainWorld('electron', {
ipcRenderer.removeAllListeners(channel);
},
getDefaultDirectory: () => ipcRenderer.invoke('getDefaultPath'),
startNode: (directory) => ipcRenderer.send('start-node', directory),
startNode: (directory, network) =>
ipcRenderer.send('start-node', directory, network),
});
29 changes: 24 additions & 5 deletions src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
IconButton,
InputAdornment,
InputBase,
MenuItem,
Select,
Snackbar,
useTheme,
} from '@mui/material';
import FolderOpenIcon from '@mui/icons-material/FolderOpen';
import reactStringReplace from 'react-string-replace';
Expand All @@ -23,6 +26,7 @@ const Dashboard = () => {
const [snackbarOpen, setSnackbarOpen] = useState(false);
const [snackbarType, setSnackbarType] = useState<MessageType>('success');
const [snackbarMessage, setSnackbarMessage] = useState('');
const [selectedNetwork, setSelectedNetwork] = useState('mainnet');

const [directory, setDirectory] = useState('');
const [nodeRunning, setNodeRunning] = useState(false);
Expand All @@ -31,6 +35,8 @@ const Dashboard = () => {
{ status: 'idle', message: 'cardano-node-ui:~$', id: -1, timestamp: 0 },
]);

const theme = useTheme();

useEffect(() => {
const getDefaultDirectory: () => Promise<string> = (window as any).electron
?.getDefaultDirectory;
Expand Down Expand Up @@ -97,7 +103,7 @@ const Dashboard = () => {

const startNode = (window as any).electron?.startNode;
if (typeof startNode === 'function') {
startNode(directory);
startNode(directory, selectedNetwork);
setNodeRunning(true);
}
};
Expand Down Expand Up @@ -139,7 +145,7 @@ const Dashboard = () => {
for (const timestamp of timestamps) {
text = [
...text,
<div>
<div key={timestamp} style={{ marginTop: 2, marginBottom: 2 }}>
{reactStringReplace(
messages[timestamp].text,
'#{...}',
Expand Down Expand Up @@ -203,7 +209,7 @@ const Dashboard = () => {
height: '100%',
}}
>
<Grid item>
<Grid item container sx={{ justifyContent: 'center' }}>
<InputBase
sx={{
minWidth: 500,
Expand All @@ -224,7 +230,21 @@ const Dashboard = () => {
</InputAdornment>
}
/>

<Select
sx={{
ml: 1,
background:
selectedNetwork === 'mainnet'
? 'white'
: theme.palette.warning.main,
}}
value={selectedNetwork}
onChange={(event) => setSelectedNetwork(event.target.value)}
>
<MenuItem value="mainnet">Mainnet</MenuItem>
<MenuItem value="preprod">Preprod</MenuItem>
<MenuItem value="preview">Preview</MenuItem>
</Select>
<Button
sx={{ ml: 1, p: 2.5 }}
variant="contained"
Expand Down Expand Up @@ -252,7 +272,6 @@ const Dashboard = () => {
sx={{
background: '#46525D',
color: 'white',
minWidth: 600,
height: 200,
pl: 2,
pr: 2,
Expand Down

0 comments on commit 2ee778c

Please sign in to comment.