Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Uncaught exception in share transfer module #871

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions packages/files-ui/src/Contexts/ThresholdKeyContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,33 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f

// Initiate request for share transfer if not enough shares
useEffect(() => {
const handler = async () => {
if (!TKeySdk) return
// Generate share transfer request
const shareTransferModule = TKeySdk.modules[SHARE_TRANSFER_MODULE_NAME] as ShareTransferModule
console.log("Creating a Share Transfer request")
const currentEncPubKeyX = await shareTransferModule.requestNewShare(window.navigator.userAgent, TKeySdk.getCurrentShareIndexes())
console.log("Share transfer request created. Starting request status poller")

await shareTransferModule.startRequestStatusCheck(currentEncPubKeyX, true)
const resultKey = await TKeySdk.getKeyDetails()
setKeyDetails(resultKey)
if (!TKeySdk) return
const shareTransferModule = TKeySdk?.modules[SHARE_TRANSFER_MODULE_NAME] as ShareTransferModule
let shareEncPubKeyX: string | undefined
const createShareTransferRequest = async () => {
try {
console.log("Creating a Share Transfer request")
const currentEncPubKeyX = await shareTransferModule.requestNewShare(window.navigator.userAgent, TKeySdk?.getCurrentShareIndexes())
console.log("Share transfer request created. Starting request status poller")
shareEncPubKeyX = currentEncPubKeyX
await shareTransferModule.startRequestStatusCheck(currentEncPubKeyX, true)
const resultKey = await TKeySdk?.getKeyDetails()
setKeyDetails(resultKey)
shareEncPubKeyX = undefined
} catch (error) {
console.error(error)
}
}

if (keyDetails && keyDetails.requiredShares > 0) {
handler()
createShareTransferRequest()
}

return () => {
if (shareEncPubKeyX && shareTransferModule) {
shareTransferModule.cancelRequestStatusCheck()
shareTransferModule.deleteShareTransferStore(shareEncPubKeyX)
}
}
}, [TKeySdk, keyDetails])

Expand Down Expand Up @@ -550,7 +562,6 @@ const ThresholdKeyProvider = ({ children, network = "mainnet", enableLogging = f
setPublicKey(undefined)
setUserInfo(undefined)
setShouldInitializeAccount(false)
clearShareTransferRequests()
FSM1 marked this conversation as resolved.
Show resolved Hide resolved

const tkey = new ThresholdKey({
modules: {
Expand Down