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

feat: base interface implementation for react package #61

Merged
merged 51 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
629e994
feat: base interface implementation for react package
wainola Jan 22, 2024
8037690
Update packages/widget/src/widget.ts
wainola Jan 24, 2024
492eae4
chore: pr review and small update to interface
wainola Jan 24, 2024
83baf6a
feat: updated interfaces for react package
wainola Jan 25, 2024
196c82d
chore: merge with main
wainola Jan 25, 2024
886150d
chore: remove unused interface
wainola Jan 25, 2024
e4318a1
Update packages/widget/src/interfaces/index.ts
wainola Jan 29, 2024
f2f4683
Update packages/widget/src/interfaces/index.ts
wainola Jan 29, 2024
1de889a
Update packages/widget/src/interfaces/index.ts
wainola Jan 29, 2024
6ee30d9
Update packages/widget/src/interfaces/index.ts
wainola Jan 29, 2024
0604620
Update packages/widget/src/interfaces/index.ts
wainola Jan 29, 2024
84bcd35
Update packages/widget/src/interfaces/index.ts
wainola Jan 29, 2024
12fe767
Update packages/widget/src/interfaces/index.ts
wainola Jan 29, 2024
4a58c48
Update packages/widget/src/interfaces/index.ts
wainola Jan 29, 2024
18cbeb6
Update packages/widget/src/interfaces/index.ts
wainola Jan 29, 2024
df437ab
Update packages/widget/src/interfaces/index.ts
wainola Jan 29, 2024
2389d3a
Update packages/widget/src/interfaces/index.ts
wainola Jan 30, 2024
8359332
feat: wrapped widget
wainola Feb 2, 2024
5dfde30
Merge branch 'main' into feat/react-package
wainola Feb 2, 2024
13d1c6b
feat: adding properties to widget, some new interface
wainola Feb 5, 2024
07575bf
chore: intrinsic element on namespace declaration to get intellisense
wainola Feb 5, 2024
82b26f8
chore: merge with main
wainola Feb 5, 2024
d29d165
chore: fix linter error
wainola Feb 5, 2024
5a67bd1
chore: update lock file
wainola Feb 5, 2024
65c64c0
chore: linter issue
wainola Feb 5, 2024
c21e910
chore: adding linting
wainola Feb 5, 2024
63a73e8
fix ci
mpetrunic Feb 6, 2024
f690626
chore: merge with main
wainola Feb 7, 2024
f94750f
chore: react as peerdep and devdep
wainola Feb 7, 2024
1bd702d
chore: example react app
wainola Feb 7, 2024
28f6f9d
chore: fix render on example app
wainola Feb 7, 2024
4cf219b
chore: small modification to workflow file
wainola Feb 7, 2024
24225d9
chore: making workflow run
wainola Feb 7, 2024
cb6ba02
chore: fixing dependency on example app
wainola Feb 7, 2024
d77fa69
chore: changes on lock file
wainola Feb 7, 2024
e7847bb
chore: inmutable back
wainola Feb 7, 2024
c0ec0e2
chore: modifying workflow
wainola Feb 7, 2024
5e348fe
chore: modifying workflow
wainola Feb 7, 2024
e0f283c
chore: modifying workflow
wainola Feb 7, 2024
9439b54
chore: modifying workflow to deploy example app
wainola Feb 7, 2024
30b8c57
chore: small fixes for the pipeline
wainola Feb 7, 2024
587f1c9
chore: small fixes for the pipeline
wainola Feb 7, 2024
1662abd
chore: small fixes for the pipeline
wainola Feb 7, 2024
d82de4a
chore: pr review
wainola Feb 8, 2024
d001145
chore: dependency
wainola Feb 8, 2024
fe95c63
chore: some linting
wainola Feb 8, 2024
b83b25f
chore: fixing some linter issues
wainola Feb 8, 2024
9c1285d
chore: restoring some scripts
wainola Feb 8, 2024
7243c5b
chore: going back to namespace on module
wainola Feb 8, 2024
0f62df3
chore: linter issues
wainola Feb 8, 2024
b5b430c
chore: removing unnecesary dependencies
wainola Feb 8, 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
11 changes: 6 additions & 5 deletions .github/workflows/cf-deploy-react.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
cache: 'yarn'
node-version: 18
- run: corepack enable
- run: yarn set version stable
- uses: actions/setup-node@v4
with:
cache: yarn
node-version: 18
- run: yarn install --immutable
- run: yarn run lint:react-widget
- run: yarn run build:react-widget
- run: yarn build

- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: sygma-react-widget
directory: ./packages/react/build
directory: ./examples/react-widget-app/dist
branch: main
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ jobs:
node-version: 18
cache: yarn
- run: yarn install --immutable
- run: yarn run lint
- run: yarn run build
- run: yarn run lint
- run: yarn run test:unit
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,3 @@ public/sygma-runtime-config*
.vscode

/dist
/examples
4 changes: 4 additions & 0 deletions examples/react-widget-app/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
wainola marked this conversation as resolved.
Show resolved Hide resolved
extends: "@chainsafe/eslint-config/frontend-react",
wainola marked this conversation as resolved.
Show resolved Hide resolved
plugins: ["react", "react-hooks"],
}
24 changes: 24 additions & 0 deletions examples/react-widget-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
12 changes: 12 additions & 0 deletions examples/react-widget-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sygma Widget React Example</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
wainola marked this conversation as resolved.
Show resolved Hide resolved
</body>
</html>
28 changes: 28 additions & 0 deletions examples/react-widget-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@buildwithsygma/react-widget-app",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "yarn run lint:types && yarn run lint:code",
"lint:types": "tsc -p ./tsconfig.json --noEmit",
"lint:code": "eslint '{src,tests}/**/*.ts'",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is intentional to just check ts files?

"preview": "vite preview"
},
"dependencies": {
"@buildwithsygma/sygmaprotocol-react-widget": "workspace:^",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@chainsafe/eslint-config": "2.2.2",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.55.0",
"typescript": "^5.2.2",
"vite": "^5.0.8"
}
}
10 changes: 10 additions & 0 deletions examples/react-widget-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { SygmaProtocolReactWidget } from '@buildwithsygma/sygmaprotocol-react-widget'

function App() {

return (
<SygmaProtocolReactWidget />
)
}

export default App
10 changes: 10 additions & 0 deletions examples/react-widget-app/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom/client';

import App from './App.tsx';

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
1 change: 1 addition & 0 deletions examples/react-widget-app/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
25 changes: 25 additions & 0 deletions examples/react-widget-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
10 changes: 10 additions & 0 deletions examples/react-widget-app/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
7 changes: 7 additions & 0 deletions examples/react-widget-app/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"test:unit": "yarn workspaces foreach --all -pt run test:unit",
"build:widget": "yarn workspace @buildwithsygma/sygmaprotocol-widget build:preview",
"build:react-widget": "yarn workspace @buildwithsygma/sygmaprotocol-react-widget build",
"build:react-widget-app": "yarn workspace @buildwithsygma/react-widget-app build",
"lint:widget": "yarn workspace @buildwithsygma/sygmaprotocol-widget lint",
"lint:react-widget": "yarn workspace @buildwithsygma/sygmaprotocol-react-widget lint"
},
Expand Down
15 changes: 12 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@
"license": "LGPL-3.0-or-later",
"type": "module",
"dependencies": {
"@lit-labs/react": "2.1.2"
"@buildwithsygma/sygmaprotocol-widget": "workspace:^",
"@lit/react": "1.0.3"
},
"peerDependencies": {
"react": ">=17",
"react-dom": ">=17"
wainola marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@types/react": ">=17",
"eslint": "^8.48.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.2.2"
},
"scripts": {
"build": "tsc --build --clean && tsc --build ./tsconfig.json",
"dev": "tsc --build --clean && tsc --build ./tsconfig.json --watch",
"clean": "rm -rf ./build",
"lint": "eslint 'src/**/*.ts'",
"lint:fix": "yarn run lint --fix"
"lint": "yarn run lint:types && yarn run lint:code",
"lint:types": "tsc -p ./tsconfig.json --noEmit",
"lint:code": "eslint '{src,tests}/**/*.ts'"
},
"author": "Sygmaprotocol Product Team"
}
18 changes: 18 additions & 0 deletions packages/react/src/WidgetReact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { createComponent } from '@lit/react';
import { SygmaProtocolWidget } from '@buildwithsygma/sygmaprotocol-widget';

