Skip to content

Commit

Permalink
Merge pull request #272 from Web3-API/prealpha-dev
Browse files Browse the repository at this point in the history
Prep 0.0.1-prealpha.13
  • Loading branch information
dOrgJelli authored Apr 8, 2021
2 parents 7d96e1f + 93d5bd1 commit 3fdb1f5
Show file tree
Hide file tree
Showing 28 changed files with 320 additions and 516 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Web3API 0.0.1-prealpha.13
## Features
* Improved template projects that are used with the `w3 create ...` CLI command.

# Web3API 0.0.1-prealpha.12
## Bug Fixes
* Added schemas to plugin manifest modules, removing the need for `import_redirects`.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1-prealpha.12
0.0.1-prealpha.13
12 changes: 9 additions & 3 deletions packages/js/client/src/Web3ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from "@web3api/core-js";

export interface ClientConfig<TUri = string> {
redirects: UriRedirect<TUri>[];
redirects?: UriRedirect<TUri>[];
}

export class Web3ApiClient implements Client {
Expand All @@ -36,20 +36,26 @@ export class Web3ApiClient implements Client {
if (config) {
this._config = {
...config,
redirects: sanitizeUriRedirects(config.redirects),
redirects: config.redirects
? sanitizeUriRedirects(config.redirects)
: [],
};
} else {
this._config = {
redirects: [],
};
}

if (!this._config.redirects) {
this._config.redirects = [];
}

// Add all default redirects (IPFS, ETH, ENS)
this._config.redirects.push(...getDefaultRedirects());
}

public redirects(): readonly UriRedirect<Uri>[] {
return this._config.redirects;
return this._config.redirects || [];
}

public async query<
Expand Down
3 changes: 0 additions & 3 deletions packages/js/client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export * from "./Web3ApiClient";
export * from "./createWeb3ApiClient";
export * from "@web3api/core-js";

// TODO: client.sanitizeRedirects() -> iterate through all redirects, make sure we can resolve all of them (will call getImplementations...)
// TODO: client.getImplementations(uri) -> iterate through all known Web3API's and find all implementations
7 changes: 2 additions & 5 deletions packages/js/react/src/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UriRedirect, Web3ApiClient } from "@web3api/client-js";
import { Web3ApiClient, ClientConfig } from "@web3api/client-js";
import React from "react";

