|
| 1 | +import { useSelector } from 'react-redux'; |
| 2 | + |
| 3 | +import { |
| 4 | + AccountsRootState, |
| 5 | + selectAccountByKey, |
| 6 | + selectSelectedDevice, |
| 7 | +} from '@suite-common/wallet-core'; |
| 8 | +import { useAlert } from '@suite-native/alerts'; |
| 9 | +import { Button, useBottomSheetModal } from '@suite-native/atoms'; |
| 10 | +import { Translation, useTranslate } from '@suite-native/intl'; |
| 11 | +import { SUITE_MOBILE_SUPPORT_URL, useOpenLink } from '@suite-native/link'; |
| 12 | +import { localFirstToBip329, selectAddressLabels, selectOutputLabels, WithLabelingState } from '@suite-common/local-first-storage'; |
| 13 | + |
| 14 | +export const AccountSettingsExportBip329Button = ({ accountKey }: { accountKey: string }) => { |
| 15 | + const account = useSelector((state: AccountsRootState) => |
| 16 | + selectAccountByKey(state, accountKey), |
| 17 | + ); |
| 18 | + const device = useSelector(selectSelectedDevice); |
| 19 | + const staticSessionId = device?.state?.staticSessionId; |
| 20 | + |
| 21 | + const labels = useSelector((state: WithLabelingState) => { |
| 22 | + console.log('staticSessionId', staticSessionId); |
| 23 | + if (!staticSessionId) return {outputLabels: [], addressLabels: []}; |
| 24 | + const outputLabels = selectOutputLabels(state, staticSessionId); |
| 25 | + console.log('outputLabels', outputLabels); |
| 26 | + |
| 27 | + const addressLabels = selectAddressLabels({state, deviceStaticSessionId: staticSessionId}); |
| 28 | + return {outputLabels, addressLabels} |
| 29 | + }); |
| 30 | + |
| 31 | + console.log('labels', labels); |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + const exportBip329 = () => { |
| 36 | + console.log('exportBip329'); |
| 37 | + // const handleExportBip329 = () => dispatch(exportMetadataToBip329File()); |
| 38 | + // console.log('handleExportBip329'); |
| 39 | + const labelsToExport = localFirstToBip329({ |
| 40 | + outputLabels: labels.outputLabels, |
| 41 | + addressLabels: labels.addressLabels, |
| 42 | + allSpendable: true, |
| 43 | + }); |
| 44 | + |
| 45 | + console.log('labelsToExport', labelsToExport); |
| 46 | + }; |
| 47 | + |
| 48 | + if (!account) return null; |
| 49 | + |
| 50 | + const buttonTitle = 'Export BIP329 Data'; |
| 51 | + |
| 52 | + return ( |
| 53 | + <> |
| 54 | + <Button size="large" onPress={exportBip329} colorScheme="tertiaryElevation0"> |
| 55 | + {buttonTitle} |
| 56 | + </Button> |
| 57 | + </> |
| 58 | + ); |
| 59 | +}; |
0 commit comments