on master help sign in
flows: add flow for bitcoin view
79c674bfang
src/lib/flowCommand.js+11−9
@@ -1,19 +1,13 @@
1−import ob from 'urbit-ob';
2−
3−import { ensurePatFormat } from 'form/formatters';
4−
5// looks into the GET parameters and attempts to construct a "flow" object,
1// looks into the GET parameters and attempts to construct a "flow" object,
6// which would indicate bridge is to be used for one specific flow.
2// which would indicate bridge is to be used for one specific flow.
7// expects to find any of the following sets of parameters, varying by kind.
3// expects to find any of the following sets of parameters, varying by kind.
8//
4//
9−// ? kind = invite
5+// ? kind = btc
10−// & as = ~ship // who to send the invite as
6+// & utx = somebase64string
11−// & ship = ~ship // what planet to send as the invite
12−// & email = ex@amp.le // email to send the invite code to
13//
7//
14
8
15const COMMANDS = {
9const COMMANDS = {
16− //
10+ BITCOIN: 'btc',
17};
11};
18
12
19const useFlowCommand = () => {
13const useFlowCommand = () => {
@@ -29,6 +23,14 @@ const useFlowCommand = () => {
29
23
30 if (typeof flow === 'object') {
24 if (typeof flow === 'object') {
31 switch (flow.kind) {
25 switch (flow.kind) {
26+ case COMMANDS.BITCOIN:
27+ try {
28+ atob(flow.utx);
29+ } catch (e) {
30+ flow = null;
31+ }
32+ break;
33+ //
32 default:
34 default:
33 console.log('unrecognized kind of flow:', flow.kind);
35 console.log('unrecognized kind of flow:', flow.kind);
34 // eslint-disable-next-line no-fallthrough
36 // eslint-disable-next-line no-fallthrough
src/lib/validators.js+8−6
@@ -143,18 +143,20 @@ export const validatePsbt = base64 => {
143};
143};
144
144
145export const validateSignablePsbt = btcWallet => base64 => {
145export const validateSignablePsbt = btcWallet => base64 => {
146− const psbt = bitcoin.Psbt.fromBase64(base64);
146+ const psbt = bitcoin.Psbt.fromBase64(base64);
147+ return !(
147− return !psbt.data.inputs.some((input, idx) => {
148+ psbt.data.inputs.some((input, idx) => {
148 try {
149 try {
149 // removing already derived part, eg m/84'/0'/0'/0/0 becomes 0/0
150 // removing already derived part, eg m/84'/0'/0'/0/0 becomes 0/0
150 const path = input.bip32Derivation[0].path
151 const path = input.bip32Derivation[0].path
151− .split("m/84'/0'/0'/")
152+ .split("m/84'/0'/0'/")
152− .join('');
153+ .join('');
153 const prv = btcWallet.derivePath(path).privateKey;
154 const prv = btcWallet.derivePath(path).privateKey;
154 psbt.signInput(idx, bitcoin.ECPair.fromPrivateKey(prv));
155 psbt.signInput(idx, bitcoin.ECPair.fromPrivateKey(prv));
155 return true;
156 return true;
156 } catch (e) {
157 } catch (e) {
157 return false;
158 return false;
158 }
159 }
159− }) && 'No inputs were signed';
160+ }) && 'No inputs were signed'
161+ );
160− };
162+};
src/views/Bitcoin/SignTransaction.js+11−1
@@ -2,6 +2,7 @@ import React, { useState } from 'react';
2import { Grid, Text } from 'indigo-react';
2import { Grid, Text } from 'indigo-react';
3
3
4import { useLocalRouter } from 'lib/LocalRouter';
4import { useLocalRouter } from 'lib/LocalRouter';
5+import { COMMANDS, useFlowCommand } from 'lib/flowCommand';
5
6
6import View from 'components/View';
7import View from 'components/View';
7import Highlighted from 'components/Highlighted';
8import Highlighted from 'components/Highlighted';
@@ -23,6 +24,7 @@ import { composeValidator, buildPsbtValidator } from 'form/validators';
23export default function SignTransaction() {
24export default function SignTransaction() {
24 const { pop } = useLocalRouter();
25 const { pop } = useLocalRouter();
25 const { urbitWallet } = useWallet();
26 const { urbitWallet } = useWallet();
27+ const flow = useFlowCommand();
26
28
27 const [signedTx, setSignedTx] = useState('');
29 const [signedTx, setSignedTx] = useState('');
28 const [psbt, setPsbt] = useState({});
30 const [psbt, setPsbt] = useState({});
@@ -64,13 +66,21 @@ export default function SignTransaction() {
64 setSignedTx(hex);
66 setSignedTx(hex);
65 };
67 };
66
68
69+ const initialValues = {};
70+ if (COMMANDS.BITCOIN === flow.kind) {
71+ initialValues.unsignedTransaction = flow.utx;
72+ }
73+
67 return (
74 return (
68 <View pop={pop} inset>
75 <View pop={pop} inset>
69 <Grid className="mt4">
76 <Grid className="mt4">
70 <Grid.Item full className="mt4" as={Text}>
77 <Grid.Item full className="mt4" as={Text}>
71 Paste unsigned transactions from Landscape here
78 Paste unsigned transactions from Landscape here
72 </Grid.Item>
79 </Grid.Item>
80+ <BridgeForm
73− <BridgeForm validate={validate} onSubmit={onSubmit}>
81+ validate={validate}
82+ initialValues={initialValues}
83+ onSubmit={onSubmit}>
74 {({ handleSubmit }) => (
84 {({ handleSubmit }) => (
75 <>
85 <>
76 <Grid.Item
86 <Grid.Item
src/views/Login.js+7
@@ -61,6 +61,10 @@ export default function Login() {
61 push(names.POINTS);
61 push(names.POINTS);
62 } else {
62 } else {
63 switch (flow.kind) {
63 switch (flow.kind) {
64+ case COMMANDS.BITCOIN:
65+ push(names.BITCOIN_SIGN_TRANSACTION);
66+ break;
67+ //
64 default:
68 default:
65 throw new Error('unimplemented flow ' + flow.kind);
69 throw new Error('unimplemented flow ' + flow.kind);
66 }
70 }
@@ -69,6 +73,9 @@ export default function Login() {
69
73
70 const flowDescription = command => {
74 const flowDescription = command => {
71 switch (command.kind) {
75 switch (command.kind) {
76+ case COMMANDS.BITCOIN:
77+ return <>To sign a Bitcoin transaction, please sign in.</>;
78+ //
72 default:
79 default:
73 return <>Flow: {command.kind}</>;
80 return <>Flow: {command.kind}</>;
74 }
81 }