-
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.
- Loading branch information
1 parent
630d71b
commit 8a0a679
Showing
7 changed files
with
126 additions
and
81 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,83 @@ | ||
import { Box, Group, Textarea, Button } from '@mantine/core'; | ||
import { useForm } from '@mantine/form'; | ||
import { useDisclosure } from '@mantine/hooks'; | ||
import { useState } from 'react'; | ||
import { signMessage } from '../lib/ledger'; | ||
|
||
import MessageModal from './message-modal'; | ||
import { notifications } from '@mantine/notifications'; | ||
|
||
export default function MessageForm(props) { | ||
const [signature, setSignature] = useState(); | ||
const [opened, { open, close }] = useDisclosure(false); | ||
|
||
const form = useForm({ | ||
initialValues: { | ||
message: '', | ||
}, | ||
validate: { | ||
message: (value) => (!value ? 'message required' : null), | ||
}, | ||
}); | ||
|
||
const onClickSignMessage = async () => { | ||
const notifId = notifications.show({ | ||
title: 'Action Required', | ||
message: 'Please review the message on your device', | ||
loading: true, | ||
}); | ||
|
||
try { | ||
const path = props.selectedAddress.derivationPath.split('/'); | ||
const result = await signMessage(form.values.message, Number(path[3]), Number(path[4])); | ||
setSignature(result.signature); | ||
|
||
open(); | ||
} catch (e) { | ||
if (e.statusText === 'CONDITIONS_OF_USE_NOT_SATISFIED' && e.message) { | ||
notifications.show({ | ||
title: 'Error', | ||
message: e.message, | ||
}); | ||
} else if (e.statusCode == 45073) { | ||
notifications.show({ | ||
title: 'Error', | ||
message: 'Message too long', | ||
}); | ||
} else { | ||
notifications.show({ | ||
title: 'Error', | ||
message: 'Message signing failed', | ||
}); | ||
console.error(e); | ||
} | ||
} finally { | ||
notifications.hide(notifId); | ||
} | ||
}; | ||
|
||
return ( | ||
<Box w={'100%'} mx='auto'> | ||
<Textarea | ||
label={'Personal Message'} | ||
placeholder={'Enter the message to sign here'} | ||
maxLength={200} | ||
rows={5} | ||
{...form.getInputProps('message')} | ||
/> | ||
|
||
<Group justify='center' mt='md'> | ||
<Button onClick={onClickSignMessage} disabled={!form.isValid()}> | ||
Sign Message | ||
</Button> | ||
</Group> | ||
|
||
<MessageModal | ||
opened={opened} | ||
onClose={close} | ||
message={form.values.message} | ||
signature={signature} | ||
/> | ||
</Box> | ||
); | ||
} |
File renamed without changes.
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