Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making dapp work on GHCS #47

Merged
merged 30 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4e40c13
public-ports-fix-hostname
amessbee Jul 5, 2024
7ecdcac
Update set.hostname.sh
amessbee Jul 5, 2024
a598cc4
fix: Updating hostname script to accomodate localhost case
amessbee Jul 5, 2024
3ffdb93
fix: hostname script works on localhost
amessbee Jul 5, 2024
6725059
Add devcontainer.json with public ports
toliaqat Jul 6, 2024
fcc492c
Update App.tsx hostname placeholder
amessbee Jul 6, 2024
1f80eab
feat: nvm command in .devcontainer
amessbee Jul 7, 2024
af16635
fix: node version
amessbee Jul 7, 2024
c85bab1
fix: nvm not working in .devcontainer so remving for now
amessbee Jul 7, 2024
cbc1754
feat: Hostname Update with ENV Only - Removed script
amessbee Jul 8, 2024
611e29d
chore: make the api and rpc endpoints dynamic
rabi-siddique Jul 8, 2024
20b9b0e
chore: update dev script in package.json
rabi-siddique Jul 8, 2024
ea3e985
chore: use node version 18.20 for the dev container
rabi-siddique Jul 8, 2024
dd791bc
Update App.tsx hostname placeholder
amessbee Jul 9, 2024
f7efe5d
fix: (probably temporary) added cors header in requests
amessbee Jul 12, 2024
6eba185
fix: comment out ports visibility command in devcontainer
amessbee Jul 18, 2024
813a518
chore: use env for codespace domain instead of hardcoded string
amessbee Jul 18, 2024
b56db1f
feat: alternate solution for CORS with GH-token
amessbee Jul 18, 2024
0103bcb
fix: env variable for GH token
amessbee Jul 18, 2024
be3f772
fix: devcontainer for ports
amessbee Jul 18, 2024
de4dc06
fix: add docker to features
amessbee Jul 18, 2024
d7b10ad
fix: port opening
amessbee Jul 18, 2024
c89fb32
fix: add gh CLI to features
amessbee Jul 18, 2024
3eeb173
fix: revert to access-control in header
amessbee Jul 18, 2024
3392cca
chore: delete setup not needed anymore
amessbee Jul 18, 2024
7fd9e20
fix: export GHCS domain name
amessbee Jul 18, 2024
a467f84
chore: clean devcontainer file
amessbee Jul 18, 2024
f0749ab
chore: yarn install in postStartCommand
amessbee Jul 18, 2024
9047c52
chore: readme for ghcs
amessbee Jul 18, 2024
fdfe3e7
fix: readme links
amessbee Jul 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node
{
"name": "Node.js",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-18-bookworm",

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [5173, 1317, 26657, 26656],
"portsAttributes": {
"5173": {
"label": "UI",
"onAutoForward": "openBrowser"
},
"1317": {
"label": "API",
"onAutoForward": "silent"
},
"26657": {
"label": "RPC",
"onAutoForward": "silent"
},
"26656": {
"label": "P2P",
"onAutoForward": "silent"
}
},
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "bash /workspaces/dapp-agoric-basics/make_ports_public.sh 26657 5173 1317",
"postStartCommand": "yarn install",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
}
}
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Agoric Dapp Starter: Agoric Basics

