Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions examples/swap-api-webpack/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PORT=3004
GENERATE_SOURCEMAP=false
DATAHUB_API_KEY=
RPC_URL=https://cosmos-mainnet-rpc.allthatnode.com:26657
25 changes: 25 additions & 0 deletions examples/swap-api-webpack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
.env
/.yarn
20 changes: 20 additions & 0 deletions examples/swap-api-webpack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

The Cross-chain Swap feature is used for sending and signing an API transaction with Metamask, Keplr, Ton, and MultiversX wallets.

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3004](http://localhost:3004) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.


## Swing integration

The [@swing.xyz/api](https://developers.swing.xyz/reference/api) Here you will find helpful API guides and references to integrate Swing API directly into your dApp, web or mobile application.

29 changes: 29 additions & 0 deletions examples/swap-api-webpack/config-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require("dotenv").config()
const webpack = require("webpack")

module.exports = function override(config, env) {
config.plugins.push(
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
new webpack.EnvironmentPlugin(["RPC_URL"]),
)
config.module.rules.push({
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
})
config.resolve.fallback = {
buffer: false,
crypto: false,
events: false,
path: false,
stream: false,
fs: false,
string_decoder: false,
os: false,
url: false,
}
return config
}
62 changes: 62 additions & 0 deletions examples/swap-api-webpack/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
)

var hostname string
var port int

func main() {
// flags declaration using flag package
// flag.StringVar(&hostname, "H", "https://rpc-cosmoshub.keplr.app", "Specify hostname")
flag.StringVar(&hostname, "H", "https://rpc.cosmos.network", "Specify hostname")
flag.IntVar(&port, "p", 8081, "Specify port")

flag.Parse() // after declaring flags we
http.HandleFunc("/", serveCorsProxy)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
}

// Serve a reverse proxy for a given url
func serveCorsProxy(res http.ResponseWriter, req *http.Request) {
proxyRequest, err := http.NewRequest(req.Method, hostname, req.Body)
proxyRequest.URL.Path = req.URL.Path
proxyRequest.URL.RawQuery = req.URL.RawQuery
if err != nil {
fmt.Printf("create request error: %v", err)
return
}
response, err := http.DefaultClient.Do(proxyRequest)
if err != nil {
fmt.Printf("proxy request error: %v", err)
return
}
setHeaders(response, &res)
body, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("response read error: %v", err)
return
}
fmt.Printf("Running...")
res.WriteHeader(response.StatusCode)
_, _ = res.Write(body)
}

func setHeaders(src *http.Response, dest *http.ResponseWriter) {
header := (*dest).Header()
for name, values := range (*src).Header {
for _, value := range values {
header.Set(name, value)
}
}
header.Set("access-control-allow-headers", "Accept,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With")
header.Set("access-control-allow-methods", "GET, POST, OPTIONS")
header.Set("access-control-allow-origin", "http://localhost:3001")
header.Set("access-control-expose-headers", "Content-Length,Content-Range")
header.Set("access-control-max-age", "1728000")
}
Loading
Loading