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: address to transfer #56

Merged
merged 48 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
bbf87e0
feat: address to transfer base implementation
wainola Jan 18, 2024
61e4848
chore: fixing conflicts
wainola Jan 18, 2024
c14b0d4
chore: fixing linter error
wainola Jan 18, 2024
3d5e06a
fix: small fix on message
wainola Jan 18, 2024
f1de178
chore: removing switch and input prefilled with current connected add…
wainola Jan 18, 2024
7eaca09
chore: modifying connect component
wainola Jan 18, 2024
0eafaba
chore: merge with main
wainola Jan 18, 2024
4b726cd
chore: changes to include address to transfer input to main view
wainola Jan 18, 2024
fc401ee
chore: remove unused dependency
wainola Jan 19, 2024
9df492c
chore: merge with main
wainola Jan 22, 2024
e7a6879
chore: fixing linter issue
wainola Jan 22, 2024
52d26af
chore: fixing linter issue for method
wainola Jan 22, 2024
8e42895
remove extra code, add vite build, add tests
mpetrunic Jan 22, 2024
bfa4d52
chore: remove setting prop to default value
sztok7 Jan 22, 2024
46b89c6
chore: typo
sztok7 Jan 22, 2024
86b5615
chore: use enum for `Direction` (to/from)
sztok7 Jan 22, 2024
b2d3cdb
chore: shorter func signature
sztok7 Jan 22, 2024
e6de33a
chore: use destructure
sztok7 Jan 22, 2024
e239b08
chore: cleanup styles partially
sztok7 Jan 22, 2024
18c3ac1
chore: remove unnecessary haschange and small fix
wainola Jan 22, 2024
08146cd
chore: rebase with reorg branch
wainola Jan 22, 2024
739a467
chore: pr review, adding test and validation for address
wainola Jan 23, 2024
61fc32c
fix: linter issue
wainola Jan 23, 2024
328e244
Merge branch 'main' into feat/address-to-transfer
mpetrunic Jan 23, 2024
0d2919b
Update packages/widget/src/components/address-input/address-input.ts
wainola Jan 23, 2024
6990502
feat: error msg + styling
wainola Jan 24, 2024
8d9b1be
feat: update tests
wainola Jan 24, 2024
87b0bdf
chore: changed tests to run on happy-dom
mpetrunic Jan 24, 2024
4ddc55b
Merge branch 'main' into feat/address-to-transfer
mpetrunic Jan 24, 2024
53827bc
bump sygma sdk version
mpetrunic Jan 24, 2024
952a9b9
chore: update test to validate prefilled address
wainola Jan 24, 2024
4c263c6
feat: adding input to the widget, some styles cleanup for input compo…
wainola Jan 24, 2024
6374028
chore: update test
wainola Jan 24, 2024
6992574
chore: addressing some comments
wainola Jan 24, 2024
a4891fa
chore: colors on host definition and applying to them
wainola Jan 29, 2024
ace424d
chore: some changes on styles and replacing px for rem
wainola Jan 29, 2024
a3ba54a
feat: remove outline for input
wainola Jan 29, 2024
f2f98d2
chore: fix test
wainola Jan 29, 2024
695f08b
Update packages/widget/src/components/address-input/address-input.ts
wainola Jan 29, 2024
d1a3844
Update packages/widget/src/components/address-input/address-input.ts
wainola Jan 29, 2024
a259fd7
chore: pr review
wainola Jan 29, 2024
09cecca
chore: pr review + changing input component to textarea because susbt…
wainola Jan 31, 2024
b1c801c
chore: pushing style changes
wainola Jan 31, 2024
c995be7
chore: merge with main
wainola Jan 31, 2024
16576f1
chore: minor changes on styles and updating test
wainola Jan 31, 2024
4d6eced
chore: more comments
wainola Jan 31, 2024
2abadbd
chore: more comments
wainola Jan 31, 2024
2ed10b4
chore: small update on test
wainola Jan 31, 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
5 changes: 4 additions & 1 deletion packages/widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"author": "Sygmaprotocol Product Team",
"dependencies": {
"@buildwithsygma/sygma-sdk-core": "^2.6.0",
"@buildwithsygma/sygma-sdk-core": "^2.6.2",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
Expand All @@ -36,6 +36,8 @@
"@lit/reactive-element": "^2.0.3",
"@polkadot/api": "^10.11.2",
"@polkadot/extension-dapp": "^0.46.6",
"@polkadot/keyring": "^12.6.2",
"@polkadot/util": "^12.6.2",
"ethers": "5.7.2",
"events": "^3.3.0",
"lit": "3.0.0"
Expand All @@ -45,6 +47,7 @@
"@open-wc/testing-helpers": "^3.0.0",
"eslint": "^8.48.0",
"eslint-plugin-lit": "^1.9.1",
"happy-dom": "^13.3.1",
"jsdom": "^23.2.0",
wainola marked this conversation as resolved.
Show resolved Hide resolved
"lit-analyzer": "^2.0.3",
"rollup-plugin-visualizer": "^5.9.2",
Expand Down
90 changes: 90 additions & 0 deletions packages/widget/src/components/address-input/address-input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { LitElement, html } from 'lit';
import type { HTMLTemplateResult } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { ethers } from 'ethers';
import { Network } from '@buildwithsygma/sygma-sdk-core';
import { when } from 'lit/directives/when.js';
import { validateSubstrateAddress } from '../../utils';
import { styles } from './styles';

@customElement('sygma-address-input')
export class AddressInput extends LitElement {
static styles = styles;
@property({
type: String
})
address: string = '';

@property({ attribute: false })
onAddressChange: (address: string) => void = () => {};

@property({
type: String
})
network: Network = Network.EVM;

@state()
errorMessage?: string;
wainola marked this conversation as resolved.
Show resolved Hide resolved

connectedCallback(): void {
super.connectedCallback();
if (this.address) {
wainola marked this conversation as resolved.
Show resolved Hide resolved
this.handleAddressChange({
target: { value: this.address }
} as unknown as Event);
wainola marked this conversation as resolved.
Show resolved Hide resolved
}
}

private handleAddressChange = ({ target }: Event): void => {
const { value } = target as HTMLInputElement;

if (this.errorMessage) {
this.errorMessage = undefined;
wainola marked this conversation as resolved.
Show resolved Hide resolved
}

if (value !== '') {
wainola marked this conversation as resolved.
Show resolved Hide resolved
if (this.network === Network.SUBSTRATE) {
const validPolkadotAddress = validateSubstrateAddress(value);

if (!validPolkadotAddress) {
this.errorMessage = 'invalid Substrate address';
return;
}
} else {
const isAddress = ethers.utils.isAddress(value);
if (!isAddress) {
this.errorMessage = 'invalid Ethereum Address';
return;
}
}
wainola marked this conversation as resolved.
Show resolved Hide resolved
}

void this.onAddressChange?.(value);
wainola marked this conversation as resolved.
Show resolved Hide resolved
};

render(): HTMLTemplateResult {
return html`<section class="addressInputContainer">
<div class="inputAddressContainer">
wainola marked this conversation as resolved.
Show resolved Hide resolved
<label>Send to</label>
${when(
this.errorMessage,
() => html` <span class="errorMessage">${this.errorMessage}</span>`
)}
<input
class=${this.errorMessage ? 'inputAddress error' : 'inputAddress'}
name="address"
type="text"
@change=${(evt: Event) => this.handleAddressChange.bind(this)(evt)}
wainola marked this conversation as resolved.
Show resolved Hide resolved
value=${ifDefined(this.address)}
/>
</div>
</section>`;
}
}

declare global {
interface HTMLElementTagNameMap {
'sygma-address-input': AddressInput;
}
}
1 change: 1 addition & 0 deletions packages/widget/src/components/address-input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AddressInput } from './address-input';
45 changes: 45 additions & 0 deletions packages/widget/src/components/address-input/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { css } from 'lit';

