|
1 |
| -import { useCallback, useState } from 'react'; |
| 1 | +import { useCallback, useEffect, useState } from 'react'; |
2 | 2 | import {
|
3 | 3 | UseFormRegister,
|
4 | 4 | UseFormSetValue,
|
@@ -40,13 +40,29 @@ function SpawnAnotherAccount({
|
40 | 40 | }: SpawnAnotherAccount) {
|
41 | 41 | const genesisID = useCurrentGenesisID();
|
42 | 42 | const { isSpawnedAccount } = useAccountData();
|
43 |
| - const isSpawned = (acc: AccountWithAddress<AnySpawnArguments>) => |
44 |
| - pipe( |
45 |
| - genesisID, |
46 |
| - O.mapWithDefault(false, (genesis) => |
47 |
| - isSpawnedAccount(genesis, acc.address) |
48 |
| - ) |
49 |
| - ); |
| 43 | + const isSpawned = useCallback( |
| 44 | + (acc: AccountWithAddress<AnySpawnArguments>) => |
| 45 | + pipe( |
| 46 | + genesisID, |
| 47 | + O.mapWithDefault(false, (genesis) => |
| 48 | + isSpawnedAccount(genesis, acc.address) |
| 49 | + ) |
| 50 | + ), |
| 51 | + [genesisID, isSpawnedAccount] |
| 52 | + ); |
| 53 | + |
| 54 | + useEffect(() => { |
| 55 | + if (accounts.length > 0) { |
| 56 | + const firstUnspawned = accounts.find((x) => !isSpawned(x)); |
| 57 | + if (firstUnspawned) { |
| 58 | + setSelectedAddress(firstUnspawned.address); |
| 59 | + setValue( |
| 60 | + 'templateAddress', |
| 61 | + firstUnspawned.templateAddress as StdTemplateKeys |
| 62 | + ); |
| 63 | + } |
| 64 | + } |
| 65 | + }, [accounts, isSpawned, setValue]); |
50 | 66 |
|
51 | 67 | const [selectedAddress, setSelectedAddress] = useState(
|
52 | 68 | accounts.find((x) => !isSpawned(x))?.address
|
|
0 commit comments