From 154ae14a127b278b043b17c131e8111cfec8abff Mon Sep 17 00:00:00 2001
From: Jono Wenger <jono@elixxir.io>
Date: Tue, 6 Sep 2022 14:23:23 -0700
Subject: [PATCH] Minor bug fixes

---
 wasm/e2e.go        | 6 +++---
 wasm/e2eHandler.go | 2 +-
 wasm/utils.go      | 7 +++++--
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/wasm/e2e.go b/wasm/e2e.go
index bc9fe489..aa26323c 100644
--- a/wasm/e2e.go
+++ b/wasm/e2e.go
@@ -192,15 +192,15 @@ type authCallbacks struct {
 func newAuthCallbacks(value js.Value) *authCallbacks {
 	a := &authCallbacks{}
 
-	if value.Get("Request").Type() != js.TypeFunction {
+	if value.Get("Request").Type() == js.TypeFunction {
 		a.request = WrapCB(value, "Request")
 	}
 
-	if value.Get("Confirm").Type() != js.TypeFunction {
+	if value.Get("Confirm").Type() == js.TypeFunction {
 		a.confirm = WrapCB(value, "Confirm")
 	}
 
-	if value.Get("Reset").Type() != js.TypeFunction {
+	if value.Get("Reset").Type() == js.TypeFunction {
 		a.reset = WrapCB(value, "Reset")
 	}
 
diff --git a/wasm/e2eHandler.go b/wasm/e2eHandler.go
index f2e01815..045b5447 100644
--- a/wasm/e2eHandler.go
+++ b/wasm/e2eHandler.go
@@ -226,7 +226,7 @@ func (e *E2e) AddService(_ js.Value, args []js.Value) interface{} {
 //  - Throws TypeError if registering the service fails
 func (e *E2e) RegisterListener(_ js.Value, args []js.Value) interface{} {
 	recipientId := CopyBytesToGo(args[0])
-	l := &listener{WrapCB(args[1], "Hear"), WrapCB(args[1], "Name")}
+	l := &listener{WrapCB(args[2], "Hear"), WrapCB(args[2], "Name")}
 
 	err := e.api.RegisterListener(recipientId, args[1].Int(), l)
 	if err != nil {
diff --git a/wasm/utils.go b/wasm/utils.go
index 73dbe40b..4b508d8a 100644
--- a/wasm/utils.go
+++ b/wasm/utils.go
@@ -12,6 +12,7 @@ package wasm
 import (
 	"encoding/json"
 	"fmt"
+	"github.com/pkg/errors"
 	jww "github.com/spf13/jwalterweatherman"
 	"syscall/js"
 )
@@ -37,8 +38,10 @@ func CopyBytesToJS(src []byte) js.Value {
 //
 // Panics if m is not a function.
 func WrapCB(parent js.Value, m string) func(args ...interface{}) js.Value {
-	if parent.Get("m").Type() != js.TypeFunction {
-		jww.FATAL.Panicf("Function %q is not of type %s", m, js.TypeFunction)
+	if parent.Get(m).Type() != js.TypeFunction {
+		// Create the error separate from the print so stack trace is printed
+		err := errors.Errorf("Function %q is not of type %s", m, js.TypeFunction)
+		jww.FATAL.Panicf("%+v", err)
 	}
 
 	return func(args ...interface{}) js.Value {
-- 
GitLab