-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] : Manage instance with DeviceAction (#7472)
- Loading branch information
1 parent
6958f82
commit e2f9934
Showing
31 changed files
with
445 additions
and
68 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { createAction } from "redux-actions"; | ||
import { WalletSyncActionTypes } from "./types"; | ||
import type { WalletSyncSetManageKeyDrawerPayload } from "./types"; | ||
|
||
export const setWallectSyncManageKeyDrawer = createAction<WalletSyncSetManageKeyDrawerPayload>( | ||
WalletSyncActionTypes.WALLET_SYNC_SET_MANAGE_KEY_DRAWER, | ||
); |
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
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
99 changes: 99 additions & 0 deletions
99
apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/useRemoveMember.ts
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,99 @@ | ||
import { | ||
memberCredentialsSelector, | ||
setTrustchain, | ||
trustchainSelector, | ||
} from "@ledgerhq/trustchain/store"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { useTrustchainSdk, runWithDevice } from "./useTrustchainSdk"; | ||
import { TrustchainMember, Trustchain } from "@ledgerhq/trustchain/types"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { Device } from "@ledgerhq/live-common/hw/actions/types"; | ||
import { useNavigation } from "@react-navigation/native"; | ||
import { ScreenName } from "~/const"; | ||
import { StackNavigatorNavigation } from "~/components/RootNavigator/types/helpers"; | ||
import { WalletSyncNavigatorStackParamList } from "~/components/RootNavigator/types/WalletSyncNavigator"; | ||
|
||
type Props = { | ||
device: Device | null; | ||
member: TrustchainMember | null; | ||
}; | ||
|
||
export function useRemoveMember({ device, member }: Props) { | ||
const dispatch = useDispatch(); | ||
const sdk = useTrustchainSdk(); | ||
const trustchain = useSelector(trustchainSelector); | ||
const memberCredentials = useSelector(memberCredentialsSelector); | ||
const [error, setError] = useState<Error | null>(null); | ||
|
||
const navigation = useNavigation<StackNavigatorNavigation<WalletSyncNavigatorStackParamList>>(); | ||
const [userDeviceInteraction, setUserDeviceInteraction] = useState(false); | ||
|
||
// eslint-disable-next-line no-console | ||
const onRetry = useCallback(() => console.log("onRetry"), []); | ||
// () => dispatch(setFlow({ flow: Flow.ManageInstances, step: Step.DeviceActionInstance })), | ||
|
||
const goToDelete = useCallback( | ||
() => navigation.navigate(ScreenName.WalletSyncActivated), | ||
[navigation], | ||
); | ||
|
||
// eslint-disable-next-line no-console | ||
const onResetFlow = useCallback(() => console.log("onResetFlow"), []); | ||
// () => dispatch(setFlow({ flow: Flow.ManageInstances, step: Step.SynchronizedInstances })), | ||
|
||
const transitionToNextScreen = useCallback( | ||
(trustchainResult: Trustchain) => { | ||
if (!member) return; | ||
dispatch(setTrustchain(trustchainResult)); | ||
navigation.navigate(ScreenName.WalletSyncManageInstancesSuccess, { | ||
member, | ||
}); | ||
}, | ||
[dispatch, member, navigation], | ||
); | ||
|
||
const removeMember = useCallback( | ||
async (member: TrustchainMember) => { | ||
if (!device) return; | ||
if (!trustchain || !memberCredentials) { | ||
throw new Error("trustchain or memberCredentials is not set"); | ||
} | ||
try { | ||
await runWithDevice(device.deviceId, async transport => { | ||
const newTrustchain = await sdk.removeMember( | ||
transport, | ||
trustchain, | ||
memberCredentials, | ||
member, | ||
{ | ||
onStartRequestUserInteraction: () => setUserDeviceInteraction(true), | ||
onEndRequestUserInteraction: () => setUserDeviceInteraction(false), | ||
}, | ||
); | ||
|
||
transitionToNextScreen(newTrustchain); | ||
}); | ||
} catch (error) { | ||
if (error instanceof Error) setError(error); | ||
} | ||
}, | ||
[device, memberCredentials, sdk, transitionToNextScreen, trustchain], | ||
); | ||
|
||
useEffect(() => { | ||
if (device && device.deviceId) { | ||
if (!member) { | ||
onResetFlow(); | ||
} else { | ||
removeMember(member); | ||
} | ||
} | ||
}, [device, member, onResetFlow, onRetry, removeMember]); | ||
|
||
return { | ||
error, | ||
onRetry, | ||
userDeviceInteraction, | ||
goToDelete, | ||
}; | ||
} |
40 changes: 40 additions & 0 deletions
40
apps/ledger-live-mobile/src/newArch/features/WalletSync/hooks/walletSync.hooks.ts
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,40 @@ | ||
import { resetTrustchainStore } from "@ledgerhq/trustchain/store"; | ||
import { useDispatch } from "react-redux"; | ||
import { TrustchainEjected, TrustchainNotAllowed } from "@ledgerhq/trustchain/errors"; | ||
import { ErrorType } from "./type.hooks"; | ||
import { useNavigation } from "@react-navigation/native"; | ||
import { StackNavigatorNavigation } from "~/components/RootNavigator/types/helpers"; | ||
import { WalletSyncNavigatorStackParamList } from "~/components/RootNavigator/types/WalletSyncNavigator"; | ||
import { ScreenName } from "~/const"; | ||
|
||
export const useLifeCycle = () => { | ||
const dispatch = useDispatch(); | ||
|
||
const navigation = useNavigation<StackNavigatorNavigation<WalletSyncNavigatorStackParamList>>(); | ||
|
||
function reset() { | ||
dispatch(resetTrustchainStore()); | ||
navigation.navigate(ScreenName.WalletSyncActivationInit); | ||
} | ||
|
||
const includesErrorActions: { [key: string]: () => void } = { | ||
[ErrorType.NO_TRUSTCHAIN]: () => reset(), | ||
}; | ||
|
||
function handleError(error: Error) { | ||
console.error("GetMember :" + error); | ||
|
||
if (error instanceof TrustchainEjected) reset(); | ||
if (error instanceof TrustchainNotAllowed) reset(); | ||
|
||
const errorToHandle = Object.entries(includesErrorActions).find(([err, _action]) => | ||
error.message.includes(err), | ||
); | ||
|
||
if (errorToHandle) errorToHandle[1](); | ||
} | ||
|
||
return { | ||
handleError, | ||
}; | ||
}; |
Oops, something went wrong.
e2f9934
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Bot] Daily non-reg on develop with 'Nitrogen' ✅ 140 txs ❌ 26 txs 💰 14 miss funds ($780.14) ⏲ 25min 6s
5 critical spec errors
Spec injective failed!
Spec Crypto org failed!
Spec Stacks failed!
Spec Polygon zkEVM Testnet failed!
Spec Solana failed!
❌ 26 mutation errors
Please increase the account target to at least 6 accounts
Please increase the account target to at least 6 accounts
Please increase the account target to at least 6 accounts
Please increase the account target to at least 6 accounts
Please increase the account target to at least 4 accounts
Please increase the account target to at least 4 accounts
Please increase the account target to at least 4 accounts
Please increase the account target to at least 4 accounts
Please increase the account target to at least 4 accounts
Please increase the account target to at least 8 accounts
Portfolio ($780.14) – Details of the 70 currencies
02026b93627ed2f76551e7cef0466468b12db8fab806266107b69947d9c95ced9e7c
0x246FFDB387F1F8c48072E1C13443540017bC71b7
osmo1rs97j43nfyvc689y5rjvnnhrq3tes6ghn8m44l
desmos1rs97j43nfyvc689y5rjvnnhrq3tes6gh0y9454
dydx1rs97j43nfyvc689y5rjvnnhrq3tes6ghj9xpr6
umee1rs97j43nfyvc689y5rjvnnhrq3tes6ghf2468l
persistence1rs97j43nfyvc689y5rjvnnhrq3tes6gh4swkdf
quick1rs97j43nfyvc689y5rjvnnhrq3tes6ghscch6l
onomy1rs97j43nfyvc689y5rjvnnhrq3tes6ghpaunjg
sei1rs97j43nfyvc689y5rjvnnhrq3tes6ghksen9v
stars1rs97j43nfyvc689y5rjvnnhrq3tes6gh0qlcgu
core1rs97j43nfyvc689y5rjvnnhrq3tes6ghgjs7yk
erd18n5sk95fq9dtgdsa9m9q5ddp66ch9cq5lpjflwn5j9z8x2e9h0qqrvk5qp
0.0.3663977
f2ed4c9253d3aca7d679bfa9f528d13e85c7f522b8857e094c850a157b750209
SP2J4VHFRAT94KY6NFT6129HBA382S6R98W9ABFG2
0xc4B17901FECf86932c3bb296BB00E7c6816Fd416
0xc4B17901FECf86932c3bb296BB00E7c6816Fd416
TM4WJOS4MZ2TD775W7GSXZMBUF74YT6SKSBXCZY3N7OUIAPXE54MZ5FCD4
tb1qva8ex44kkad8gz4m7yukmc9hdvhml29ych5esm
qr20vhwqtrjtkm97j7x57nt5wgmquklm8crhn4r9dq
ARCUFQWLhxurPQ3ZvaW2imA2sGRE92QnPG
XvZAEv6fqS9KEnnjVUgfjpUnb8YuTEFJ4y
dgb1qvhumqg0rzutcgaguzrssdjjllw3zm2gsy4ww30
D8fnWsavUwREp7yPVGqbhQzwiwzFE1YnCd
RFpuzjf9KjBwkHQZ8eCYThGTQU5fMVocxz
ltc1qxzgz09avj8gdzvvll96ztkjjuyma4h3p5x5th8
DUJ7XqFVXpqs12adgE147P3BUrMarCz1AM
t1SDpcaNZmbCH5TCCb5vNAh5bXs3isDtA5h
znmhw5LXHrt8kUnBGj51edcz95TXK182Mef
0x7584df0780C5eB83b26aE55abBc265014f8bf897
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0573d7a9c745fa9fe224b080832aa93d740760b94f192c9c141c709945e9aaaf
GDJPZPOWITPCBX3TIHB6N7E4WCHS6JBZKSNWGU34QYCJXKWBTUZY5RYC
tz1aDK1uFAmnUXZ7KJPEmcCEFeYHiVZ56zVF
r9etPtq3oboweMPju5gdYufmvwhH2euz8z
hxdd614da5f057ce32185619f98edd81445a946ea5
UQDL7vAIogYGacmfO0xTS1bwPEMJNh1g1Jliwq2p-qWkS1J0
Performance ⏲ 25min 6s
Time spent for each spec: (total across mutations)