Skip to content

Commit d42cc1f

Browse files
authored
Mf/add buy deso with megaswap tab (#610)
* Add buy DESO with MegaSwap tab. * Remove empty div element. * Center tabs. * Make Buy w BTC and Buy w ETH their own pages. * Make tabs more consistent. * Wrap iframe in row/col. * Make iframe sizing more responsive. * Fix height issue. * Use GH pages link for now. * Support other themes. * Add links to megaswap.xyz. * Update URL to megaswap.xyz. * Add x padding. * Remove x padding.
1 parent 89babe7 commit d42cc1f

14 files changed

+147
-11
lines changed

Caddyfile

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ header @html Content-Security-Policy "
3737
https://altumbase.com
3838
localhost:*
3939
explorer.bitclout.com
40+
megaswap.dev
41+
megaswap.xyz
4042
https://api.blockchain.com/ticker
4143
https://api.blockchain.com/mempool/fees
4244
https://ka-f.fontawesome.com/
@@ -80,6 +82,8 @@ header @html Content-Security-Policy "
8082
identity.bitclout.com
8183
identity.bitclout.blue
8284
identity.bitclout.green
85+
megaswap.dev
86+
megaswap.xyz
8387
https://geo.captcha-delivery.com
8488
https://www.youtube.com
8589
https://youtube.com

src/app/app-routing.module.ts

+5
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ const routes: Routes = [
112112
component: BuyDeSoPageComponent,
113113
pathMatch: 'full',
114114
},
115+
{
116+
path: RouteNames.BUY_DESO + '/:ticker',
117+
component: BuyDeSoPageComponent,
118+
pathMatch: 'full',
119+
},
115120
{
116121
path: RouteNames.PICK_A_COIN,
117122
component: PickACoinPageComponent,

src/app/app.module.ts

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { LeftBarButtonComponent } from './left-bar/left-bar-button/left-bar-butt
4141
import { TradeCreatorPageComponent } from './trade-creator-page/trade-creator-page.component';
4242
import { TradeCreatorComponent } from './trade-creator-page/trade-creator/trade-creator.component';
4343
import { BuyDeSoComponent } from './buy-deso-page/buy-deso/buy-deso.component';
44+
import { BuyDeSoMegaSwapComponent } from './buy-deso-page/buy-deso-megaswap/buy-deso-megaswap.component';
4445
import { BuyDeSoUSDComponent } from './buy-deso-page/buy-deso-usd/buy-deso-usd.component';
4546
import { TradeCreatorFormComponent } from './trade-creator-page/trade-creator-form/trade-creator-form.component';
4647
import { TradeCreatorPreviewComponent } from './trade-creator-page/trade-creator-preview/trade-creator-preview.component';
@@ -212,6 +213,7 @@ const greenishTheme: Theme = { key: 'greenish', name: 'Green Theme' };
212213
TradeCreatorPageComponent,
213214
TradeCreatorComponent,
214215
BuyDeSoComponent,
216+
BuyDeSoMegaSwapComponent,
215217
BuyDeSoUSDComponent,
216218
TradeCreatorFormComponent,
217219
TradeCreatorPreviewComponent,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<div class="vh-75">
2+
<p class="mb-2 px-3 fs-7 text-muted">
3+
<i class="fas fa-info-circle"></i>
4+
Swap from BTC, ETH, SOL, and other chains to DESO using MegaSwap.
5+
The legacy <a [routerLink]="'/' + globalVars.RouteNames.BUY_DESO + '/BTC'">Buy with BTC</a>
6+
<span *ngIf="globalVars.showBuyWithETH; else elseBlockInfo">
7+
and <a [routerLink]="'/' + globalVars.RouteNames.BUY_DESO + '/ETH'">Buy with ETH</a> flows are
8+
</span>
9+
<ng-template #elseBlockInfo>
10+
flow is
11+
</ng-template>
12+
still accessible but being deprecated.
13+
</p>
14+
15+
<iframe
16+
*ngIf="iframeURL; else elseBlockIframe"
17+
[src]="iframeURL"
18+
class="border-0 rounded w-100 h-100"
19+
></iframe>
20+
<ng-template #elseBlockIframe>
21+
<p class="fs-8 text-danger text-center">
22+
<i class="fas fa-exclamation-triangle"></i> Unable to render iFrame.<br />Invalid MegaSwap URL.
23+
</p>
24+
</ng-template>
25+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.fs-7 {
2+
font-size: 0.7rem;
3+
}
4+
5+
.fs-8 {
6+
font-size: 0.8rem;
7+
}
8+
9+
.vh-75 {
10+
height: 75vh;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { BuyDeSoMegaSwapComponent } from './buy-deso-megaswap.component';
4+
5+
describe('BuyDeSoMegaSwapComponent', () => {
6+
let component: BuyDeSoMegaSwapComponent;
7+
let fixture: ComponentFixture<BuyDeSoMegaSwapComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [BuyDeSoMegaSwapComponent],
12+
}).compileComponents();
13+
}));
14+
15+
beforeEach(() => {
16+
fixture = TestBed.createComponent(BuyDeSoMegaSwapComponent);
17+
component = fixture.componentInstance;
18+
fixture.detectChanges();
19+
});
20+
21+
it('should create', () => {
22+
expect(component).toBeTruthy();
23+
});
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { DomSanitizer, SafeResourceUrl, Title } from '@angular/platform-browser';
3+
import { GlobalVarsService } from 'src/app/global-vars.service';
4+
import { environment } from 'src/environments/environment';
5+
6+
@Component({
7+
selector: 'buy-deso-megaswap',
8+
templateUrl: './buy-deso-megaswap.component.html',
9+
styleUrls: ['./buy-deso-megaswap.component.scss'],
10+
})
11+
export class BuyDeSoMegaSwapComponent implements OnInit {
12+
iframeURL: SafeResourceUrl = '';
13+
14+
constructor(
15+
public globalVars: GlobalVarsService,
16+
private sanitizer: DomSanitizer,
17+
) {
18+
if (!environment.megaswapURL) {
19+
return;
20+
}
21+
22+
// Map theme to MegaSwap theme.
23+
let theme = {
24+
'cake': 'light-peach',
25+
'dark': 'dark-gray',
26+
'greenish': 'dark-green',
27+
'icydark': 'dark-icy',
28+
'legends': 'dark-brown',
29+
'light': 'light-white',
30+
}[localStorage.getItem('theme')] || 'default';
31+
32+
if (theme === 'default' && window.matchMedia('(prefers-color-scheme: dark)').matches) {
33+
theme = 'dark-gray';
34+
}
35+
36+
this.iframeURL = this.sanitizer.bypassSecurityTrustResourceUrl(
37+
[
38+
environment.megaswapURL,
39+
'/#/iframe/v1?',
40+
`network=${environment.production ? 'mainnet' : 'testnet'}`,
41+
`&theme=${theme}`,
42+
'&destinationTickers=DESO',
43+
'&destinationTicker=DESO',
44+
`&destinationAddress=${this.globalVars.loggedInUser?.PublicKeyBase58Check || ''}`,
45+
].join('')
46+
);
47+
}
48+
49+
ngOnInit() {
50+
window.scroll(0, 0);
51+
}
52+
}

