-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* TSDK-775 Show LVL status * TSDK-775 Auto-init bridge * TSDK-775 First implementation/missing WS * TSDK-775 Fix integration tests * TSDK-775 Fix integration tests * TSDK-775 Fix integration tests (add log) * TSDK-775 Fix integration tests (add log) * TSDK-775 Use latest version * TSDK-775 Remove logs * TSDK-775 First more or less working version * TSDK-775 First version completed * TSDK-775 Add extra information to session * TSDK-775 Fix UI build
- Loading branch information
Showing
32 changed files
with
2,320 additions
and
661 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
import { getCookie, setCookie } from '../cookie-typescript-utils'; | ||
import { SessionInformation, StartSessionResponse } from '../views/StartSession'; | ||
|
||
export enum PeginUIState { | ||
InitialState, | ||
SessionStarted, | ||
WaitingForBTC, | ||
MintingTBTC, | ||
WaitingForMint, | ||
MintedTBTC | ||
} | ||
|
||
function stringToPeginUIState(state: string): PeginUIState { | ||
switch (state) { | ||
case "InitialState": | ||
return PeginUIState.InitialState; | ||
case "SessionStarted": | ||
return PeginUIState.SessionStarted; | ||
case "WaitingForBTC": | ||
return PeginUIState.WaitingForBTC; | ||
case "MintingTBTC": | ||
return PeginUIState.MintingTBTC; | ||
case "WaitingForMint": | ||
return PeginUIState.WaitingForMint; | ||
case "MintedTBTC": | ||
return PeginUIState.MintedTBTC; | ||
default: | ||
return PeginUIState.InitialState; | ||
} | ||
} | ||
|
||
export function setupSession(session: SessionInformation, setSession: React.Dispatch<React.SetStateAction<SessionInformation>>) { | ||
if (!session.isSet) { | ||
const sessionId = getCookie("sessionID"); | ||
const escrowAddress = getCookie("escrowAddress"); | ||
const currentState = getCookie("currentState"); | ||
const redeemAddress = getCookie("redeemAddress"); | ||
const toplBridgePKey = getCookie("toplBridgePKey"); | ||
const redeemTemplate = getCookie("redeemTemplate"); | ||
|
||
if (sessionId !== undefined && escrowAddress !== undefined && currentState !== undefined && redeemAddress !== undefined && toplBridgePKey !== undefined && redeemTemplate !== undefined) { | ||
console.log("Session exists in cookie") | ||
setSession({ isSet: true, sessionID: sessionId, escrowAddress: escrowAddress, currentState: stringToPeginUIState(currentState), redeemAddress: redeemAddress, toplBridgePKey: toplBridgePKey, redeemTemplate: redeemTemplate }); | ||
} | ||
} | ||
} | ||
|
||
export function sessionStarted(setSession: React.Dispatch<React.SetStateAction<SessionInformation>>, response: StartSessionResponse) { | ||
setCookie("sessionID", response.sessionID); | ||
setCookie("escrowAddress", response.escrowAddress); | ||
setCookie("currentState", "SessionStarted"); | ||
setSession({ isSet: true, sessionID: response.sessionID, escrowAddress: response.escrowAddress, currentState: PeginUIState.SessionStarted, redeemAddress: "", toplBridgePKey: "", redeemTemplate: "" }); | ||
} | ||
|
||
export function btcSent(setSession: React.Dispatch<React.SetStateAction<SessionInformation>>, session: SessionInformation) { | ||
setCookie("currentState", "WaitingForBTC"); | ||
setSession({ isSet: true, sessionID: session.sessionID, escrowAddress: session.escrowAddress, currentState: PeginUIState.WaitingForBTC, redeemAddress: "", toplBridgePKey: "", redeemTemplate: "" }); | ||
} | ||
export function btcArrived(setSession: React.Dispatch<React.SetStateAction<SessionInformation>>, session: SessionInformation) { | ||
setCookie("currentState", "MintingTBTC"); | ||
setSession({ isSet: true, sessionID: session.sessionID, escrowAddress: session.escrowAddress, currentState: PeginUIState.MintingTBTC, redeemAddress: "", toplBridgePKey: "", redeemTemplate: "" }); | ||
} | ||
|
||
export function mintingBTC(setSession: React.Dispatch<React.SetStateAction<SessionInformation>>, session: SessionInformation) { | ||
setCookie("currentState", "MintingTBTC"); | ||
setSession({ isSet: true, sessionID: session.sessionID, escrowAddress: session.escrowAddress, currentState: PeginUIState.MintingTBTC, redeemAddress: "", toplBridgePKey: "", redeemTemplate: "" }); | ||
} | ||
|
||
export function waitingForTBTC(setSession: React.Dispatch<React.SetStateAction<SessionInformation>>, session: SessionInformation) { | ||
setCookie("currentState", "WaitingForMint"); | ||
setSession({ isSet: true, sessionID: session.sessionID, escrowAddress: session.escrowAddress, currentState: PeginUIState.WaitingForMint, redeemAddress: "", toplBridgePKey: "", redeemTemplate: "" }); | ||
} | ||
|
||
export function mintedBTC(setSession: React.Dispatch<React.SetStateAction<SessionInformation>>, session: SessionInformation, address: string, toplBridgePKey: string, redeemTemplate: string) { | ||
setCookie("currentState", "MintedTBTC"); | ||
setCookie("redeemAddress", address); | ||
setCookie("toplBridgePKey", toplBridgePKey); | ||
setCookie("redeemTemplate", redeemTemplate); | ||
setSession({ isSet: true, sessionID: session.sessionID, escrowAddress: session.escrowAddress, currentState: PeginUIState.MintedTBTC, redeemAddress: address, toplBridgePKey: toplBridgePKey, redeemTemplate: redeemTemplate }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useOutletContext } from "react-router-dom"; | ||
import { PeginUIState } from "../controllers/PeginController"; | ||
import StartSession, { SessionInformation } from "./StartSession"; | ||
import WaitingForBTC from "./WaitingForBTC"; | ||
import WaitingForMint from "./WaitingForMint"; | ||
import { SessionCtx } from "../Frame"; | ||
|
||
const currentView = (session: SessionInformation, setSession: React.Dispatch<React.SetStateAction<SessionInformation>>) => { | ||
switch (session.currentState) { | ||
case PeginUIState.InitialState: | ||
return StartSession(session, setSession) | ||
case PeginUIState.SessionStarted: | ||
return StartSession(session, setSession) | ||
case PeginUIState.WaitingForBTC: | ||
return WaitingForBTC(session, setSession) | ||
case PeginUIState.WaitingForMint: | ||
return WaitingForMint(session) | ||
case PeginUIState.MintingTBTC: | ||
return WaitingForMint(session) | ||
case PeginUIState.MintedTBTC: | ||
return WaitingForMint(session) | ||
default: | ||
return StartSession(session, setSession) | ||
} | ||
} | ||
|
||
|
||
function PeginView() { | ||
|
||
const sessionCtx = useOutletContext<SessionCtx>(); | ||
|
||
return ( | ||
<> | ||
<h1 className="mt-4">Peg-in</h1> | ||
<div className='row g-3'> | ||
<div className="col"></div> | ||
<div className="col"> | ||
<div className="card"> | ||
<div className="card-header"> | ||
Peg-in | ||
</div> | ||
{currentView(sessionCtx.session, sessionCtx.setSession)} | ||
</div></div> | ||
<div className="col"></div> | ||
</div> | ||
</>) | ||
|
||
} | ||
|
||
export default PeginView; |
Oops, something went wrong.