-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transaction list UI fix, fixed ledger zkapp integration, minor UI fix
- Loading branch information
1 parent
cb1b45d
commit 5c1fed6
Showing
27 changed files
with
478 additions
and
99 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
88 changes: 88 additions & 0 deletions
88
packages/renderer/src/components/UI/modals/zkAppIntegration/ConfirmZkappLedgerDelegation.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,88 @@ | ||
import {useEffect, useState} from 'react'; | ||
import {useRecoilValue} from 'recoil'; | ||
import {walletState, zkappState} from '/@/store'; | ||
import { | ||
createLedgerDelegationTransaction, | ||
isMinaAppOpen, | ||
signTransaction, | ||
} from '/@/tools/ledger/ledger'; | ||
import {toast} from 'react-toastify'; | ||
import {toNanoMINA} from '/@/tools'; | ||
import LedgerSignError from './LedgerSignError'; | ||
import LedgerSingPending from './LedgerSingPending'; | ||
|
||
interface IConfirmZkappLedgerDelegation { | ||
onSuccess: (signedTx: unknown) => void; | ||
onClose: () => void; | ||
} | ||
export default function ConfirmZkappLedgerDelegation({ | ||
onSuccess, | ||
onClose, | ||
}: IConfirmZkappLedgerDelegation) { | ||
const {transactionData} = useRecoilValue(zkappState); | ||
const {ledgerAccount} = useRecoilValue(walletState); | ||
const [showError, setShowError] = useState(false); | ||
const [errorMessage, setErrorMessage] = useState(''); | ||
|
||
useEffect(() => { | ||
sendLedgerTransaction(); | ||
}, []); | ||
|
||
/** | ||
* Sign transaction with Ledger | ||
*/ | ||
const sendLedgerTransaction = async () => { | ||
try { | ||
await isMinaAppOpen(); | ||
const senderAccount = ledgerAccount || 0; | ||
const transactionToSend = await createLedgerDelegationTransaction({ | ||
senderAddress: transactionData.from, | ||
receiverAddress: transactionData.to, | ||
fee: toNanoMINA(transactionData.fee), | ||
nonce: +transactionData.nonce || 0, | ||
senderAccount, | ||
}); | ||
|
||
const signature = await signTransaction(transactionToSend); | ||
completeSignature(signature.signature); | ||
} catch (e) { | ||
console.log('🚀 ~ sendLedgerTransaction ~ e:', e); | ||
setShowError(true); | ||
setErrorMessage(e.message || 'An error occurred while loading hardware wallet'); | ||
toast.error(e.message || 'An error occurred while loading hardware wallet'); | ||
} | ||
}; | ||
|
||
const completeSignature = signature => { | ||
const data = { | ||
signature: {rawSignature: signature}, | ||
publicKey: transactionData.from, | ||
data: { | ||
from: transactionData.from, | ||
to: transactionData.to, | ||
fee: '' + toNanoMINA(transactionData.fee), | ||
nonce: '' + transactionData.nonce || 0, | ||
}, | ||
}; | ||
return onSuccess(data); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className="mx-auto w-100"> | ||
<div className="align-left mb-2 label text-center w-100"> | ||
<div className="flex w-100 items-center flex-col"> | ||
{showError ? ( | ||
<LedgerSignError message={errorMessage} /> | ||
) : ( | ||
<LedgerSingPending | ||
transactionData={transactionData} | ||
isDelegation | ||
/> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.