mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 08:32:39 +03:00
Fix issues with bridge and external invoices
This commit is contained in:
parent
c9a508c653
commit
eb5d026df4
@ -25,10 +25,18 @@ type Props = {
|
||||
};
|
||||
|
||||
const BridgeInvoice: React.FC<Props> = ({ payee, stopSending, satsAmount }) => {
|
||||
const { error, currencyRates, fee, broadcastSuccess, denomination, psbt } =
|
||||
useSettings();
|
||||
const {
|
||||
error,
|
||||
currencyRates,
|
||||
fee,
|
||||
broadcastSuccess,
|
||||
denomination,
|
||||
psbt,
|
||||
history,
|
||||
} = useSettings();
|
||||
const [txHex, setTxHex] = useState('');
|
||||
const [ready, setReady] = useState(false);
|
||||
const [historyLength, setHistoryLength] = useState(0);
|
||||
const [localError, setLocalError] = useState('');
|
||||
const [broadcasting, setBroadcasting] = useState(false);
|
||||
const invoiceRef = useRef();
|
||||
@ -44,7 +52,17 @@ const BridgeInvoice: React.FC<Props> = ({ payee, stopSending, satsAmount }) => {
|
||||
|
||||
useEffect(() => {
|
||||
window.open('https://bridge.urbit.org/?kind=btc&utx=' + psbt);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (historyLength === 0) {
|
||||
setHistoryLength(history.length);
|
||||
}
|
||||
if (broadcasting && history.length > historyLength) {
|
||||
setBroadcasting(false);
|
||||
stopSending();
|
||||
}
|
||||
}, [history]);
|
||||
|
||||
const broadCastTx = (hex: string) => {
|
||||
let command = {
|
||||
@ -65,9 +83,14 @@ const BridgeInvoice: React.FC<Props> = ({ payee, stopSending, satsAmount }) => {
|
||||
};
|
||||
|
||||
const checkTxHex = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setTxHex(e.target.value);
|
||||
setReady(txHex.length > 0);
|
||||
setLocalError('');
|
||||
// TODO: validate this hex with something other than length check.
|
||||
if (e.target.value.length > 0) {
|
||||
setTxHex(e.target.value);
|
||||
setReady(true);
|
||||
setLocalError('');
|
||||
} else {
|
||||
setLocalError('Invalid transaction hex');
|
||||
}
|
||||
};
|
||||
|
||||
let inputColor = 'black';
|
||||
|
@ -29,10 +29,18 @@ const ExternalInvoice: React.FC<Props> = ({
|
||||
stopSending,
|
||||
satsAmount,
|
||||
}) => {
|
||||
const { error, currencyRates, fee, broadcastSuccess, denomination, psbt } =
|
||||
useSettings();
|
||||
const {
|
||||
error,
|
||||
currencyRates,
|
||||
fee,
|
||||
broadcastSuccess,
|
||||
denomination,
|
||||
psbt,
|
||||
history,
|
||||
} = useSettings();
|
||||
const [txHex, setTxHex] = useState('');
|
||||
const [ready, setReady] = useState(false);
|
||||
const [historyLength, setHistoryLength] = useState(0);
|
||||
const [localError, setLocalError] = useState('');
|
||||
const [broadcasting, setBroadcasting] = useState(false);
|
||||
const invoiceRef = useRef();
|
||||
@ -46,6 +54,16 @@ const ExternalInvoice: React.FC<Props> = ({
|
||||
}
|
||||
}, [error, broadcasting, setBroadcasting]);
|
||||
|
||||
useEffect(() => {
|
||||
if (historyLength === 0) {
|
||||
setHistoryLength(history.length);
|
||||
}
|
||||
if (broadcasting && history.length > historyLength) {
|
||||
setBroadcasting(false);
|
||||
stopSending();
|
||||
}
|
||||
}, [history]);
|
||||
|
||||
const broadCastTx = (hex: string) => {
|
||||
let command = {
|
||||
'broadcast-tx': hex,
|
||||
@ -65,9 +83,14 @@ const ExternalInvoice: React.FC<Props> = ({
|
||||
};
|
||||
|
||||
const checkTxHex = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setTxHex(e.target.value);
|
||||
setReady(txHex.length > 0);
|
||||
setLocalError('');
|
||||
// TODO: validate this hex with something other than length check.
|
||||
if (e.target.value.length > 0) {
|
||||
setTxHex(e.target.value);
|
||||
setReady(true);
|
||||
setLocalError('');
|
||||
} else {
|
||||
setLocalError('Invalid transaction hex');
|
||||
}
|
||||
};
|
||||
|
||||
const copyPsbt = () => {
|
||||
|
Loading…
Reference in New Issue
Block a user