3
js/ui/.gitignore
vendored
Normal file
3
js/ui/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
public/build/bundle.*
|
||||
1
js/ui/.vscode/extensions.json
vendored
Normal file
1
js/ui/.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"recommendations": ["svelte.svelte-vscode"]}
|
||||
64
js/ui/README.md
Normal file
64
js/ui/README.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# svelte app
|
||||
|
||||
This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template-webpack.
|
||||
|
||||
To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit):
|
||||
|
||||
```bash
|
||||
npx degit sveltejs/template-webpack svelte-app
|
||||
cd svelte-app
|
||||
```
|
||||
|
||||
*Note that you will need to have [Node.js](https://nodejs.org) installed.*
|
||||
|
||||
|
||||
## Get started
|
||||
|
||||
Install the dependencies...
|
||||
|
||||
```bash
|
||||
cd svelte-app
|
||||
npm install
|
||||
```
|
||||
|
||||
...then start webpack:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Navigate to [localhost:8080](http://localhost:8080). You should see your app running. Edit a component file in `src`, save it, and the page should reload with your changes.
|
||||
|
||||
|
||||
## Deploying to the web
|
||||
|
||||
### With [now](https://zeit.co/now)
|
||||
|
||||
Install `now` if you haven't already:
|
||||
|
||||
```bash
|
||||
npm install -g now
|
||||
```
|
||||
|
||||
Then, from within your project folder:
|
||||
|
||||
```bash
|
||||
now
|
||||
```
|
||||
|
||||
As an alternative, use the [Now desktop client](https://zeit.co/download) and simply drag the unzipped project folder to the taskbar icon.
|
||||
|
||||
### With [surge](https://surge.sh/)
|
||||
|
||||
Install `surge` if you haven't already:
|
||||
|
||||
```bash
|
||||
npm install -g surge
|
||||
```
|
||||
|
||||
Then, from within your project folder:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
surge public
|
||||
```
|
||||
23436
js/ui/package-lock.json
generated
Normal file
23436
js/ui/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
43
js/ui/package.json
Normal file
43
js/ui/package.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "svelte-app",
|
||||
"version": "1.0.0",
|
||||
"devDependencies": {
|
||||
"@tsconfig/svelte": "^1.0.10",
|
||||
"@types/node": "^14.11.1",
|
||||
"assert": "^2.0.0",
|
||||
"buffer": "^6.0.3",
|
||||
"cross-env": "^7.0.3",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"css-loader": "^5.0.1",
|
||||
"dotenv-webpack": "^7.0.3",
|
||||
"https-browserify": "^1.0.0",
|
||||
"mini-css-extract-plugin": "^1.3.4",
|
||||
"os-browserify": "^0.3.0",
|
||||
"process": "^0.11.10",
|
||||
"stream-browserify": "^3.0.0",
|
||||
"stream-http": "^3.2.0",
|
||||
"svelte": "^3.31.2",
|
||||
"svelte-check": "^1.0.46",
|
||||
"svelte-loader": "^3.0.0",
|
||||
"svelte-preprocess": "^4.3.0",
|
||||
"ts-loader": "^8.0.4",
|
||||
"tslib": "^2.0.1",
|
||||
"typescript": "^4.0.3",
|
||||
"webpack": "^5.16.0",
|
||||
"webpack-cli": "^4.4.0",
|
||||
"webpack-dev-server": "^3.11.2"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "cross-env NODE_ENV=production webpack",
|
||||
"dev": "webpack serve --content-base public",
|
||||
"validate": "svelte-check"
|
||||
},
|
||||
"dependencies": {
|
||||
"@portis/web3": "^4.0.6",
|
||||
"@spruceid/siwe-web3modal": "^0.1.5",
|
||||
"@toruslabs/torus-embed": "^1.18.3",
|
||||
"@walletconnect/web3-provider": "^1.6.6",
|
||||
"fortmatic": "^2.2.1",
|
||||
"walletlink": "^2.2.8"
|
||||
}
|
||||
}
|
||||
118
js/ui/src/App.svelte
Normal file
118
js/ui/src/App.svelte
Normal file
@@ -0,0 +1,118 @@
|
||||
<script lang="ts">
|
||||
import Portis from "@portis/web3";
|
||||
import { Client, SiweSession } from "@spruceid/siwe-web3modal";
|
||||
import Torus from "@toruslabs/torus-embed";
|
||||
import WalletConnectProvider from "@walletconnect/web3-provider";
|
||||
import Fortmatic from "fortmatic";
|
||||
import WalletLink from "walletlink";
|
||||
|
||||
// TODO: REMOVE DEFAULTS:
|
||||
// main.ts will parse the params from the server
|
||||
export let domain: string;
|
||||
export let nonce: string;
|
||||
export let redirect: string;
|
||||
export let state: string;
|
||||
export let oidc_nonce: string;
|
||||
|
||||
let uri: string = window.location.href.split("?")[0];
|
||||
|
||||
// Could be exposed in the future.
|
||||
export let useENS: boolean = true;
|
||||
|
||||
$: status = "Not Logged In";
|
||||
|
||||
let client = new Client({
|
||||
session: {
|
||||
domain,
|
||||
uri,
|
||||
useENS,
|
||||
version: "1",
|
||||
// TODO: Vet this as the default statement.
|
||||
statement: "Sign-In With Ethereum OpenID-Connect",
|
||||
},
|
||||
modal: {
|
||||
theme: "dark",
|
||||
providerOptions: {
|
||||
walletconnect: {
|
||||
package: WalletConnectProvider,
|
||||
options: {
|
||||
infuraId: process.env.INFURA_ID,
|
||||
pollingInterval: 100000,
|
||||
},
|
||||
},
|
||||
torus: {
|
||||
package: Torus,
|
||||
},
|
||||
portis: {
|
||||
package: Portis,
|
||||
options: {
|
||||
id: process.env.PORTIS_ID,
|
||||
},
|
||||
},
|
||||
fortmatic: {
|
||||
package: Fortmatic,
|
||||
options: {
|
||||
key: process.env.FORTMATIC_KEY,
|
||||
},
|
||||
},
|
||||
"custom-coinbase": {
|
||||
display: {
|
||||
logo: "img/coinbase.svg",
|
||||
name: "Coinbase",
|
||||
description: "Scan with WalletLink to connect",
|
||||
},
|
||||
options: {
|
||||
appName: "Sign-In with Ethereum",
|
||||
networkUrl: `https://mainnet.infura.io/v3/${process.env.INFURA_ID}`,
|
||||
chainId: 1,
|
||||
darkMode: false,
|
||||
},
|
||||
package: WalletLink,
|
||||
connector: async (_, options) => {
|
||||
const { appName, networkUrl, chainId, darkMode } =
|
||||
options;
|
||||
const walletLink = new WalletLink({
|
||||
appName,
|
||||
darkMode,
|
||||
});
|
||||
const provider = walletLink.makeWeb3Provider(
|
||||
networkUrl,
|
||||
chainId
|
||||
);
|
||||
await provider.enable();
|
||||
return provider;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
let oidc_nonce_param = "";
|
||||
if (oidc_nonce != "") {
|
||||
oidc_nonce_param = `&oidc_nonce=${oidc_nonce}`;
|
||||
}
|
||||
client.on("signIn", (result) => {
|
||||
console.log(result);
|
||||
window.location.replace(`/sign_in?redirect_uri=${encodeURI(redirect)}&state=${encodeURI(state)}${encodeURI(oidc_nonce_param)}`);
|
||||
});
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<div>
|
||||
<h2>Sign-In With Ethereum</h2>
|
||||
<p>{status}</p>
|
||||
<!-- TODO: Add copy / info about who is requesting here. -->
|
||||
<button
|
||||
on:click={() => {
|
||||
client.signIn(nonce).catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
}}
|
||||
>
|
||||
Sign In
|
||||
</button>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
63
js/ui/src/global.css
Normal file
63
js/ui/src/global.css
Normal file
@@ -0,0 +1,63 @@
|
||||
html, body {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
color: #333;
|
||||
margin: 0;
|
||||
padding: 8px;
|
||||
box-sizing: border-box;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
||||
}
|
||||
|
||||
a {
|
||||
color: rgb(0,100,200);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: rgb(0,80,160);
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
}
|
||||
|
||||
input, button, select, textarea {
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
-webkit-padding: 0.4em 0;
|
||||
padding: 0.4em;
|
||||
margin: 0 0 0.5em 0;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
input:disabled {
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
button {
|
||||
color: #333;
|
||||
background-color: #f4f4f4;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
button:not(:disabled):active {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
button:focus {
|
||||
border-color: #666;
|
||||
}
|
||||
18
js/ui/src/main.ts
Normal file
18
js/ui/src/main.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import './global.css';
|
||||
|
||||
import App from './App.svelte';
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
|
||||
const app = new App({
|
||||
target: document.body,
|
||||
props: {
|
||||
domain: params.get('domain'),
|
||||
nonce: params.get('nonce'),
|
||||
redirect: params.get('redirect_uri'),
|
||||
state: params.get('state'),
|
||||
oidc_nonce: params.get('oidc_nonce')
|
||||
}
|
||||
});
|
||||
|
||||
export default app;
|
||||
5
js/ui/tsconfig.json
Normal file
5
js/ui/tsconfig.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "@tsconfig/svelte/tsconfig.json",
|
||||
"include": ["src/**/*", "src/node_modules/**/*"],
|
||||
"exclude": ["node_modules/*", "__sapper__/*", "static/*"]
|
||||
}
|
||||
91
js/ui/webpack.config.js
Normal file
91
js/ui/webpack.config.js
Normal file
@@ -0,0 +1,91 @@
|
||||
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
|
||||
const path = require('path');
|
||||
const sveltePreprocess = require('svelte-preprocess');
|
||||
const Dotenv = require('dotenv-webpack');
|
||||
const webpack = require('webpack');
|
||||
|
||||
const mode = process.env.NODE_ENV || 'development';
|
||||
const prod = mode === 'production';
|
||||
|
||||
module.exports = {
|
||||
entry: {
|
||||
'build/bundle': ['./src/main.ts']
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
svelte: path.dirname(require.resolve('svelte/package.json'))
|
||||
},
|
||||
extensions: ['.mjs', '.js', '.ts', '.svelte'],
|
||||
mainFields: ['svelte', 'browser', 'module', 'main'],
|
||||
fallback: {
|
||||
assert: require.resolve("assert"),
|
||||
buffer: require.resolve('buffer/'),
|
||||
crypto: require.resolve('crypto-browserify'),
|
||||
fs: false,
|
||||
http: require.resolve('stream-http'),
|
||||
https: require.resolve('https-browserify'),
|
||||
os: require.resolve('os-browserify/browser'),
|
||||
path: false,
|
||||
process: require.resolve('process/browser'),
|
||||
stream: require.resolve('stream-browserify'),
|
||||
// util: false,
|
||||
}
|
||||
},
|
||||
output: {
|
||||
path: path.join(__dirname, '../../static'),
|
||||
filename: '[name].js',
|
||||
chunkFilename: '[name].[id].js'
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts$/,
|
||||
loader: 'ts-loader',
|
||||
exclude: /node_modules/
|
||||
},
|
||||
{
|
||||
test: /\.svelte$/,
|
||||
use: {
|
||||
loader: 'svelte-loader',
|
||||
options: {
|
||||
compilerOptions: {
|
||||
dev: !prod
|
||||
},
|
||||
emitCss: prod,
|
||||
hotReload: !prod,
|
||||
preprocess: sveltePreprocess({ sourceMap: !prod })
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
MiniCssExtractPlugin.loader,
|
||||
'css-loader'
|
||||
]
|
||||
},
|
||||
{
|
||||
// required to prevent errors from Svelte on Webpack 5+
|
||||
test: /node_modules\/svelte\/.*\.mjs$/,
|
||||
resolve: {
|
||||
fullySpecified: false
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
mode,
|
||||
plugins: [
|
||||
new webpack.ProvidePlugin({
|
||||
Buffer: ["buffer", "Buffer"],
|
||||
process: path.resolve(path.join(__dirname, "node_modules/process/browser")),
|
||||
}),
|
||||
new MiniCssExtractPlugin({
|
||||
filename: '[name].css'
|
||||
}),
|
||||
new Dotenv(),
|
||||
],
|
||||
devtool: prod ? false : 'source-map',
|
||||
devServer: {
|
||||
hot: true
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user