-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
55,692 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,35 @@ | ||
# Cross-chain Swaps using the Swing API | ||
# Cross-chain Swaps using the Swing API in Next.js | ||
|
||
The Cross-chain Swap feature is used for sending and signing an API transaction with Metamask, Keplr, Ton, and MultiversX wallets. | ||
|
||
|
||
## Demo | ||
|
||
|
||
## Getting started | ||
|
||
To get started with this template, first install the npm dependencies: | ||
|
||
```bash | ||
yarn install | ||
``` | ||
|
||
Next, run the development server: | ||
|
||
```bash | ||
Copy .env.example variables to your new .env at the same directoty | ||
``` | ||
|
||
```bash | ||
yarn start | ||
``` | ||
|
||
Finally, open [http://localhost:3004](http://localhost:3004) in your browser to view the website. | ||
|
||
## Swing integration | ||
|
||
Visit [@swing.xyz/api](https://developers.swing.xyz/reference/api) find helpful API guides and references to integrate Swing API directly into your dApp, web or mobile application. | ||
|
||
## Customizing | ||
|
||
You can start editing this template by modifying the files in the `/src` folder. The site will auto-update as you edit these files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
Oops, something went wrong.