-
Notifications
You must be signed in to change notification settings - Fork 10
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
4753456
commit 9662ef8
Showing
7 changed files
with
188 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'walletd': minor | ||
--- | ||
|
||
Address generation and addition dialogs now have an option to resubscribe from a specified height. |
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,100 @@ | ||
import { | ||
Alert, | ||
ConfigFields, | ||
FieldNumber, | ||
FieldSwitch, | ||
Label, | ||
Text, | ||
} from '@siafoundation/design-system' | ||
import { Path, UseFormReturn } from 'react-hook-form' | ||
import { Warning16 } from '@carbon/icons-react' | ||
import BigNumber from 'bignumber.js' | ||
import { useResubscribe } from '@siafoundation/react-walletd' | ||
|
||
export function getResubscribeFields() { | ||
return { | ||
shouldResubscribe: { | ||
type: 'boolean', | ||
title: 'Resubscribe', | ||
validation: {}, | ||
}, | ||
resubscribeStartHeight: { | ||
type: 'number', | ||
decimalsLimit: 0, | ||
title: 'Start index', | ||
validation: {}, | ||
}, | ||
} as const | ||
} | ||
|
||
export const defaultResubscribeValues = { | ||
shouldResubscribe: false, | ||
resubscribeStartHeight: new BigNumber(0), | ||
} | ||
|
||
type Values = typeof defaultResubscribeValues | ||
|
||
type Props<V extends Values> = { | ||
fields: ConfigFields<V, never> | ||
form: UseFormReturn<V> | ||
} | ||
|
||
export function FieldResubscribe<V extends Values>({ form, fields }: Props<V>) { | ||
const shouldResubscribe = form.watch('shouldResubscribe' as Path<V>) | ||
return ( | ||
<div className="flex flex-col gap-1 pt-2"> | ||
<div className="flex flex-col gap-2"> | ||
<Label color="contrast">Advanced</Label> | ||
<Text size="14" color="subtle"> | ||
Resubscribe to wallet events after adding addresses. | ||
</Text> | ||
</div> | ||
<div className="flex justify-start gap-3"> | ||
<FieldSwitch | ||
form={form} | ||
fields={fields} | ||
name={'shouldResubscribe' as Path<V>} | ||
/> | ||
{shouldResubscribe && ( | ||
<FieldNumber | ||
form={form} | ||
fields={fields} | ||
name={'resubscribeStartHeight' as Path<V>} | ||
/> | ||
)} | ||
</div> | ||
{shouldResubscribe && ( | ||
<div className="pt-2"> | ||
<Alert className="!p-2"> | ||
<div className="flex flex-col gap-1"> | ||
<div className="flex gap-2 items-center"> | ||
<Text> | ||
<Warning16 /> | ||
</Text> | ||
<Text weight="medium">Warning</Text> | ||
</div> | ||
<Text size="14" color="subtle"> | ||
Only enable this if you are adding addresses with past | ||
transactions. Resubscribing processes the blockchain from the | ||
specified height - this can take take a long time. | ||
</Text> | ||
</div> | ||
</Alert> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export function useTriggerResubscribe() { | ||
const resubscribe = useResubscribe() | ||
return async (values: Values) => { | ||
if (values.shouldResubscribe) { | ||
await resubscribe.post({ | ||
payload: values.resubscribeStartHeight | ||
? values.resubscribeStartHeight.toNumber() | ||
: 0, | ||
}) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.