export const SygmaProtocolReactWidget = createComponent<SygmaProtocolWidget>({
tagName: 'sygmaprotocol-widget',
elementClass: SygmaProtocolWidget,
react: React
});

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace JSX {
interface IntrinsicElements {
'sygmaprotocol-widget': SygmaProtocolWidget;
}
}
}
wainola marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SygmaProtocolReactWidget } from './WidgetReact';
37 changes: 37 additions & 0 deletions packages/widget/src/interfaces/index.ts
wainola marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type {
EvmResource,
Network,
SubstrateResource
} from '@buildwithsygma/sygma-sdk-core';
import type { ApiPromise } from '@polkadot/api';
import type { Signer } from '@polkadot/api/types';

export type ThemeVariables =
| 'mainColor'
| 'secondaryColor'
| 'fontSize'
| 'borderRadius'
| 'borderRadiusSecondary';

export type Theme = Record<ThemeVariables, string>;

export interface Eip1193Provider {
request(request: {
method: string;
params?: Array<unknown> | Record<string, unknown>;
}): Promise<unknown>;
}

export interface ISygmaProtocolWidget {
whitelistedSourceNetworks?: Network[];
whitelistedDestinationNetworks?: Network[];
evmProvider?: Eip1193Provider;
substrateProvider?: ApiPromise | string;
substrateSigner?: Signer;
show?: boolean;
whitelistedSourceResources?: Array<EvmResource | SubstrateResource>;
expandable?: boolean;
darkTheme?: boolean;
customLogo?: SVGElement;
theme?: Theme;
}
56 changes: 49 additions & 7 deletions packages/widget/src/widget.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,61 @@
import type { HTMLTemplateResult } from 'lit';
import { html } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import type { HTMLTemplateResult } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import type {
EvmResource,
Network,
SubstrateResource
} from '@buildwithsygma/sygma-sdk-core';
import type { ApiPromise } from '@polkadot/api';
import type { Signer } from '@polkadot/api/types';
import { when } from 'lit/directives/when.js';
import { styles } from './styles';
import { sygmaLogo } from './assets';
import './components';
import { WidgetController } from './controllers/widget';
import './components/network-selector';
import './components/amount-selector';
import './components/address-input';
import { Directions } from './components/network-selector/network-selector';
import type {
Eip1193Provider,
ISygmaProtocolWidget,
Theme
} from './interfaces';
import './components';
import './context/wallet';
import { WidgetController } from './controllers/widget';
import { styles } from './styles';
import { BaseComponent } from './components/base-component/base-component';

@customElement('sygmaprotocol-widget')
class SygmaProtocolWidget extends BaseComponent {
class SygmaProtocolWidget
extends BaseComponent
implements ISygmaProtocolWidget
{
static styles = styles;

@property({ type: Array }) whitelistedSourceNetworks?: Network[];

@property({ type: Array }) whitelistedDestinationNetworks?: Network[];

@property({ type: Object }) evmProvider?: Eip1193Provider;

@property() substrateProvider?: ApiPromise | string;

@property({ type: Object }) substrateSigner?: Signer;

@property({ type: Boolean }) show?: boolean;

@property({ type: Array }) whitelistedSourceResources?: Array<
EvmResource | SubstrateResource
>;

@property({ type: Boolean }) expandable?: boolean;

@property({ type: Boolean }) darkTheme?: boolean;

@property({ type: Object }) customLogo?: SVGElement;

@property({ type: Object }) theme?: Theme;

@state()
private isLoading = false;

Expand Down Expand Up @@ -109,6 +151,6 @@ export { SygmaProtocolWidget };

declare global {
interface HTMLElementTagNameMap {
'sygmaprotocol-widget': SygmaProtocolWidget;
'sygmaprotocol-widget': ISygmaProtocolWidget;
}
}
Loading
Loading