export const styles = css`
.addressInputContainer {
display: flex;
flex-direction: column;
justify-content: center;
gap: 0.5rem;
min-height: 7.75rem;
wainola marked this conversation as resolved.
Show resolved Hide resolved
height: 100%;
wainola marked this conversation as resolved.
Show resolved Hide resolved
}

.inputAddressContainer {
display: flex;
flex-direction: column;
width: 100%;
min-height: 7.75rem;
height: 100%;
gap: 0.5rem;
}

.inputAddress {
border-radius: 1.5rem;
border: 0.063rem solid var(--zinc-200);
width: 100%;
height: 4.25rem;
wainola marked this conversation as resolved.
Show resolved Hide resolved
font-size: 0.875rem;
text-align: center;
}

.inputAddress:focus {
outline: none;
border: 0.063rem solid var(--zinc-200);
}

.error {
border-color: red;
}

.errorMessage {
color: red;
font-weight: 300;
font-size: 0.75rem;
}
`;
6 changes: 3 additions & 3 deletions packages/widget/src/components/amount-selector/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const styles = css`
display: flex;
width: 100%;
justify-content: flex-start;
color: #525252;
color: var(--neutral-600);
font-size: 14px;
font-weight: 500;
line-height: 20px; /* 142.857% */
Expand All @@ -30,7 +30,7 @@ export const styles = css`

