import * as React from 'react' import classNames from 'classnames' import { Network } from '@dcl/schemas' import { getNetworkMANADescription } from '../../lib/network' import { Button } from '../Button/Button' import './Network.css' export enum NetworkGatewayType { MOON_PAY = 'moonPay', TRANSAK = 'transak' } export type GatewaysNames = { [key in NetworkGatewayType]: string } export const gatewaysNames: GatewaysNames = { [NetworkGatewayType.MOON_PAY]: 'MoonPay', [NetworkGatewayType.TRANSAK]: 'Transak' } export type BuyWithFiatNetworkProps = { className?: string message?: React.ReactNode open?: boolean i18n?: NetworkI18N type: Network gateways: Omit[] onClose?: () => void onInfo?: () => void onBack?: () => void } export type NetworkGatewayProps = { type: NetworkGatewayType network: Network learnMoreLink?: string i18n?: NetworkGatewayI18N disabled?: boolean onContinue: () => void } export type NetworkI18N = { title: React.ReactNode error: React.ReactNode } export type NetworkGatewayI18N = { title: React.ReactNode subtitle: React.ReactNode continueButtonText: React.ReactNode learnMoreText: React.ReactNode } class ButWithFiatNetworkGateway extends React.PureComponent { render(): JSX.Element { const { type, network, i18n, learnMoreLink, disabled = false, onContinue } = this.props const title: React.ReactNode = `Buy ${getNetworkMANADescription( network )} with ${gatewaysNames[type]}` const subtitle: React.ReactNode = 'You can buy with debit and credit cards, Apple Pay, Google Pay, or via bank transfer.' const continueButtonText: React.ReactNode = `Continue with ${gatewaysNames[type]}` return (
{i18n?.title || title}
{i18n?.subtitle || subtitle}
{i18n?.learnMoreText ? ( {i18n?.learnMoreText} ) : ( Learn more {` about ${gatewaysNames[type]}`} )}
) } } export class BuyWithFiatNetwork extends React.Component { static Gateway = ButWithFiatNetworkGateway enabledFirst( { disabled: disabledA = false }, { disabled: disabledB = false } ): number { return Number(disabledA) - Number(disabledB) } render(): JSX.Element { const { type, gateways } = this.props return (
{gateways.sort(this.enabledFirst).map((gatewayProps) => ( ))}
) } }