Skip to content

Commit

Permalink
remove: OpenSessionPacketResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
marino39 committed Feb 6, 2024
1 parent 901c713 commit 8d7466d
Showing 1 changed file with 0 additions and 57 deletions.
57 changes: 0 additions & 57 deletions intents/packets/open_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,60 +38,3 @@ func (p *OpenSessionPacket) HasEmail() bool {
func (p *OpenSessionPacket) HasIDToken() bool {
return p.Proof.IDToken != ""
}

const OpenSessionPacketResponseCode = "sessionOpened"

type OpenSessionPacketResponse struct {
Code string `json:"code"`
Data OpenSessionPacketResponseData `json:"data"`
}

type OpenSessionPacketResponseData struct {
SessionId string `json:"sessionId"`
Wallet string `json:"wallet"`
}

func (p *OpenSessionPacketResponse) UnmarshalFromAny(a any) error {
m, ok := a.(map[string]any)
if !ok {
return fmt.Errorf("packet is not a map")
}

if code, ok := m["code"].(string); ok && code == OpenSessionPacketResponseCode {
p.Code = code
} else {
return fmt.Errorf("packet code is not '%s', got '%s'", OpenSessionPacketResponseCode, m["code"])
}

data, ok := m["data"].(map[string]any)
if !ok {
return fmt.Errorf("packet data is not a map")
}

if sessionId, ok := data["sessionId"].(string); ok {
p.Data.SessionId = sessionId
} else {
return fmt.Errorf("packet data is missing sessionId")
}

if wallet, ok := data["wallet"].(string); ok {
p.Data.Wallet = wallet
} else {
return fmt.Errorf("packet data is missing wallet")
}

return nil
}

func (p *OpenSessionPacketResponse) Unmarshal(packet json.RawMessage) error {
err := json.Unmarshal(packet, &p)
if err != nil {
return err
}

if p.Code != OpenSessionPacketResponseCode {
return fmt.Errorf("packet code is not '%s', got '%s'", OpenSessionPacketResponseCode, p.Code)
}

return nil
}

0 comments on commit 8d7466d

Please sign in to comment.