.amountSelectorInput {
border: none;
color: #525252;
color: var(--neutral-600);
font-size: 34px;
font-weight: 500;
line-height: 40px;
Expand All @@ -52,7 +52,7 @@ export const styles = css`
}

.maxButton {
color: #2563eb;
color: var(--blue-600);
border: none;
background: none;
font-weight: 500;
Expand Down
1 change: 1 addition & 0 deletions packages/widget/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { AmountSelector } from './amount-selector';
export { NetworkSelector } from './network-selector';
export { AddressInput } from './address-input';
6 changes: 3 additions & 3 deletions packages/widget/src/components/network-selector/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { css } from 'lit';
export const styles = css`
.selectorContainer {
border-radius: 24px;
border: 1px solid #e4e4e7;
border: 1px solid var(--zinc-200);
display: flex;
width: 314px;
padding: 12px 16px;
Expand All @@ -14,7 +14,7 @@ export const styles = css`
}

.directionLabel {
color: #a1a1aa;
color: var(--zinc-400);
font-size: 14px;
font-weight: 500;
line-height: 20px;
Expand All @@ -29,7 +29,7 @@ export const styles = css`

.selector {
width: 100%;
color: #525252;
color: var(--neutral-600);
font-size: 18px;
font-weight: 500;
line-height: 26px;
Expand Down
6 changes: 6 additions & 0 deletions packages/widget/src/controllers/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class WidgetController implements ReactiveController {
public supportedSourceNetworks: Domain[] = [];
public supportedDestinationNetworks: Domain[] = [];
public supportedResources: Resource[] = [];
public destinatonAddress?: string = '';

//@ts-expect-error it will be used
private assetTransfer?: EVMAssetTransfer | SubstrateAssetTransfer;
Expand Down Expand Up @@ -126,4 +127,9 @@ export class WidgetController implements ReactiveController {
console.log('resource amount', amount);
this.resourceAmount = amount;
};

onDestinationAddressChange = (address: string): void => {
console.log('destination address', address);
this.destinatonAddress = address;
};
}
29 changes: 20 additions & 9 deletions packages/widget/src/styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { css } from 'lit';

export const styles = css`
:host {
--zinc-200: #e4e4e7;
--zinc-400: #a1a1aa;
--white: #fff;
--gray-100: #f3f4f6;
--neutral-600: #525252;
--primary-300: #a5b4fc;
--primary-500: #6366f1;
--blue-600: #2563eb;
}

@font-face {
font-family: 'Inter';
font-style: normal;
Expand All @@ -15,11 +26,11 @@ export const styles = css`
gap: 16px;

padding: 24px;
wainola marked this conversation as resolved.
Show resolved Hide resolved
width: 350px; /* TODO: remove these hardcoded values */
height: 476px; /* TODO: ↑ */
width: 21.875rem; /* TODO: remove these hardcoded values */
height: 31.25rem; /* TODO: ↑ */
border-radius: 12px;
border: 1px solid #f3f4f6;
background-color: #fff;
border: 1px solid var(--gray-100);
background-color: var(--white);

box-shadow:
0 4px 6px -1px rgba(0, 0, 0, 0.1),
Expand All @@ -43,7 +54,7 @@ export const styles = css`

border-radius: 16px;
border: none;
background-color: #a5b4fc;
background-color: var(--primary-300);
color: #ffffff;

width: 314px; /* TODO: remove these hardcoded values */
Expand All @@ -58,7 +69,7 @@ export const styles = css`
}

.actionButton:active {
background-color: #6366f1;
background-color: var(--primary-500);
}

.actionButtonReady {
Expand All @@ -71,13 +82,13 @@ export const styles = css`
padding: 12px 20px;

border-radius: 16px;
background-color: #6366f1;
background-color: var(--primary-500);
color: #ffffff;
border: none;
}

.actionButtonReady:active {
background-color: #a5b4fc;
background-color: var(--primary-300);
}

.actionButtonReady:hover {
Expand All @@ -90,7 +101,7 @@ export const styles = css`
gap: 6px;
align-self: flex-start;

color: #525252;
color: var(--neutral-600);
font-size: 12px;
line-height: 150%;
}
Expand Down
11 changes: 11 additions & 0 deletions packages/widget/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { HTMLTemplateResult } from 'lit';
import { html } from 'lit';
import { decodeAddress, encodeAddress } from '@polkadot/keyring';
import { hexToU8a, isHex } from '@polkadot/util';
import {
baseNetworkIcon,
cronosNetworkIcon,
Expand Down Expand Up @@ -46,3 +48,12 @@ export const capitalize = (s: string): string => {
const rest = s.slice(1);
return `${firstLetter}${rest}`;
};

export const validateSubstrateAddress = (address: string): boolean => {
try {
encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address));
return true;
} catch (error) {
return false;
}
};
9 changes: 9 additions & 0 deletions packages/widget/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { switchNetworkIcon, sygmaLogo } from './assets';
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';

@customElement('sygmaprotocol-widget')
Expand Down Expand Up @@ -51,6 +52,14 @@ class SygmaProtocolWidget extends LitElement {
>
</sygma-resource-selector>
</section>
<section>
<sygma-address-input
.address=${this.widgetController.destinatonAddress}
.onAddressChange=${this.widgetController
.onDestinationAddressChange}
>
</sygma-address-input>
</section>
<section>
<button
.disabled=${!this.widgetController.isReadyForTransfer}
Expand Down
Loading
Loading