Skip to content

Mf/add buy deso with megaswap tab #610

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

Merged
merged 14 commits into from
Oct 24, 2022
4 changes: 4 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ header @html Content-Security-Policy "
https://altumbase.com
localhost:*
explorer.bitclout.com
megaswap.dev
megaswap.xyz
https://api.blockchain.com/ticker
https://api.blockchain.com/mempool/fees
https://ka-f.fontawesome.com/
Expand Down Expand Up @@ -80,6 +82,8 @@ header @html Content-Security-Policy "
identity.bitclout.com
identity.bitclout.blue
identity.bitclout.green
megaswap.dev
megaswap.xyz
https://geo.captcha-delivery.com
https://www.youtube.com
https://youtube.com
Expand Down
5 changes: 5 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ const routes: Routes = [
component: BuyDeSoPageComponent,
pathMatch: 'full',
},
{
path: RouteNames.BUY_DESO + '/:ticker',
component: BuyDeSoPageComponent,
pathMatch: 'full',
},
{
path: RouteNames.PICK_A_COIN,
component: PickACoinPageComponent,
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { LeftBarButtonComponent } from './left-bar/left-bar-button/left-bar-butt
import { TradeCreatorPageComponent } from './trade-creator-page/trade-creator-page.component';
import { TradeCreatorComponent } from './trade-creator-page/trade-creator/trade-creator.component';
import { BuyDeSoComponent } from './buy-deso-page/buy-deso/buy-deso.component';
import { BuyDeSoMegaSwapComponent } from './buy-deso-page/buy-deso-megaswap/buy-deso-megaswap.component';
import { BuyDeSoUSDComponent } from './buy-deso-page/buy-deso-usd/buy-deso-usd.component';
import { TradeCreatorFormComponent } from './trade-creator-page/trade-creator-form/trade-creator-form.component';
import { TradeCreatorPreviewComponent } from './trade-creator-page/trade-creator-preview/trade-creator-preview.component';
Expand Down Expand Up @@ -212,6 +213,7 @@ const greenishTheme: Theme = { key: 'greenish', name: 'Green Theme' };
TradeCreatorPageComponent,
TradeCreatorComponent,
BuyDeSoComponent,
BuyDeSoMegaSwapComponent,
BuyDeSoUSDComponent,
TradeCreatorFormComponent,
TradeCreatorPreviewComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="vh-75">
<p class="mb-2 px-3 fs-7 text-muted">
<i class="fas fa-info-circle"></i>
Swap from BTC, ETH, SOL, and other chains to DESO using MegaSwap.
The legacy <a [routerLink]="'/' + globalVars.RouteNames.BUY_DESO + '/BTC'">Buy with BTC</a>
<span *ngIf="globalVars.showBuyWithETH; else elseBlockInfo">
and <a [routerLink]="'/' + globalVars.RouteNames.BUY_DESO + '/ETH'">Buy with ETH</a> flows are
</span>
<ng-template #elseBlockInfo>
flow is
</ng-template>
still accessible but being deprecated.
</p>

<iframe
*ngIf="iframeURL; else elseBlockIframe"
[src]="iframeURL"
class="border-0 rounded w-100 h-100"
></iframe>
<ng-template #elseBlockIframe>
<p class="fs-8 text-danger text-center">
<i class="fas fa-exclamation-triangle"></i> Unable to render iFrame.<br />Invalid MegaSwap URL.
</p>
</ng-template>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.fs-7 {
font-size: 0.7rem;
}

.fs-8 {
font-size: 0.8rem;
}

.vh-75 {
height: 75vh;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { BuyDeSoMegaSwapComponent } from './buy-deso-megaswap.component';

describe('BuyDeSoMegaSwapComponent', () => {
let component: BuyDeSoMegaSwapComponent;
let fixture: ComponentFixture<BuyDeSoMegaSwapComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [BuyDeSoMegaSwapComponent],
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(BuyDeSoMegaSwapComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Component, OnInit } from '@angular/core';
import { DomSanitizer, SafeResourceUrl, Title } from '@angular/platform-browser';
import { GlobalVarsService } from 'src/app/global-vars.service';
import { environment } from 'src/environments/environment';

@Component({
selector: 'buy-deso-megaswap',
templateUrl: './buy-deso-megaswap.component.html',
styleUrls: ['./buy-deso-megaswap.component.scss'],
})
export class BuyDeSoMegaSwapComponent implements OnInit {
iframeURL: SafeResourceUrl = '';

constructor(
public globalVars: GlobalVarsService,
private sanitizer: DomSanitizer,
) {
if (!environment.megaswapURL) {
return;
}

// Map theme to MegaSwap theme.
let theme = {
'cake': 'light-peach',
'dark': 'dark-gray',
'greenish': 'dark-green',
'icydark': 'dark-icy',
'legends': 'dark-brown',
'light': 'light-white',
}[localStorage.getItem('theme')] || 'default';

if (theme === 'default' && window.matchMedia('(prefers-color-scheme: dark)').matches) {
theme = 'dark-gray';
}

this.iframeURL = this.sanitizer.bypassSecurityTrustResourceUrl(
[
environment.megaswapURL,
'/#/iframe/v1?',
`network=${environment.production ? 'mainnet' : 'testnet'}`,
`&theme=${theme}`,
'&destinationTickers=DESO',
'&destinationTicker=DESO',
`&destinationAddress=${this.globalVars.loggedInUser?.PublicKeyBase58Check || ''}`,
].join('')
);
}

ngOnInit() {
window.scroll(0, 0);
}
}
3 changes: 3 additions & 0 deletions src/app/buy-deso-page/buy-deso/buy-deso.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
(tabClick)="_handleTabClick($event)"
></tab-selector>
</div>
<div *ngIf="activeTab === BuyDeSoComponent.BUY_WITH_MEGASWAP">
<buy-deso-megaswap></buy-deso-megaswap>
</div>
<div *ngIf="activeTab === BuyDeSoComponent.BUY_WITH_USD">
<buy-deso-usd></buy-deso-usd>
</div>
Expand Down
27 changes: 16 additions & 11 deletions src/app/buy-deso-page/buy-deso/buy-deso.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ export class BuyDeSoComponent implements OnInit {

BuyDeSoComponent = BuyDeSoComponent;

static BUY_WITH_MEGASWAP = 'Buy with Crypto';
static BUY_WITH_USD = 'Buy with USD';
static BUY_WITH_BTC = 'Buy with Bitcoin';
static BUY_WITH_BTC = 'Buy with BTC';
static BUY_WITH_ETH = 'Buy with ETH';

buyTabs = [BuyDeSoComponent.BUY_WITH_BTC];
activeTab = BuyDeSoComponent.BUY_WITH_BTC;
buyTabs = [BuyDeSoComponent.BUY_WITH_MEGASWAP];
activeTab = BuyDeSoComponent.BUY_WITH_MEGASWAP;

constructor(
public ref: ChangeDetectorRef,
Expand Down Expand Up @@ -518,14 +519,18 @@ export class BuyDeSoComponent implements OnInit {
window.scroll(0, 0);

// Add extra tabs
if (this.globalVars.showBuyWithUSD) {
this.buyTabs.unshift(BuyDeSoComponent.BUY_WITH_USD);
this.activeTab = BuyDeSoComponent.BUY_WITH_USD;
}

if (this.globalVars.showBuyWithETH) {
this.buyTabs.push(BuyDeSoComponent.BUY_WITH_ETH);
}
this.route.params.subscribe((params) => {
const ticker = (params.ticker || '').toUpperCase();
if (ticker === 'BTC') {
this.buyTabs = [BuyDeSoComponent.BUY_WITH_BTC];
this.activeTab = BuyDeSoComponent.BUY_WITH_BTC
} else if (ticker === 'ETH' && this.globalVars.showBuyWithETH) {
this.buyTabs = [BuyDeSoComponent.BUY_WITH_ETH];
this.activeTab = BuyDeSoComponent.BUY_WITH_ETH;
} else if (this.globalVars.showBuyWithUSD) {
this.buyTabs.push(BuyDeSoComponent.BUY_WITH_USD);
}
});

// Query the website to get the fees.
this.backendApi.GetBitcoinFeeRateSatoshisPerKB().subscribe(
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.bitclout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export const environment = {
url: 'https://bitclout.com',
logoAssetDir: '/assets/bitclout/',
},
megaswapURL: 'https://megaswap.xyz',
};
1 change: 1 addition & 0 deletions src/environments/environment.deso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export const environment = {
url: 'https://node.deso.org',
logoAssetDir: '/assets/deso/',
},
megaswapURL: 'https://megaswap.xyz',
};
1 change: 1 addition & 0 deletions src/environments/environment.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export const environment = {
url: 'https://test.deso.org',
logoAssetDir: '/assets/deso/',
},
megaswapURL: 'https://megaswap.xyz',
};
1 change: 1 addition & 0 deletions src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export const environment = {
url: 'https://node.deso.org',
logoAssetDir: '/assets/deso/',
},
megaswapURL: 'https://megaswap.xyz',
};
1 change: 1 addition & 0 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export const environment = {
url: 'https://node.deso.org',
logoAssetDir: '/assets/deso/',
},
megaswapURL: 'https://megaswap.xyz',
};