forked from Koniverse/SubWallet-Extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'upgrade-ui' into master-to-webapp-1.1.18
- Loading branch information
Showing
34 changed files
with
423 additions
and
930 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
TRANSAK_API_KEY=4b767e2c-2e01-45c9-978e-d32c6f0c8900 | ||
COINBASE_PAY_ID=1dbd2a0b94 | ||
NFT_MINTING_HOST=http://... | ||
MARKETING_CAMPAIGN_URL=https://static-data.subwallet.app/marketing-campaigns/list.json | ||
BRANCH_NAME=master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/extension-base/src/services/buy-service/constants/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright 2019-2022 @subwallet/extension-base authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './token'; |
14 changes: 14 additions & 0 deletions
14
packages/extension-base/src/services/buy-service/constants/token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2019-2022 @subwallet/extension-base authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { BuyService, SupportService } from '@subwallet/extension-base/types'; | ||
|
||
const DEFAULT_BUY_SERVICE: BuyService = { symbol: '', network: '' }; | ||
|
||
export const DEFAULT_SERVICE_INFO: Record<SupportService, BuyService> = { | ||
transak: { ...DEFAULT_BUY_SERVICE }, | ||
banxa: { ...DEFAULT_BUY_SERVICE }, | ||
coinbase: { ...DEFAULT_BUY_SERVICE }, | ||
onramper: { ...DEFAULT_BUY_SERVICE }, | ||
moonpay: { ...DEFAULT_BUY_SERVICE } | ||
}; |
114 changes: 114 additions & 0 deletions
114
packages/extension-base/src/services/buy-service/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2019-2022 @subwallet/extension-base authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import KoniState from '@subwallet/extension-base/koni/background/handlers/State'; | ||
import { ListBuyServicesResponse, ListBuyTokenResponse } from '@subwallet/extension-base/services/buy-service/types'; | ||
import { BuyServiceInfo, BuyTokenInfo, SupportService } from '@subwallet/extension-base/types'; | ||
import { fetchStaticData } from '@subwallet/extension-base/utils/fetchStaticData'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
import { DEFAULT_SERVICE_INFO } from './constants'; | ||
|
||
export default class BuyService { | ||
readonly #state: KoniState; | ||
|
||
private buyTokensSubject = new BehaviorSubject<Record<string, BuyTokenInfo>>({}); | ||
private buyServicesSubject = new BehaviorSubject<Record<string, BuyServiceInfo>>({}); | ||
|
||
constructor (state: KoniState) { | ||
this.#state = state; | ||
|
||
this.buyTokensSubject.next({}); | ||
this.buyServicesSubject.next({}); | ||
|
||
this.fetchTokens() | ||
.catch((e) => { | ||
console.error('Error on fetch buy tokens', e); | ||
this.#state.eventService.emit('buy.tokens.ready', true); | ||
}); | ||
|
||
this.fetchServices() | ||
.catch((e) => { | ||
console.error('Error on fetch buy services', e); | ||
this.#state.eventService.emit('buy.services.ready', true); | ||
}); | ||
} | ||
|
||
private async fetchTokens () { | ||
const data = await fetchStaticData<ListBuyTokenResponse>('buy-token-configs'); | ||
|
||
const result: Record<string, BuyTokenInfo> = {}; | ||
|
||
for (const datum of data) { | ||
const temp: BuyTokenInfo = { | ||
serviceInfo: { | ||
...DEFAULT_SERVICE_INFO | ||
}, | ||
support: datum.support, | ||
services: [], | ||
slug: datum.slug, | ||
symbol: datum.symbol, | ||
network: datum.network | ||
}; | ||
|
||
for (const [_service, info] of Object.entries(datum.serviceInfo)) { | ||
const service = _service as SupportService; | ||
|
||
if (info.isSuspended) { | ||
continue; | ||
} | ||
|
||
temp.serviceInfo[service] = { | ||
network: info.network, | ||
symbol: info.symbol | ||
}; | ||
|
||
temp.services.push(service); | ||
} | ||
|
||
if (temp.services.length) { | ||
result[temp.slug] = temp; | ||
} | ||
} | ||
|
||
this.buyTokensSubject.next(result); | ||
|
||
this.#state.eventService.emit('buy.tokens.ready', true); | ||
} | ||
|
||
private async fetchServices () { | ||
const data = await fetchStaticData<ListBuyServicesResponse>('buy-service-infos'); | ||
|
||
const result: Record<string, BuyServiceInfo> = {}; | ||
|
||
for (const datum of data) { | ||
const { id, slug, ...info } = datum; | ||
|
||
result[slug] = { ...info }; | ||
} | ||
|
||
this.buyServicesSubject.next(result); | ||
|
||
this.#state.eventService.emit('buy.services.ready', true); | ||
} | ||
|
||
public subscribeBuyTokens (callback: (data: Record<string, BuyTokenInfo>) => void) { | ||
return this.buyTokensSubject.subscribe({ | ||
next: callback | ||
}); | ||
} | ||
|
||
public getBuyTokens () { | ||
return this.buyTokensSubject.getValue(); | ||
} | ||
|
||
public subscribeBuyServices (callback: (data: Record<string, BuyServiceInfo>) => void) { | ||
return this.buyServicesSubject.subscribe({ | ||
next: callback | ||
}); | ||
} | ||
|
||
public getBuyServices () { | ||
return this.buyServicesSubject.getValue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { BuyService, BuyTokenInfo, SupportService } from '@subwallet/extension-base/types'; | ||
|
||
interface _BuyTokenInfo { | ||
serviceInfo: Record<string, BuyService & { isSuspended: boolean }>; | ||
network: string; | ||
slug: string; | ||
symbol: string; | ||
support: BuyTokenInfo['support']; | ||
} | ||
|
||
interface _BuyServiceInfo { | ||
id: number; | ||
name: string; | ||
contactUrl: string; | ||
termUrl: string; | ||
policyUrl: string; | ||
url: string; | ||
slug: SupportService; | ||
} | ||
|
||
export type ListBuyTokenResponse = _BuyTokenInfo[]; | ||
export type ListBuyServicesResponse = _BuyServiceInfo[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.