This is a basic Agoric Dapp that contains three smart contracts `postal-service`, `sell-concert-tickets`, and `swaparoo` demonstrating different scenarios which can be implemented easily using Agoric SDK. There is also a UI for `sell-concert-tickets` contract that a user can use to buy three different types of concert tickets and pay through a wallet extension in the browser.
The following instrucions provide a guide to setup an environment to try `dapp-agoric-basics` on your local machine. If you want to try it in cloud environment without any installations or downloads, you can [try it in github codespaces](#instructions-to-run-dapp-agoric-basic-in-ghcs).

## Getting started

Expand Down Expand Up @@ -29,5 +30,20 @@ To perform unit tests:
To perform end to end test
-run the command `yarn test:e2e` in the root directory.

## Instructions to run `dapp-agoric-basic` in GHCS

Here are the step-by-step instructions to run/work on `dapp-agoric-basic` in github codespaces:

1. Go to repo here: [https://github.com/Agoric/dapp-agoric-basics/](https://github.com/Agoric/dapp-agoric-basics/)
2. Click on ![Green `<> Code` button](https://docs.github.com/assets/cb-13128/mw-1440/images/help/repository/code-button.webp)
3. Click on `Codespaces` tab and create a new Codespace. If you are already using Codespaces on current repo then click the "+" button on top right of the `Codespaces` tab to create a new one.
4. You should see a VSCode environment load in your browser followed by a setup. This should take a few minutes.
5. Once it's done do `yarn install` in the terminal.
6. Do `yarn start:docker` followed by `yarn docker:logs` - kill it after you see `begin`/`commit`.
7. Do `yarn start:contract`.
8. Do `yarn start:ui` - a pop-up should appear in bottom right. Click open in browser if needed.
9. DApp should be load in your browser.
10. Connect your Wallet and interact with DApp as usual.

## Contributing
See [CONTRIBUTING](./CONTRIBUTING.md) for more on contributions.
4 changes: 3 additions & 1 deletion contract/tools/ui-kit-goals/makeHttpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const filterBadStatus = res => {
* @returns {import('@cosmjs/tendermint-rpc').RpcClient}
*/
export const makeHttpClient = (url, fetch) => {
const headers = {}; // XXX needed?
const headers = { 'Access-Control-Allow-Origin': '*'
}; // XXX needed?

// based on cosmjs 0.30.1:
// https://github.com/cosmos/cosmjs/blob/33271bc51cdc865cadb647a1b7ab55d873637f39/packages/tendermint-rpc/src/rpcclients/http.ts#L37
Expand Down Expand Up @@ -80,6 +81,7 @@ export const makeAPI = (apiAddress, { fetch }) => {
keepalive: true,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
...options.headers,
},
};
Expand Down
19 changes: 19 additions & 0 deletions make_ports_public.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -x

# Function to change port visibility to public
change_port_visibility() {
local port=$1
gh codespace ports visibility $port:public -c $CODESPACE_NAME
}

# Check if at least one port is provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <port1> [port2 ... portN]"
exit 1
fi

# Loop through each provided port and change its visibility to public
for port in "$@"; do
change_port_visibility $port
done
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"docker:make": "cd contract; docker compose exec agd make -C /workspace/contract",
"make:help": "make -C contract list",
"start:contract": "cd contract && yarn start",
"start:ui": "cd ui && yarn dev",
"start:ui": "export VITE_HOSTNAME=$CODESPACE_NAME && export VITE_GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN=$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN && cd ui && yarn dev",
"lint": "yarn workspaces run lint",
"lint:fix": "yarn workspaces run lint:fix",
"test": "yarn workspaces run test",
Expand Down
14 changes: 12 additions & 2 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import '@agoric/react-components/dist/style.css';

function App() {
const { themeClass } = useTheme();
let REST_HOSTNAME = 'http://localhost:1317';
let RPC_HOSTNAME = 'http://localhost:26657';

const codeSpaceHostName = import.meta.env.VITE_HOSTNAME;
const codeSpaceDomain = import.meta.env.VITE_GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN;

if (codeSpaceHostName) {
REST_HOSTNAME = `https://${codeSpaceHostName}-1317.${codeSpaceDomain}`;
RPC_HOSTNAME = `https://${codeSpaceHostName}-26657.${codeSpaceDomain}`;
}

return (
<ThemeProvider>
Expand All @@ -22,8 +32,8 @@ function App() {
iconUrl: 'agoric.svg', // Optional icon for dropdown display
},
apis: {
rest: ['http://localhost:1317'],
rpc: ['http://localhost:26657'],
rest: [REST_HOSTNAME],
rpc: [RPC_HOSTNAME],
},
},
]}
Expand Down