type ClientContext = React.Context<Web3ApiClient>
Expand All @@ -14,10 +14,7 @@ interface Web3ApiProviderMap {

export const PROVIDERS: Web3ApiProviderMap = {};

interface Web3ApiProviderProps {
redirects: UriRedirect<string>[];
children: React.ReactNode;
}
interface Web3ApiProviderProps extends ClientConfig { }

export type Web3ApiProviderFC = React.FC<Web3ApiProviderProps>;

Expand Down
1 change: 1 addition & 0 deletions packages/templates/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!.gitignore
3 changes: 3 additions & 0 deletions packages/templates/app/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/react-lottie": "^1.2.5",
"@web3api/client-js": "0.0.1-prealpha.12",
"@web3api/react": "^0.0.1-prealpha.12",
"http-proxy": "1.18.1",
"http-proxy-middleware": "1.0.6",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-lottie": "^1.2.3",
"react-scripts": "3.4.1",
"stream-array": "1.1.2",
"typescript": "4.0.7"
Expand Down
3 changes: 3 additions & 0 deletions packages/templates/app/react/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600&display=swap");
</style>
<meta name="theme-color" content="#000000" />
<meta
name="description"
Expand Down
120 changes: 60 additions & 60 deletions packages/templates/app/react/public/thread.js

Large diffs are not rendered by default.

92 changes: 66 additions & 26 deletions packages/templates/app/react/src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,78 @@
.App {
text-align: center;
.main {
display: flex;
flex-direction: column;
justify-content: center;
height: 100vh;
align-items: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
.main__logo {
max-width: 15rem;
margin-bottom: 5rem;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
.main__heading {
font-size: 45px;
margin-top: 2rem;
font-weight: 700;
margin-bottom: 20px;
color: white;
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
.main__text {
text-align: center;
max-width: 40rem;
color: #529dad;
font-style: italic;
line-height: 1.5;
font-weight: 400;
font-size: 22px;
}

.main__link {
text-decoration: none;
font-size: 22px;
font-weight: 600;
margin-top: 2rem;
color: white;
}

.main__input {
font: inherit;
color: white;
width: 40rem;
border: 1px solid white;
height: 1.1876em;
margin: 2.5rem 0;
display: block;
padding: 1rem;
min-width: 0;
background: none;
box-sizing: content-box;
letter-spacing: inherit;
animation-duration: 10ms;
-webkit-tap-highlight-color: transparent;
}

.App-link {
color: #61dafb;
.main__btn {
font-size: 0.875rem;
color: #60c093;
border: 1px solid #529dad;
padding: 5px 15px;
font-weight: 500;
line-height: 1.75;
min-width: 64px;
cursor: pointer;
border-radius: 4px;
text-transform: uppercase;
background-color: transparent;
transition: background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,
box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,
border 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
.main__btn:hover {
color: #ffffff;
border: solid 1px #529dad;
background-color: #60c093;
}
9 changes: 0 additions & 9 deletions packages/templates/app/react/src/App.test.tsx

This file was deleted.

104 changes: 23 additions & 81 deletions packages/templates/app/react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,88 +1,30 @@
import React from 'react';
import logo from './logo.svg';
import './App.css';
import React from "react";
import Lottie from "react-lottie";
import { Web3ApiProvider } from "@web3api/react";

import { Uri, UriRedirect, Web3ApiClient } from "@web3api/client-js";
import { ensPlugin } from "@web3api/ens-plugin-js";
import { ethereumPlugin } from "@web3api/ethereum-plugin-js";
import { ipfsPlugin } from "@web3api/ipfs-plugin-js";
import { HelloWorld } from "./HelloWorld";
import Web3ApiAnimation from "./lottie/Web3API_Icon_Cycle.json";
import "./App.css";

function App() {
const [contract, setContract] = React.useState<string | undefined>(undefined);
const [client, setClient] = React.useState<Web3ApiClient | undefined>(undefined);
export const App: React.FC = () => {

async function setupClient() {
const ethereum = (window as any).ethereum;
if (ethereum && ethereum.enable) {
await ethereum.enable();
}

const redirects: UriRedirect[] = [
{
from: "w3://ens/ethereum.web3api.eth",
to: ethereumPlugin({ provider: ethereum })
},
{
from: "w3://ens/ipfs.web3api.eth",
to: ipfsPlugin({ provider: "https://ipfs.io/api/v0/" }),
},
{
from: "w3://ens/ens.web3api.eth",
to: ensPlugin({}),
}
];
setClient(new Web3ApiClient({ redirects }));
}

const deployContract = async () => {
if (!client) {
await setupClient();

if (!client) {
return;
}
}

console.log("querying")

const { data, errors } = await client.query({
uri: new Uri("ens/api.simplestorage.eth"),
query: `mutation { deployContract }`
});

console.log(data)
console.log(errors)

if (errors) {
console.error(errors);
}

if (data) {
setContract(
data.deployContract as string
);
}
}
const logoLottieOptions = {
loop: true,
autoplay: true,
animationData: Web3ApiAnimation,
};

return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Web3API: SimpleStorage Demo
</p>
{!contract ?
(<button onClick={deployContract}>
Deploy Contract
</button>) :
<p>SimpleStorage Contract: {contract}</p>
}
<button>
Set Storage
</button>
</header>
<div className="main">
<Web3ApiProvider>
<Lottie
options={logoLottieOptions}
isClickToPauseDisabled={true}
height={"300px"}
width={"300px"}
/>
<HelloWorld />
</Web3ApiProvider>
</div>
);
}

export default App;
};
53 changes: 53 additions & 0 deletions packages/templates/app/react/src/HelloWorld.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from "react";
import { useWeb3ApiQuery } from "@web3api/react";

export const HelloWorld: React.FC = () => {
const [message, setMessage] = React.useState("");

const { execute } = useWeb3ApiQuery({
provider: "helloWorld",
uri: "ens/helloworld.eth",
query: `query {
logMessage(
message: "${message}"
)
}`,
});

// data: deployData,
// loading: loadingDeploy,
// errors: deployContractErrors,
const logMsgHandler = async (): Promise<any> => {
const result = await execute();
console.log(result);
};

const onChangeHandler = (event: any): void => {
setMessage(event?.target.value);
};

return (
<>
<text className="main__heading">Hello world from Web3API!</text>
<text className="main__text">
Try out our Hello World demo by typing anything into
the input below, click the submit and check out your
developer console logs.
</text>
<input
className="main__input"
onChange={(event) => onChangeHandler(event)}
/>
<button className="main__btn" onClick={logMsgHandler}>
Submit
</button>
<a
className="main__link"
href="https://documentation-master.on.fleek.co/"
>
Want to build your own Web3API? Visit our documentation{" "}
<span style={{ color: "blue" }}>here</span>.
</a>
</>
);
}
Loading

0 comments on commit 3fdb1f5

Please sign in to comment.