Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:sygmaprotocol/sygma-widget into feat…
Browse files Browse the repository at this point in the history
…/display_gas_fee_estimation
  • Loading branch information
saadahmsiddiqui committed Apr 19, 2024
2 parents 7869009 + 21ceb18 commit a1a32bc
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
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 @@ -17,9 +18,10 @@ import './transfer-button';
import './transfer-detail';
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 @@ -74,6 +76,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 @@ -144,6 +168,9 @@ export class FungibleTokenTransfer extends BaseComponent {
</sygma-address-input>
</section>
<section>
${when(this.transferController.destinationAddress, () =>
this.renderAmountOnDestination()
)}
<sygma-fungible-transfer-detail
.estimatedGasFee=${this.transferController.estimatedGas}
.selectedResource=${this.transferController.selectedResource}
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 @@ -78,7 +78,7 @@ export class FungibleTokenTransferController implements ReactiveController {
protected buildEvmTransactions = buildEvmFungibleTransactions;
protected executeNextEvmTransaction = executeNextEvmTransaction;
protected pendingEvmApprovalTransactions: UnsignedTransaction[] = [];
protected pendingTransferTransaction?:
public pendingTransferTransaction?:
| UnsignedTransaction
| SubstrateTransaction;

Expand All @@ -98,13 +98,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 @@ -128,6 +121,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
2 changes: 2 additions & 0 deletions packages/widget/src/controllers/transfers/substrate/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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
1 change: 0 additions & 1 deletion packages/widget/src/controllers/wallet-manager/manager.ts
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

0 comments on commit a1a32bc

Please sign in to comment.