From f9091a63723a8abd23de9fc5c1fb6c267b336f81 Mon Sep 17 00:00:00 2001
From: Jono Wenger <jono@elixxir.io>
Date: Tue, 18 Oct 2022 10:33:25 -0700
Subject: [PATCH] Add ReadyToSend, which checks if the network is ready to send
 on.

---
 go.mod         |  2 +-
 go.sum         |  4 ++--
 wasm/cmix.go   |  1 +
 wasm/follow.go | 10 ++++++++++
 4 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/go.mod b/go.mod
index bf5e93f4..5a77e7ad 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,7 @@ require (
 	github.com/hack-pad/go-indexeddb v0.2.0
 	github.com/pkg/errors v0.9.1
 	github.com/spf13/jwalterweatherman v1.1.0
-	gitlab.com/elixxir/client v1.5.1-0.20221017222923-185226c4412d
+	gitlab.com/elixxir/client v1.5.1-0.20221018172737-bd006184ff48
 	gitlab.com/elixxir/crypto v0.0.7-0.20221017204335-9201b3672f3a
 	gitlab.com/elixxir/primitives v0.0.3-0.20221017172918-6176818d1aba
 	gitlab.com/xx_network/crypto v0.0.5-0.20221017172404-b384a8d8b171
diff --git a/go.sum b/go.sum
index 1c0830cd..b33f2d68 100644
--- a/go.sum
+++ b/go.sum
@@ -616,8 +616,8 @@ github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo=
 github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
 gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f h1:yXGvNBqzZwAhDYlSnxPRbgor6JWoOt1Z7s3z1O9JR40=
 gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k=
-gitlab.com/elixxir/client v1.5.1-0.20221017222923-185226c4412d h1:c6hhamrVh5xAG4n/mc4LuPXkPuREd1Ql181wL16i+bI=
-gitlab.com/elixxir/client v1.5.1-0.20221017222923-185226c4412d/go.mod h1:/j/GbuxAVfR5cqLqYAq5s8IgafpyHVO63efwh/Xob4w=
+gitlab.com/elixxir/client v1.5.1-0.20221018172737-bd006184ff48 h1:m6upCBR5S2FmGbBZsGZkgYd/FBsd3l7DXOu/7IbVFZI=
+gitlab.com/elixxir/client v1.5.1-0.20221018172737-bd006184ff48/go.mod h1:/j/GbuxAVfR5cqLqYAq5s8IgafpyHVO63efwh/Xob4w=
 gitlab.com/elixxir/comms v0.0.4-0.20221017173926-4eaa6061dfaa h1:/FEpu0N0rAyq74FkvO3uY8BcQoWLSbVPhj/s5QfscZw=
 gitlab.com/elixxir/comms v0.0.4-0.20221017173926-4eaa6061dfaa/go.mod h1:rW7xdbHntP2MoF3q+2+f+IR8OHol94MRyviotfR5rXg=
 gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c=
diff --git a/wasm/cmix.go b/wasm/cmix.go
index 4779e557..cf18ee06 100644
--- a/wasm/cmix.go
+++ b/wasm/cmix.go
@@ -41,6 +41,7 @@ func newCmixJS(api *bindings.Cmix) map[string]interface{} {
 		"StartNetworkFollower":        js.FuncOf(c.StartNetworkFollower),
 		"StopNetworkFollower":         js.FuncOf(c.StopNetworkFollower),
 		"WaitForNetwork":              js.FuncOf(c.WaitForNetwork),
+		"ReadyToSend":                 js.FuncOf(c.ReadyToSend),
 		"NetworkFollowerStatus":       js.FuncOf(c.NetworkFollowerStatus),
 		"GetNodeRegistrationStatus":   js.FuncOf(c.GetNodeRegistrationStatus),
 		"HasRunningProcessies":        js.FuncOf(c.HasRunningProcessies),
diff --git a/wasm/follow.go b/wasm/follow.go
index 62725063..4b343314 100644
--- a/wasm/follow.go
+++ b/wasm/follow.go
@@ -103,6 +103,16 @@ func (c *Cmix) WaitForNetwork(_ js.Value, args []js.Value) interface{} {
 	return utils.CreatePromise(promiseFn)
 }
 
+// ReadyToSend determines if the network is ready to send messages on. It
+// returns true if the network is healthy and if the client has registered with
+// at least 70% of the nodes. Returns false otherwise.
+//
+// Returns:
+//  - Returns true if network is ready to send on (boolean).
+func (c *Cmix) ReadyToSend(js.Value, []js.Value) interface{} {
+	return c.api.ReadyToSend()
+}
+
 // NetworkFollowerStatus gets the state of the network follower. It returns a
 // status with the following values:
 //  Stopped  - 0
-- 
GitLab