Skip to content

Commit 597b34e

Browse files
authored
Submit ledger network tx (#230)
1 parent 1827b8c commit 597b34e

File tree

14 files changed

+472
-241
lines changed

14 files changed

+472
-241
lines changed

main/api/ledger/utils/ledger.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { z } from "zod";
1414
import { ledgerStore } from "../../../stores/ledgerStore";
1515
import { handleImportAccount } from "../../accounts/handleImportAccount";
1616
import { logger } from "../../ironfish/logger";
17+
import { manager } from "../../manager";
1718
import { handleSendTransactionInput } from "../../transactions/handleSendTransaction";
1819
import { PromiseQueue } from "../../utils/promiseQueue";
1920
import { createUnsignedTransaction } from "../../utils/transactions";
@@ -409,13 +410,20 @@ class LedgerManager {
409410
throw new Error(signResponse.errorMessage || "No signature returned");
410411
}
411412

412-
const splitSignParams = {
413-
unsignedTransaction: unsignedTransactionBuffer,
413+
const ironfish = await manager.getIronfish();
414+
const rpcClient = await ironfish.rpcClient();
415+
416+
const addSignatureResponse = await rpcClient.wallet.addSignature({
417+
unsignedTransaction,
414418
signature: signResponse.signature.toString("hex"),
415-
};
419+
});
420+
421+
const addTransactionResponse = await rpcClient.wallet.addTransaction({
422+
transaction: addSignatureResponse.content.transaction,
423+
broadcast: true,
424+
});
416425

417-
// @todo: Sign and submit the transaction once addSignature is available from the RPC client
418-
return splitSignParams;
426+
return addTransactionResponse.content;
419427
} catch (err) {
420428
const message =
421429
err instanceof Error ? err.message : "Failed to import account";

main/api/transactions/handleSendTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const handleSendTransactionInput = z.object({
99
toAccount: z.string(),
1010
assetId: z.string(),
1111
amount: z.string(),
12-
fee: z.number(),
12+
fee: z.number().nullable(),
1313
memo: z.string().optional(),
1414
});
1515

main/api/utils/transactions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const createTransactionInput = z.object({
1212
toAccount: z.string(),
1313
assetId: z.string(),
1414
amount: z.string(),
15-
fee: z.number(),
15+
fee: z.number().nullable(),
1616
memo: z.string().optional(),
1717
});
1818

@@ -67,7 +67,7 @@ export async function createRawTransaction({
6767
assetId: assetId,
6868
},
6969
],
70-
fee: CurrencyUtils.encode(BigInt(fee)),
70+
fee: fee ? CurrencyUtils.encode(BigInt(fee)) : null,
7171
feeRate: null,
7272
expiration: undefined,
7373
confirmations: undefined,

package-lock.json

Lines changed: 59 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"license": "MPL-2.0",
2424
"dependencies": {
25-
"@ironfish/sdk": "2.4.1",
25+
"@ironfish/sdk": "2.5.0",
2626
"@ledgerhq/hw-transport-node-hid": "^6.29.1",
2727
"electron-serve": "^1.1.0",
2828
"keccak": "^3.0.4"

renderer/components/AccountAssets/AccountAssets.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const messages = defineMessages({
4949

5050
export function AccountAssets({ accountName }: { accountName: string }) {
5151
const { formatMessage } = useIntl();
52-
const { data } = trpcReact.getAccount.useQuery({
52+
const { data: accountData } = trpcReact.getAccount.useQuery({
5353
name: accountName,
5454
});
5555

@@ -63,11 +63,14 @@ export function AccountAssets({ accountName }: { accountName: string }) {
6363
},
6464
);
6565

66-
if (!data) {
66+
if (!accountData) {
6767
// @todo: Error handling
6868
return null;
6969
}
7070

71+
const isAccountSendEligible =
72+
!accountData.status.viewOnly || accountData.isLedger;
73+
7174
return (
7275
<Box>
7376
<LightMode>
@@ -98,19 +101,19 @@ export function AccountAssets({ accountName }: { accountName: string }) {
98101
$IRON
99102
</Text>
100103
<Heading as="span" color="black" mb={5}>
101-
{formatOre(data.balances.iron.confirmed)}
104+
{formatOre(accountData.balances.iron.confirmed)}
102105
</Heading>
103106
<HStack alignItems="stretch" justifyContent="center">
104107
<ChakraLink
105108
href={
106-
data.status.viewOnly
109+
!isAccountSendEligible
107110
? "#"
108111
: `/send?account=${accountName}`
109112
}
110113
>
111114
<Tooltip
112115
label={
113-
data.status.viewOnly
116+
!isAccountSendEligible
114117
? formatMessage(messages.viewOnlySendDisabled)
115118
: !isSynced.synced
116119
? formatMessage(messages.syncingSendDisabled)
@@ -122,7 +125,9 @@ export function AccountAssets({ accountName }: { accountName: string }) {
122125
<PillButton
123126
size="sm"
124127
as="div"
125-
isDisabled={data.status.viewOnly || !isSynced.synced}
128+
isDisabled={
129+
!isAccountSendEligible || !isSynced.synced
130+
}
126131
>
127132
<ArrowSend transform="scale(0.8)" />
128133
{formatMessage(messages.sendButton)}
@@ -141,7 +146,7 @@ export function AccountAssets({ accountName }: { accountName: string }) {
141146
<Image alt="" src={treasureChest} />
142147
</HStack>
143148

144-
{data.balances.custom.length > 0 && (
149+
{accountData.balances.custom.length > 0 && (
145150
<Box
146151
bg="rgba(255, 255, 255, 0.15)"
147152
p={8}
@@ -155,10 +160,12 @@ export function AccountAssets({ accountName }: { accountName: string }) {
155160
<Grid
156161
gap={4}
157162
templateColumns={
158-
data.balances.custom.length > 1 ? "repeat(2, 1fr)" : "1fr"
163+
accountData.balances.custom.length > 1
164+
? "repeat(2, 1fr)"
165+
: "1fr"
159166
}
160167
>
161-
{data.balances.custom.map((balance) => {
168+
{accountData.balances.custom.map((balance) => {
162169
const { confirmed, assetId, asset } = balance;
163170
const majorString = CurrencyUtils.render(
164171
confirmed,

renderer/components/AccountRow/AccountRow.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export function AccountRow({
7070
refetchInterval: 5000,
7171
},
7272
);
73+
74+
const isAccountSendEligible = !viewOnly || isLedger;
7375
return (
7476
<ChakraLink href={`/accounts/${name}`} w="100%">
7577
<ShadowCard hoverable>
@@ -105,7 +107,7 @@ export function AccountRow({
105107
<HStack gap={3}>
106108
<Text as="h3">{name}</Text>
107109
{isLedger && <LedgerChip />}
108-
{!isLedger && viewOnly && <ViewOnlyChip />}
110+
{!isAccountSendEligible && <ViewOnlyChip />}
109111
</HStack>
110112
<Heading as="span" fontWeight="regular" fontSize="2xl">
111113
{formatOre(balance)} $IRON
@@ -120,7 +122,7 @@ export function AccountRow({
120122
>
121123
<Tooltip
122124
label={
123-
viewOnly
125+
!isAccountSendEligible
124126
? formatMessage(messages.viewOnlySendDisabled)
125127
: !isSynced.synced
126128
? formatMessage(messages.syncingSendDisabled)
@@ -131,11 +133,11 @@ export function AccountRow({
131133
<VStack w="100%" alignItems="stretch">
132134
<PillButton
133135
size="sm"
134-
isDisabled={viewOnly || !isSynced.synced}
136+
isDisabled={!isAccountSendEligible || !isSynced.synced}
135137
onClick={(e) => {
136138
e.preventDefault();
137139
e.stopPropagation();
138-
if (viewOnly || !isSynced.synced) return;
140+
if (!isAccountSendEligible || !isSynced.synced) return;
139141
router.push(`/send?account=${name}`);
140142
}}
141143
>

0 commit comments

Comments
 (0)