Skip to content

Commit

Permalink
Merge pull request #51 from pshalagin/master
Browse files Browse the repository at this point in the history
enabled multiple entry of the same account if the account is a co-signer
  • Loading branch information
sozidatel authored Jun 3, 2024
2 parents 4acf0ad + da41803 commit fb098ac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "org.montelibero.solar",
"displayName": "MTL Solar",
"version": "1.0.0-beta",
"version": "1.0.0-beta.2",
"description": "Wallet for the Stellar payment network by Montelibero.",
"license": "MIT",
"private": true,
Expand Down
23 changes: 16 additions & 7 deletions src/AccountCreation/hooks/useAccountCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,21 @@ import { Account, AccountsContext } from "~App/contexts/accounts"
import { CustomError } from "~Generic/lib/errors"
import { AccountCreation, AccountCreationErrors } from "../types/types"

function isAccountAlreadyImported(privateKey: string, accounts: Account[], testnet: boolean) {
const publicKey = Keypair.fromSecret(privateKey).publicKey()
return accounts.some(account => account.publicKey === publicKey && account.testnet === testnet)
function isAccountAlreadyImported(creatingAccount: AccountCreation, accounts: Account[], testnet: boolean) {
const publicKey = Keypair.fromSecret(creatingAccount.secretKey!).publicKey()
const simpleDuplicate =
!creatingAccount.cosigner &&
accounts.some(account => account.publicKey === publicKey && account.testnet === testnet && !account.cosignerOf)
const cosignerDuplicate =
creatingAccount.cosigner &&
accounts.some(
account =>
account.publicKey === publicKey &&
account.testnet === testnet &&
account.cosignerOf === creatingAccount.cosignerOf
)
const cosigningMyself = creatingAccount.cosigner && publicKey === creatingAccount.cosignerOf
return simpleDuplicate || cosigningMyself || cosignerDuplicate
}

function isValidSecretKey(privateKey: string) {
Expand Down Expand Up @@ -49,10 +61,7 @@ function validateAccountCreation(t: TFunction, accounts: Account[], accountCreat

if (accountCreation.import && !isValidSecretKey(accountCreation.secretKey!)) {
errors.secretKey = t("create-account.validation.invalid-key")
} else if (
accountCreation.import &&
isAccountAlreadyImported(accountCreation.secretKey!, accounts, accountCreation.testnet)
) {
} else if (accountCreation.import && isAccountAlreadyImported(accountCreation, accounts, accountCreation.testnet)) {
errors.secretKey = t("create-account.validation.same-account")
}

Expand Down

0 comments on commit fb098ac

Please sign in to comment.