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: display amount to be received on destination #168

Merged
merged 24 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7dd44e4
feat: allow bridge environment configuration (#104)
mpetrunic Feb 21, 2024
b178429
fix: amount selector prefilled with zero (#109)
mpetrunic Feb 21, 2024
9acf7f0
fix: address input not submitted on paste (#108)
mpetrunic Feb 22, 2024
7935f81
fix: re-validate on account balance change (#107)
mpetrunic Feb 22, 2024
cc8617d
feat: externalize wallet connect connection through props (#94)
wainola Feb 22, 2024
ca4ece0
fix: error where start new transfer isn't working (#126)
wainola Mar 4, 2024
74191b1
fix: substrate address not validated bug (#128)
wainola Mar 5, 2024
f65f372
chore: remove lit warnings (#131)
mpetrunic Mar 7, 2024
359e6df
fix: incorrect transfer state when disconnecting wallet after transfe…
mpetrunic Mar 11, 2024
9122c07
chore: add codeowners (#142)
mpetrunic Mar 13, 2024
db9ad8a
fix: switch networks and misc fixes (#127)
wainola Mar 13, 2024
679346a
feat: set destination address for EVM (#129)
Lykhoyda Mar 14, 2024
01901e6
fix: max button rounds value (#137)
Lykhoyda Mar 18, 2024
4a497e2
fix: clear wallet context on disconnect (#152)
Lykhoyda Mar 28, 2024
e2d16fd
fix: Switching to a different TOKEN mapping for "From - TO" relations…
saadahmsiddiqui Apr 3, 2024
ec154be
feat: Transfer UI page (#144)
mj52951 Apr 3, 2024
8d6620e
fix: easier amount input (#159)
mpetrunic Apr 3, 2024
d29771e
fix: evm amount is now calculated as user input minus the fee (#143)
mpetrunic Apr 4, 2024
762e95a
feat: reset fields after transfer is complete (#163)
Lykhoyda Apr 8, 2024
0e38bff
feat: base impl for amount to receive and flag to display only comput…
wainola Apr 12, 2024
9a9c93f
chore: pr review
wainola Apr 13, 2024
47e54ca
chore: fix conflicts and rebase with dev
wainola Apr 16, 2024
6a021cc
chore: correct amount when going from sub to evm
wainola Apr 18, 2024
ed21f8b
chore: addressing last comment from Saad
wainola Apr 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { html } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import '../../../context/wallet';
import { choose } from 'lit/directives/choose.js';
import { when } from 'lit/directives/when.js';
import type { Eip1193Provider } from 'packages/widget/src/interfaces';
import {
FungibleTokenTransferController,
Expand All @@ -16,9 +17,10 @@ import '../../resource-amount-selector';
import './transfer-button';
import './transfer-status';
import '../../network-selector';
import { BaseComponent } from '../../common';
import { Directions } from '../../network-selector/network-selector';
import { WalletController } from '../../../controllers';
import { BaseComponent } from '../../common/base-component';
import { tokenBalanceToNumber } from '../../../utils/token';
import { styles } from './styles';

@customElement('sygma-fungible-transfer')
Expand Down Expand Up @@ -73,6 +75,28 @@ export class FungibleTokenTransfer extends BaseComponent {
}
};

renderAmountOnDestination(): HTMLTemplateResult | null {
if (
this.transferController.selectedResource &&
this.transferController.pendingTransferTransaction !== undefined
) {
const { decimals, symbol } = this.transferController.selectedResource;
return html`
<div class="amountOnDestination">
<span> Amount to receive: </span>
<span>
${tokenBalanceToNumber(
this.transferController.resourceAmount,
decimals!
)}
${symbol}
</span>
</div>
`;
}
return null;
}

renderTransferStatus(): HTMLTemplateResult {
return html` <section>
<sygma-transfer-status
Expand Down Expand Up @@ -143,6 +167,9 @@ export class FungibleTokenTransfer extends BaseComponent {
</sygma-address-input>
</section>
<section>
${when(this.transferController.destinationAddress, () =>
this.renderAmountOnDestination()
)}
<sygma-fungible-transfer-detail
.selectedResource=${this.transferController.selectedResource}
.fee=${this.transferController.fee}
Expand Down
10 changes: 10 additions & 0 deletions packages/widget/src/components/transfer/fungible/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@ export const styles = css`
align-items: stretch;
gap: 0.5rem;
}

.amountOnDestination {
display: flex;
justify-content: space-between;
padding-bottom: 0.5rem;
font-size: 0.75rem;
font-style: normal;
font-weight: 400;
line-height: normal;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class FungibleTokenTransferController implements ReactiveController {
protected buildEvmTransactions = buildEvmFungibleTransactions;
protected executeNextEvmTransaction = executeNextEvmTransaction;
protected pendingEvmApprovalTransactions: UnsignedTransaction[] = [];
protected pendingTransferTransaction?:
public pendingTransferTransaction?:
| UnsignedTransaction
| SubstrateTransaction;

Expand All @@ -96,13 +96,6 @@ export class FungibleTokenTransferController implements ReactiveController {
ReactiveElement
>;

isWalletDisconnected(context: WalletContext): boolean {
// Skip the method call during init
if (Object.values(context).length === 0) return false;

return !(!!context.evmWallet || !!context.substrateWallet);
}

get sourceSubstrateProvider(): ApiPromise | undefined {
if (this.sourceNetwork && this.sourceNetwork.type === Network.SUBSTRATE) {
const domainConfig = this.config.getDomainConfig(
Expand All @@ -126,6 +119,13 @@ export class FungibleTokenTransferController implements ReactiveController {
);
}

isWalletDisconnected(context: WalletContext): boolean {
// Skip the method call during init
if (Object.values(context).length === 0) return false;

return !(!!context.evmWallet || !!context.substrateWallet);
}

constructor(host: ReactiveElement) {
(this.host = host).addController(this);
this.config = new Config();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export async function buildSubstrateFungibleTransactions(
);

this.fee = await substrateTransfer.getFee(transfer);

this.resourceAmount = this.resourceAmount.sub(this.fee.fee.toString());
this.pendingTransferTransaction = substrateTransfer.buildTransferTransaction(
transfer,
this.fee
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ export class WalletController implements ReactiveController {
}
}
}

connectEvmWallet = async (
network: Domain,
options?: {
Expand Down
2 changes: 1 addition & 1 deletion packages/widget/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ class SygmaProtocolWidget
.appMetadata=${this.appMetadata}
.theme=${this.theme}
.walletConnectOptions=${this.walletConnectOptions}
.walletModules=${this.walletModules}
>
<sygma-wallet-context-provider
.walletModules=${this.walletModules}
.substrateProviders=${this.substrateProviders}
.environment=${this.environment}
>
Expand Down
Loading