btc: fix issue with channel-js resubscribes

This commit is contained in:
Isaac Visintainer 2021-04-21 18:34:16 -07:00 committed by ixv
parent 62afe28f3f
commit 99a44640f0
3 changed files with 18 additions and 12 deletions

View File

@ -8,18 +8,16 @@ import './css/indigo-static.css';
import './css/fonts.css';
import './css/custom.css';
api.setAuthTokens({
ship: window.ship
});
window.NETWORK = 'testnet'; // 'bitcoin'
window.urb = new window.channel();
const channel = new window.channel();
api.setChannel(window.ship, channel);
subscription.start();
if (module.hot) {
module.hot.accept()
}
ReactDOM.render((
<Root />
<Root channel={channel}/>
), document.querySelectorAll("#root")[0]);

View File

@ -1,15 +1,16 @@
import _ from 'lodash';
class UrbitApi {
setAuthTokens(authTokens) {
this.authTokens = authTokens;
setChannel(ship, channel) {
this.ship = ship;
this.channel = channel;
this.bindPaths = [];
}
bind(path, method, ship = this.authTokens.ship, appl = "btc-wallet", success, fail) {
bind(path, method, ship = this.ship, appl = "btc-wallet", success, fail) {
this.bindPaths = _.uniq([...this.bindPaths, path]);
window.subscriptionId = window.urb.subscribe(ship, appl, path,
window.subscriptionId = this.channel.subscribe(ship, appl, path,
(err) => {
fail(err);
},
@ -33,7 +34,7 @@ class UrbitApi {
action(appl, mark, data) {
return new Promise((resolve, reject) => {
window.urb.poke(ship, appl, mark, data,
this.channel.poke(ship, appl, mark, data,
(json) => {
resolve(json);
},

View File

@ -12,6 +12,7 @@ import StartupModal from './lib/startupModal.js';
import Header from './lib/header.js'
import Balance from './lib/balance.js'
import Transactions from './lib/transactions.js'
import { subscription } from '../subscription.js'
export class Root extends Component {
@ -23,6 +24,13 @@ export class Root extends Component {
console.log('state', this.state);
}
componentDidMount(){
this.props.channel.setOnChannelError((e) => {
subscription.start();
});
subscription.start();
}
render() {
return (
<BrowserRouter>
@ -53,4 +61,3 @@ export class Root extends Component {
)
}
}