Skip to content

Commit

Permalink
Deploy new ten gateway frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
zkokelj committed Dec 8, 2023
1 parent d9ead96 commit 460021b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 146 deletions.
21 changes: 20 additions & 1 deletion tools/walletextension/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ FROM system as get-dependencies
# setup container data structure
RUN mkdir -p /home/obscuro/go-obscuro


# Install Node.js and npm (needed for frontend)
RUN apk add --update nodejs npm

# Ensures container layer caching when dependencies are not changed
WORKDIR /home/obscuro/go-obscuro
COPY go.mod .
Expand All @@ -27,7 +31,22 @@ FROM get-dependencies as build-wallet
# make sure the geth network code is available
COPY . /home/obscuro/go-obscuro

# build the contract deployer exec
# Create .env file for frontend
WORKDIR /home/obscuro/go-obscuro/tools/walletextension/frontend
RUN if [ "$TESTNET_TYPE" = "dev-testnet" ]; then \
echo "NEXT_PUBLIC_API_GATEWAY_URL=https://dev-testnet.obscu.ro" > .env; \
elif [ "$TESTNET_TYPE" = "uat-testnet" ]; then \
echo "NEXT_PUBLIC_API_GATEWAY_URL=https://uat-testnet.obscu.ro" > .env; \
elif [ "$TESTNET_TYPE" = "sepolia-testnet" ]; then \
echo "NEXT_PUBLIC_API_GATEWAY_URL=https://testnet.obscu.ro" > .env; \
else \
echo "NEXT_PUBLIC_API_GATEWAY_URL=http://127.0.0.1:3000" > .env; \
fi
# Run npm build for frontend
RUN npm install
RUN npm run build

# build the gateway executable
WORKDIR /home/obscuro/go-obscuro/tools/walletextension/main
RUN --mount=type=cache,target=/root/.cache/go-build \
go build -o ../bin/wallet_extension_linux
Expand Down
14 changes: 3 additions & 11 deletions tools/walletextension/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import (
"github.com/ten-protocol/go-ten/tools/walletextension/common"
)

//go:embed static
//go:embed staticOG
//go:embed all:static
var staticFiles embed.FS

const (
staticDir = "static"
staticDirOG = "staticOG"
staticDir = "static"
)

// Server is a wrapper for the http server
Expand Down Expand Up @@ -67,13 +65,7 @@ func createHTTPServer(address string, routes []Route) *http.Server {
if err != nil {
panic(fmt.Sprintf("could not serve static files. Cause: %s", err))
}
serveMux.Handle(common.PathViewingKeys, http.StripPrefix(common.PathViewingKeys, http.FileServer(http.FS(noPrefixStaticFiles))))

noPrefixStaticFilesOG, err := fs.Sub(staticFiles, staticDirOG)
if err != nil {
panic(fmt.Errorf("could not serve static files. Cause: %w", err).Error())
}
serveMux.Handle(common.PathObscuroGateway, http.StripPrefix(common.PathObscuroGateway, http.FileServer(http.FS(noPrefixStaticFilesOG))))
serveMux.Handle(common.PathObscuroGateway, http.StripPrefix(common.PathObscuroGateway, http.FileServer(http.FS(noPrefixStaticFiles))))

// Creates the actual http server with a ReadHeaderTimeout to avoid Potential Slowloris Attack
server := &http.Server{Addr: address, Handler: serveMux, ReadHeaderTimeout: common.ReaderHeadTimeout}
Expand Down
Binary file added tools/walletextension/api/static/favicon.ico
Binary file not shown.
21 changes: 0 additions & 21 deletions tools/walletextension/api/static/index.html

This file was deleted.

77 changes: 0 additions & 77 deletions tools/walletextension/api/static/javascript.js

This file was deleted.

34 changes: 0 additions & 34 deletions tools/walletextension/api/static/style.css

This file was deleted.

2 changes: 2 additions & 0 deletions tools/walletextension/frontend/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
output: 'export',
distDir: '../api/static'
}

module.exports = nextConfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const MessageContent = (
);

export const NetworkStatus = ({ message = MessageContent }) => {
const [isOnline, setIsOnline] = React.useState(navigator.onLine);
const [isOnline, setIsOnline] = React.useState(true);

React.useEffect(() => {
const setOnlineStatus = () => {
Expand Down
2 changes: 1 addition & 1 deletion tools/walletextension/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func main() {
}()

walletExtensionAddr := fmt.Sprintf("%s:%d", common.Localhost, config.WalletExtensionPortHTTP)
fmt.Printf("💡 Wallet extension started - visit http://%s/viewingkeys/ to generate an ephemeral viewing key.\n", walletExtensionAddr)
fmt.Printf("💡 Wallet extension started") // Some tests rely on seeing this message. Removed in next PR.
fmt.Printf("💡 Obscuro Gateway started - visit http://%s to use it.\n", walletExtensionAddr)

select {}
Expand Down

0 comments on commit 460021b

Please sign in to comment.