-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node): support deposit for stub settlement module
- Loading branch information
Showing
9 changed files
with
186 additions
and
4 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
28 changes: 28 additions & 0 deletions
28
packages/app-node/src/backend/settlement-schemes/trpc-routers/settlement.ts
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,28 @@ | ||
import { z } from "zod" | ||
|
||
import { trpc } from "../../local-ipc-server/trpc-context" | ||
import { SettlementSchemeId } from "../../peer-protocol/types/settlement-scheme-id" | ||
import { protectedProcedure } from "../../trpc-server/middlewares/auth" | ||
import { ManageSettlementSchemeInstancesActor } from "../manage-settlement-scheme-instances" | ||
|
||
export const settlementRouter = trpc.router({ | ||
stubDeposit: protectedProcedure | ||
.input(z.string()) | ||
.mutation(async ({ input: amount, ctx: { sig } }) => { | ||
const manageSettlementSchemeInstancesActor = sig.reactor.use( | ||
ManageSettlementSchemeInstancesActor, | ||
) | ||
|
||
const stubActor = manageSettlementSchemeInstancesActor.get( | ||
"stub" as SettlementSchemeId, | ||
) | ||
|
||
if (!stubActor) { | ||
throw new Error("Stub settlement scheme is not enabled") | ||
} | ||
|
||
await stubActor.api.handleDeposit.ask({ amount: BigInt(amount) }) | ||
|
||
return true | ||
}), | ||
}) |
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
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,91 @@ | ||
import { ComponentType, LazyExoticComponent, Suspense, lazy } from "react" | ||
import { Link } from "wouter" | ||
|
||
import { SettlementSchemeId } from "../../../backend/peer-protocol/types/settlement-scheme-id" | ||
import { Button } from "../../components/ui/button" | ||
import { | ||
Card, | ||
CardContent, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from "../../components/ui/card" | ||
import { | ||
Tabs, | ||
TabsContent, | ||
TabsList, | ||
TabsTrigger, | ||
} from "../../components/ui/tabs" | ||
import { trpc } from "../../utils/trpc" | ||
|
||
const SCHEME_DEPOSIT_NAME_MAP: Record<SettlementSchemeId, string> = { | ||
["stub" as SettlementSchemeId]: "Stub", | ||
} | ||
|
||
const SCHEME_DEPOSIT_UI_MAP: Record< | ||
SettlementSchemeId, | ||
LazyExoticComponent<ComponentType> | ||
> = { | ||
["stub" as SettlementSchemeId]: lazy( | ||
() => import("./settlement-schemes/stub"), | ||
), | ||
} | ||
|
||
export function ReceivePage() { | ||
const basicState = trpc.general.getBasicState.useQuery() | ||
|
||
const activeSettlementSchemes = basicState.data?.activeSettlementSchemes ?? [] | ||
|
||
return ( | ||
<div className="flex h-full items-center justify-center"> | ||
<Card> | ||
<CardHeader> | ||
<CardTitle className="flex-grow flex-shrink-0 basis-auto font-bold text-lg md:text-xl"> | ||
Receive | ||
</CardTitle> | ||
</CardHeader> | ||
<CardContent> | ||
<Tabs defaultValue="interledger"> | ||
<TabsList> | ||
<TabsTrigger value="interledger">Interledger</TabsTrigger> | ||
{activeSettlementSchemes.map((schemeId) => | ||
SCHEME_DEPOSIT_NAME_MAP[schemeId] ? ( | ||
<TabsTrigger key={schemeId} value={schemeId}> | ||
{SCHEME_DEPOSIT_NAME_MAP[schemeId]} | ||
</TabsTrigger> | ||
) : null, | ||
)} | ||
</TabsList> | ||
<TabsContent value="interledger"> | ||
<p>Send money to the following payment pointer:</p> | ||
<div className="text-lg font-bold border rounded-lg p-4 mt-4"> | ||
{basicState.data ? `$${basicState.data.hostname}` : "???"} | ||
</div> | ||
</TabsContent> | ||
|
||
{activeSettlementSchemes.map((schemeId) => { | ||
const Component = SCHEME_DEPOSIT_UI_MAP[schemeId] | ||
|
||
if (!Component) { | ||
return null | ||
} | ||
|
||
return ( | ||
<TabsContent key={schemeId} value={schemeId}> | ||
<Suspense fallback={<div>Loading...</div>}> | ||
<Component /> | ||
</Suspense> | ||
</TabsContent> | ||
) | ||
})} | ||
</Tabs> | ||
</CardContent> | ||
<CardFooter> | ||
<Link href="/"> | ||
<Button variant="ghost">Back</Button> | ||
</Link> | ||
</CardFooter> | ||
</Card> | ||
</div> | ||
) | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/app-node/src/frontend/pages/receive/settlement-schemes/stub.tsx
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,28 @@ | ||
import { useLocation } from "wouter" | ||
|
||
import { Button } from "../../../components/ui/button" | ||
import { trpc } from "../../../utils/trpc" | ||
|
||
export default function StubDeposit() { | ||
const stubDepositMutation = trpc.settlement.stubDeposit.useMutation() | ||
const [, setLocation] = useLocation() | ||
|
||
return ( | ||
<div> | ||
<p> | ||
The "stub" settlement method only simulates a ledger rather | ||
than using a real one. You can click the button below to simulate | ||
receiving funds on the underlying ledger. | ||
</p> | ||
<Button | ||
className="mt-4" | ||
onClick={() => { | ||
stubDepositMutation.mutate("100000000000") | ||
setLocation("/") | ||
}} | ||
> | ||
Receive $100 | ||
</Button> | ||
</div> | ||
) | ||
} |