-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(multisig): allow to import existing multisig by address #1397
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,8 @@ | ||||||
import { createMultisigThresholdPubkey } from "@cosmjs/amino"; | ||||||
import { | ||||||
Pubkey, | ||||||
createMultisigThresholdPubkey, | ||||||
pubkeyToAddress, | ||||||
} from "@cosmjs/amino"; | ||||||
import React, { useEffect, useMemo, useState } from "react"; | ||||||
import { useForm } from "react-hook-form"; | ||||||
import { Pressable, ScrollView, View } from "react-native"; | ||||||
|
@@ -22,7 +26,12 @@ import { useMultisigAuthToken } from "@/hooks/multisig/useMultisigAuthToken"; | |||||
import { useMultisigClient } from "@/hooks/multisig/useMultisigClient"; | ||||||
import { useAppNavigation } from "@/hooks/navigation/useAppNavigation"; | ||||||
import { useSelectedNetworkInfo } from "@/hooks/useSelectedNetwork"; | ||||||
import { getUserId, NetworkKind, parseUserId } from "@/networks"; | ||||||
import { | ||||||
getNonSigningStargateClient, | ||||||
getUserId, | ||||||
NetworkKind, | ||||||
parseUserId, | ||||||
} from "@/networks"; | ||||||
import { getCosmosAccount } from "@/utils/cosmos"; | ||||||
import { | ||||||
patternOnlyNumbers, | ||||||
|
@@ -210,6 +219,76 @@ export const MultisigCreateScreen = () => { | |||||
/> | ||||||
<SpacerColumn size={3} /> | ||||||
|
||||||
<TextInputCustom | ||||||
name="existing-address" | ||||||
variant="labelOutside" | ||||||
noBrokenCorners | ||||||
label="Optional existing multisig address" | ||||||
onChangeText={async (addr) => { | ||||||
try { | ||||||
console.log("addr", addr); | ||||||
if (selectedNetwork?.kind !== NetworkKind.Cosmos) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove console.log usages |
||||||
console.error("not a cosmos netwokr"); | ||||||
return; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
const networkId = selectedNetwork?.id; | ||||||
if (!networkId) { | ||||||
console.error("invalid network id", networkId); | ||||||
return; | ||||||
} | ||||||
const client = await getNonSigningStargateClient(networkId); | ||||||
const account = await client.getAccount(addr); | ||||||
console.log("got account", account); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should |
||||||
const multisig = account?.pubkey; | ||||||
if (!multisig) { | ||||||
console.error("multisig not found on chain"); | ||||||
return; | ||||||
} | ||||||
if (multisig.type !== "tendermint/PubKeyMultisigThreshold") { | ||||||
console.error("invalid multisig type", multisig.type); | ||||||
return; | ||||||
} | ||||||
console.log(multisig.value); | ||||||
const threshold: string = multisig.value.threshold; | ||||||
const participants: Pubkey[] = multisig.value.pubkeys; | ||||||
console.log("threshold", threshold); | ||||||
console.log("participants", participants); | ||||||
for (const p of participants) { | ||||||
if (typeof p.value !== "string") { | ||||||
console.error( | ||||||
"invalid participant pubkey value type", | ||||||
participants, | ||||||
); | ||||||
return; | ||||||
} | ||||||
} | ||||||
const formPubkeys = participants.map((p) => { | ||||||
const address = pubkeyToAddress( | ||||||
p, | ||||||
selectedNetwork.addressPrefix, | ||||||
); | ||||||
return { | ||||||
address, | ||||||
compressedPubkey: p.value, | ||||||
}; | ||||||
}); | ||||||
setValue("maxSignature", formPubkeys.length.toString()); | ||||||
setValue("signatureRequired", threshold); | ||||||
setValue( | ||||||
"addresses", | ||||||
formPubkeys.map((fpk) => ({ address: fpk.address })), | ||||||
); | ||||||
setAddressIndexes(formPubkeys); | ||||||
} catch (err) { | ||||||
console.error(err); | ||||||
} | ||||||
}} | ||||||
placeHolder="Type the address of an existing multisig to import it" | ||||||
iconSVG={walletInputSVG} | ||||||
/> | ||||||
|
||||||
<SpacerColumn size={3} /> | ||||||
|
||||||
{addressIndexes.map((_, index) => ( | ||||||
<> | ||||||
<View key={index.toString()}> | ||||||
|
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.
It's more lisible to use a function and remove the logic from the JSX imo