Only connect to address socket on address page

Co-authored-by: Tim Mecklem <timothy@mecklem.com>
pull/333/head
jimmay5469 7 years ago
parent 3a50823ef5
commit 259fce7580
  1. 9
      apps/explorer_web/assets/js/app.js
  2. 16
      apps/explorer_web/assets/js/pages/address.js
  3. 17
      apps/explorer_web/assets/js/socket.js
  4. 1
      apps/explorer_web/lib/explorer_web/templates/address/overview.html.eex

@ -18,16 +18,11 @@ import 'bootstrap'
// Local files can be imported directly using relative
// paths "./socket" or full ones "web/static/js/socket".
<<<<<<< HEAD
// import socket from "./socket"
=======
import './socket'
import './lib/sidebar'
import './lib/market_history_chart'
>>>>>>> Prepend broadcasted transaction to address transactions list
import './lib/card_flip'
import './lib/clipboard_buttons'
import './lib/from_now'
import './lib/market_history_chart'
import './lib/sidebar'
import './lib/tooltip'
import './pages/address'

@ -0,0 +1,16 @@
import $ from 'jquery'
import socket from '../socket'
if (window.page === 'address') {
const channel = socket.channel(`addresses:${window.addressHash}`, {})
channel.join()
.receive('ok', resp => { console.log('Joined successfully', `addresses:${window.addressHash}`, resp) })
.receive('error', resp => { console.log('Unable to join', `addresses:${window.addressHash}`, resp) })
const $transactionsList = $('[data-selector="transactions-list"]')
if ($transactionsList) {
channel.on('transaction', (msg) => {
$transactionsList.prepend(msg.transaction)
})
}
}

@ -1,21 +1,6 @@
import {Socket} from 'phoenix'
import $ from 'jquery'
let socket = new Socket('/socket', {params: {locale: window.locale}})
const socket = new Socket('/socket', {params: {locale: window.locale}})
socket.connect()
// addresses channel
let channel = socket.channel(`addresses:${window.addressHash}`, {})
channel.join()
.receive('ok', resp => { console.log('Joined successfully', resp) })
.receive('error', resp => { console.log('Unable to join', resp) })
channel.on('transaction', (msg) => {
$('[data-selector="transactions-list"]').prepend(msg.transaction)
})
export default socket

@ -1,4 +1,5 @@
<script>
window.page = 'address'
window.addressHash = '<%= @address %>'
</script>

Loading…
Cancel
Save