From 732e764b376dff6b0262b869b29dbdee0c455a0e Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Jul 2020 23:17:12 +0530 Subject: new balances API, remove defunct 'return funds to own account' implementation --- src/webex/pages/return-coins.tsx | 287 +-------------------------------------- 1 file changed, 1 insertion(+), 286 deletions(-) (limited to 'src/webex/pages/return-coins.tsx') diff --git a/src/webex/pages/return-coins.tsx b/src/webex/pages/return-coins.tsx index ccdb6db53..e8cf8c9dd 100644 --- a/src/webex/pages/return-coins.tsx +++ b/src/webex/pages/return-coins.tsx @@ -23,293 +23,8 @@ /** * Imports. */ - -import { AmountJson } from "../../util/amounts"; -import { Amounts } from "../../util/amounts"; - -import { SenderWireInfos, WalletBalance } from "../../types/walletTypes"; - -import * as i18n from "../i18n"; - -import * as wire from "../../util/wire"; - -import { getBalance, getSenderWireInfos, returnCoins } from "../wxApi"; - -import { renderAmount } from "../renderHtml"; - import * as React from "react"; -interface ReturnSelectionItemProps extends ReturnSelectionListProps { - exchangeUrl: string; - senderWireInfos: SenderWireInfos; -} - -interface ReturnSelectionItemState { - selectedValue: string; - supportedWires: string[]; - selectedWire: string; - currency: string; -} - -class ReturnSelectionItem extends React.Component< - ReturnSelectionItemProps, - ReturnSelectionItemState -> { - constructor(props: ReturnSelectionItemProps) { - super(props); - const exchange = this.props.exchangeUrl; - const wireTypes = this.props.senderWireInfos.exchangeWireTypes; - const supportedWires = this.props.senderWireInfos.senderWires.filter( - (x) => { - return ( - wireTypes[exchange] && - wireTypes[exchange].indexOf((x as any).type) >= 0 - ); - }, - ); - this.state = { - currency: props.balance.byExchange[props.exchangeUrl].available.currency, - selectedValue: Amounts.stringify( - props.balance.byExchange[props.exchangeUrl].available, - ), - selectedWire: "", - supportedWires, - }; - } - render(): JSX.Element { - const exchange = this.props.exchangeUrl; - const byExchange = this.props.balance.byExchange; - const wireTypes = this.props.senderWireInfos.exchangeWireTypes; - return ( -
-

Exchange {exchange}

-

Available amount: {renderAmount(byExchange[exchange].available)}

-

- Supported wire methods:{" "} - {wireTypes[exchange].length ? wireTypes[exchange].join(", ") : "none"} -

-

- Wire {""} - - this.setState({ selectedValue: evt.target.value }) - } - style={{ textAlign: "center" }} - />{" "} - {this.props.balance.byExchange[exchange].available.currency} {""} - to account {""} - - . -

- {this.state.selectedWire ? ( - - ) : null} -
- ); - } - - select(): void { - let val: number; - let selectedWire: number; - try { - val = Number.parseFloat(this.state.selectedValue); - selectedWire = Number.parseInt(this.state.selectedWire); - } catch (e) { - console.error(e); - return; - } - this.props.selectDetail({ - amount: Amounts.fromFloat(val, this.state.currency), - exchange: this.props.exchangeUrl, - senderWire: this.state.supportedWires[selectedWire], - }); - } -} - -interface ReturnSelectionListProps { - balance: WalletBalance; - senderWireInfos: SenderWireInfos; - selectDetail(d: SelectedDetail): void; -} - -class ReturnSelectionList extends React.Component< - ReturnSelectionListProps, - {} -> { - render(): JSX.Element { - const byExchange = this.props.balance.byExchange; - const exchanges = Object.keys(byExchange); - if (!exchanges.length) { - return ( -

Currently no funds available to transfer.

- ); - } - return ( -
- {exchanges.map((e) => ( - - ))} -
- ); - } -} - -interface SelectedDetail { - amount: AmountJson; - senderWire: any; - exchange: string; -} - -interface ReturnConfirmationProps { - detail: SelectedDetail; - cancel(): void; - confirm(): void; -} - -class ReturnConfirmation extends React.Component { - render(): JSX.Element { - return ( -
-

- Please confirm if you want to transmit{" "} - {renderAmount(this.props.detail.amount)} at {""} - {this.props.detail.exchange} to account {""} - - {wire.summarizeWire(this.props.detail.senderWire)} - - . -

- - -
- ); - } -} - -interface ReturnCoinsState { - balance: WalletBalance | undefined; - senderWireInfos: SenderWireInfos | undefined; - selectedReturn: SelectedDetail | undefined; - /** - * Last confirmed detail, so we can show a nice box. - */ - lastConfirmedDetail: SelectedDetail | undefined; -} - -class ReturnCoins extends React.Component<{}, ReturnCoinsState> { - constructor(props: {}) { - super(props); - const port = chrome.runtime.connect(); - port.onMessage.addListener((msg: any) => { - if (msg.notify) { - console.log("got notified"); - this.update(); - } - }); - this.update(); - this.state = {} as any; - } - - async update(): Promise { - const balance = await getBalance(); - const senderWireInfos = await getSenderWireInfos(); - console.log("got swi", senderWireInfos); - console.log("got bal", balance); - this.setState({ balance, senderWireInfos }); - } - - selectDetail(d: SelectedDetail): void { - this.setState({ selectedReturn: d }); - } - - async confirm(): Promise { - const selectedReturn = this.state.selectedReturn; - if (!selectedReturn) { - return; - } - await returnCoins(selectedReturn); - await this.update(); - this.setState({ - selectedReturn: undefined, - lastConfirmedDetail: selectedReturn, - }); - } - - async cancel(): Promise { - this.setState({ - selectedReturn: undefined, - lastConfirmedDetail: undefined, - }); - } - - render(): JSX.Element { - const balance = this.state.balance; - const senderWireInfos = this.state.senderWireInfos; - if (!balance || !senderWireInfos) { - return ...; - } - if (this.state.selectedReturn) { - return ( -
- this.cancel()} - confirm={() => this.confirm()} - /> -
- ); - } - return ( -
-

Wire electronic cash back to own bank account

-

- You can send coins back into your own bank account. Note that - you're acting as a merchant when doing this, and thus the same - fees apply. -

- {this.state.lastConfirmedDetail ? ( -

- Transfer of {renderAmount(this.state.lastConfirmedDetail.amount)}{" "} - successfully initiated. -

- ) : null} - this.selectDetail(d)} - balance={balance} - senderWireInfos={senderWireInfos} - /> -
- ); - } -} - export function createReturnCoinsPage(): JSX.Element { - return ; + return Not implemented yet.; } -- cgit v1.2.3