diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-05-08 04:53:26 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-05-08 04:53:26 +0200 |
commit | 6904c2759ec75ab9c3a5ace358a20c582dfa1a1b (patch) | |
tree | ee9f6790f390c44219f5d0fd775199e58c78772d /src/webex | |
parent | 3db38fbd0b84d066d64f9b637f1efcc35ebf8ce3 (diff) |
implement payto URIs
Diffstat (limited to 'src/webex')
-rw-r--r-- | src/webex/pages/confirm-create-reserve.tsx | 40 | ||||
-rw-r--r-- | src/webex/wxApi.ts | 2 |
2 files changed, 25 insertions, 17 deletions
diff --git a/src/webex/pages/confirm-create-reserve.tsx b/src/webex/pages/confirm-create-reserve.tsx index cef647163..2d4f41dfe 100644 --- a/src/webex/pages/confirm-create-reserve.tsx +++ b/src/webex/pages/confirm-create-reserve.tsx @@ -92,7 +92,7 @@ interface ExchangeSelectionProps { callback_url: string; wt_types: string[]; currencyRecord: CurrencyRecord|null; - sender_wire: object | undefined; + sender_wire: string | undefined; } interface ManualSelectionProps { @@ -410,7 +410,7 @@ class ExchangeSelection extends ImplicitStateComponent<ExchangeSelectionProps> { exchange: string, amount: AmountJson, callback_url: string, - sender_wire: object | undefined) { + sender_wire: string | undefined) { const rawResp = await createReserve({ amount, exchange: canonicalizeBaseUrl(exchange), @@ -420,21 +420,25 @@ class ExchangeSelection extends ImplicitStateComponent<ExchangeSelectionProps> { throw Error("empty response"); } // FIXME: filter out types that bank/exchange don't have in common - const wireDetails = rci.wireInfo; - const filteredWireDetails: any = {}; - for (const wireType in wireDetails) { - if (this.props.wt_types.findIndex((x) => x.toLowerCase() === wireType.toLowerCase()) < 0) { + const exchangeWireAccounts = []; + + for (let acct of rci.exchangeWireAccounts) { + const payto = new URI(acct); + if (payto.scheme() != "payto") { + console.warn("unknown wire account URI scheme", acct); continue; } - const obj = Object.assign({}, wireDetails[wireType]); - // The bank doesn't need to know about fees - delete obj.fees; - // Consequently the bank can't verify signatures anyway, so - // we delete this extra data, to make the request URL shorter. - delete obj.salt; - delete obj.sig; - filteredWireDetails[wireType] = obj; + if (this.props.wt_types.includes(payto.authority())) { + exchangeWireAccounts.push(acct); + } } + + const chosenAcct = exchangeWireAccounts[0]; + + if (!chosenAcct) { + throw Error("no exchange account matches the bank's supported types"); + } + if (!rawResp.error) { const resp = CreateReserveResponse.checked(rawResp); const q: {[name: string]: string|number} = { @@ -442,7 +446,7 @@ class ExchangeSelection extends ImplicitStateComponent<ExchangeSelectionProps> { amount_fraction: amount.fraction, amount_value: amount.value, exchange: resp.exchange, - exchange_wire_details: JSON.stringify(filteredWireDetails), + exchange_wire_details: chosenAcct, reserve_pub: resp.reservePub, }; const url = new URI(callback_url).addQuery(q); @@ -487,7 +491,11 @@ async function main() { let sender_wire; if (query.sender_wire) { - sender_wire = JSON.parse(query.sender_wire); + let senderWireUri = new URI(query.sender_wire); + if (senderWireUri.scheme() != "payto") { + throw Error("sender wire info must be a payto URI"); + } + sender_wire = query.sender_wire; } const suggestedExchangeUrl = query.suggested_exchange_url; diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts index fde7b8c35..4f7500368 100644 --- a/src/webex/wxApi.ts +++ b/src/webex/wxApi.ts @@ -273,7 +273,7 @@ export function checkUpgrade(): Promise<UpgradeResponse> { /** * Create a reserve. */ -export function createReserve(args: { amount: AmountJson, exchange: string, senderWire?: object }): Promise<any> { +export function createReserve(args: { amount: AmountJson, exchange: string, senderWire?: string }): Promise<any> { return callBackend("create-reserve", args); } |