src/app/buy-deso-page/buy-deso/buy-deso.component.html

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
(tabClick)="_handleTabClick($event)"
2626
></tab-selector>
2727
</div>
28+
<div *ngIf="activeTab === BuyDeSoComponent.BUY_WITH_MEGASWAP">
29+
<buy-deso-megaswap></buy-deso-megaswap>
30+
</div>
2831
<div *ngIf="activeTab === BuyDeSoComponent.BUY_WITH_USD">
2932
<buy-deso-usd></buy-deso-usd>
3033
</div>

src/app/buy-deso-page/buy-deso/buy-deso.component.ts

+16-11
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ export class BuyDeSoComponent implements OnInit {
4343

4444
BuyDeSoComponent = BuyDeSoComponent;
4545

46+
static BUY_WITH_MEGASWAP = 'Buy with Crypto';
4647
static BUY_WITH_USD = 'Buy with USD';
47-
static BUY_WITH_BTC = 'Buy with Bitcoin';
48+
static BUY_WITH_BTC = 'Buy with BTC';
4849
static BUY_WITH_ETH = 'Buy with ETH';
4950

50-
buyTabs = [BuyDeSoComponent.BUY_WITH_BTC];
51-
activeTab = BuyDeSoComponent.BUY_WITH_BTC;
51+
buyTabs = [BuyDeSoComponent.BUY_WITH_MEGASWAP];
52+
activeTab = BuyDeSoComponent.BUY_WITH_MEGASWAP;
5253

5354
constructor(
5455
public ref: ChangeDetectorRef,
@@ -518,14 +519,18 @@ export class BuyDeSoComponent implements OnInit {
518519
window.scroll(0, 0);
519520

520521
// Add extra tabs
521-
if (this.globalVars.showBuyWithUSD) {
522-
this.buyTabs.unshift(BuyDeSoComponent.BUY_WITH_USD);
523-
this.activeTab = BuyDeSoComponent.BUY_WITH_USD;
524-
}
525-
526-
if (this.globalVars.showBuyWithETH) {
527-
this.buyTabs.push(BuyDeSoComponent.BUY_WITH_ETH);
528-
}
522+
this.route.params.subscribe((params) => {
523+
const ticker = (params.ticker || '').toUpperCase();
524+
if (ticker === 'BTC') {
525+
this.buyTabs = [BuyDeSoComponent.BUY_WITH_BTC];
526+
this.activeTab = BuyDeSoComponent.BUY_WITH_BTC
527+
} else if (ticker === 'ETH' && this.globalVars.showBuyWithETH) {
528+
this.buyTabs = [BuyDeSoComponent.BUY_WITH_ETH];
529+
this.activeTab = BuyDeSoComponent.BUY_WITH_ETH;
530+
} else if (this.globalVars.showBuyWithUSD) {
531+
this.buyTabs.push(BuyDeSoComponent.BUY_WITH_USD);
532+
}
533+
});
529534

530535
// Query the website to get the fees.
531536
this.backendApi.GetBitcoinFeeRateSatoshisPerKB().subscribe(

src/environments/environment.bitclout.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ export const environment = {
2121
url: 'https://bitclout.com',
2222
logoAssetDir: '/assets/bitclout/',
2323
},
24+
megaswapURL: 'https://megaswap.xyz',
2425
};

src/environments/environment.deso.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ export const environment = {
2121
url: 'https://node.deso.org',
2222
logoAssetDir: '/assets/deso/',
2323
},
24+
megaswapURL: 'https://megaswap.xyz',
2425
};

src/environments/environment.dev.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ export const environment = {
2121
url: 'https://test.deso.org',
2222
logoAssetDir: '/assets/deso/',
2323
},
24+
megaswapURL: 'https://megaswap.xyz',
2425
};

src/environments/environment.prod.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ export const environment = {
2121
url: 'https://node.deso.org',
2222
logoAssetDir: '/assets/deso/',
2323
},
24+
megaswapURL: 'https://megaswap.xyz',
2425
};

src/environments/environment.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ export const environment = {
2525
url: 'https://node.deso.org',
2626
logoAssetDir: '/assets/deso/',
2727
},
28+
megaswapURL: 'https://megaswap.xyz',
2829
};

0 commit comments

Comments
 (0)