-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enable import of zero balance account w/ link (testnet)
- Loading branch information
1 parent
b8c6394
commit cfe7f83
Showing
4 changed files
with
118 additions
and
60 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/frontend/src/components/accounts/CouldNotFindAccountModalWrapper.js
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,44 @@ | ||
import { KeyPair } from 'near-api-js'; | ||
import { parseSeedPhrase } from 'near-seed-phrase'; | ||
import React from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
|
||
import { | ||
redirectTo, | ||
refreshAccount | ||
} from '../../redux/actions/account'; | ||
import { showCustomAlert, clearGlobalAlert } from '../../redux/actions/status'; | ||
import { getImplicitAccountIdFromSeedPhrase, getKeyPairFromSeedPhrase } from '../../utils/parseSeedPhrase'; | ||
import { wallet } from '../../utils/wallet'; | ||
import CouldNotFindAccountModal from './CouldNotFindAccountModal'; | ||
|
||
export default ({ | ||
isOpen, | ||
onClose, | ||
seedPhrase | ||
}) => { | ||
const dispatch = useDispatch(); | ||
return ( | ||
<CouldNotFindAccountModal | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
onClickImport={async () => { | ||
const recoveryKeyPair = getKeyPairFromSeedPhrase(seedPhrase); | ||
const implicitAccountId = getImplicitAccountIdFromSeedPhrase(seedPhrase); | ||
try { | ||
await wallet.importZeroBalanceAccount(implicitAccountId, recoveryKeyPair); | ||
dispatch(refreshAccount()); | ||
dispatch(redirectTo('/')); | ||
dispatch(clearGlobalAlert()); | ||
} catch (e) { | ||
dispatch(showCustomAlert({ | ||
success: false, | ||
messageCodeHeader: 'error', | ||
messageCode: 'walletErrorCodes.recoverAccountSeedPhrase.errorNotAbleToImportAccount', | ||
errorMessage: e.message | ||
})); | ||
} | ||
}} | ||
/> | ||
); | ||
}; |
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,14 @@ | ||
import { KeyPair } from 'near-api-js'; | ||
import { parseSeedPhrase } from 'near-seed-phrase'; | ||
|
||
export function getImplicitAccountIdFromSeedPhrase(seedPhrase) { | ||
const { secretKey } = parseSeedPhrase(seedPhrase); | ||
const recoveryKeyPair = KeyPair.fromString(secretKey); | ||
return Buffer.from(recoveryKeyPair.publicKey.data).toString('hex'); | ||
}; | ||
|
||
export function getKeyPairFromSeedPhrase(seedPhrase) { | ||
const { secretKey } = parseSeedPhrase(seedPhrase); | ||
return KeyPair.fromString(secretKey); | ||
}; | ||
|