Skip to content

Commit

Permalink
fix: include anchorAccounts wherever account is used
Browse files Browse the repository at this point in the history
  • Loading branch information
sohrab- committed Aug 14, 2022
1 parent 187abad commit 5253081
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
3 changes: 3 additions & 0 deletions src/components/client/TransactionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ export const TransactionHeader: React.FC<{ transaction: ITransaction }> = ({
aria-label="Run Program"
rightIcon={<Icon as={FaPlay} />}
onClick={() => {
setUI((state) => {
state.transactionRun = DEFAULT_TRANSACTION_RUN;
});
send(transaction);
}}
>
Expand Down
17 changes: 9 additions & 8 deletions src/components/client/accounts/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import { PdaButton } from "./PdaButton";
export const Account: React.FC<{
account: IAccount;
index: number;
locked?: boolean;
isAnchor?: boolean;
}> = ({
account: { id, name, pubkey, isWritable, isSigner },
index,
locked = false,
isAnchor = false,
}) => {
const {
instruction: { programId },
Expand All @@ -55,12 +55,13 @@ export const Account: React.FC<{

const updateAccount = (fn: (state: WritableDraft<IAccount>) => void) => {
update((state) => {
fn(state.accounts.map[id]);
fn(isAnchor ? state.anchorAccounts![index] : state.accounts.map[id]);
});
};

const removeAccount = () => {
update((state) => {
// no need for the anchor side since it is never deleted
removeFrom(state.accounts, id);
});
if (hasPrivateKey) {
Expand Down Expand Up @@ -101,7 +102,7 @@ export const Account: React.FC<{
<DragHandle
unlockedProps={{ h: "2.5", w: "2.5" }}
lockedProps={{ h: "3" }}
locked={locked}
locked={isAnchor}
/>

<Numbering index={index} ml="2" minW="30px" fontSize="sm" />
Expand All @@ -114,7 +115,7 @@ export const Account: React.FC<{
fontSize="sm"
placeholder="Unnamed"
tooltipProps={{ placement: "bottom-end" }}
isDisabled={locked}
isDisabled={isAnchor}
value={name}
onChange={(value: string) => {
updateAccount((state) => {
Expand Down Expand Up @@ -213,7 +214,7 @@ export const Account: React.FC<{
size="sm"
label="Writable"
icon={<EditIcon />}
isDisabled={!locked}
isDisabled={isAnchor}
toggled={isWritable}
onToggle={(toggled) => {
updateAccount((state) => {
Expand All @@ -227,7 +228,7 @@ export const Account: React.FC<{
size="sm"
label="Signer"
icon={<Icon as={FaPenNib} />}
isDisabled={locked}
isDisabled={isAnchor}
toggled={isSigner}
onToggle={(toggled) => {
updateAccount((state) => {
Expand All @@ -236,7 +237,7 @@ export const Account: React.FC<{
}}
/>

{!locked && (
{!isAnchor && (
<Tooltip label="Remove">
<IconButton
ml="3"
Expand Down
2 changes: 1 addition & 1 deletion src/components/client/accounts/Accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const Accounts: React.FC<{
{anchorAccounts?.map((account, index) => (
<Account
account={account}
locked={true}
isAnchor={true}
index={index}
key={account.id}
/>
Expand Down
18 changes: 10 additions & 8 deletions src/components/client/results/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ export const Results: React.FC = () => {
(state) => state.transactionOptions.finality
);

const setInProgress = useSessionStoreWithoutUndo(
(state) => (value: boolean) => {
state.set((state) => {
state.transactionRun.inProgress = value;
});
}
);
const [error, set] = useSessionStoreWithoutUndo((state) => [
state.transactionRun.error,
state.set,
]);

const setInProgress = (value: boolean) =>
set((state) => {
state.transactionRun.inProgress = value;
});

const {
signature,
Expand Down Expand Up @@ -191,7 +193,7 @@ export const Results: React.FC = () => {
</Flex>

<ErrorAlert
error={results.error}
error={error || results.error}
onClose={() => {
setResults({ ...results, error: "" });
}}
Expand Down
11 changes: 9 additions & 2 deletions src/hooks/useSendWeb3Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ export const useSendWeb3Transaction = ({

// add additional signers
const signerPubkeys = Object.values(transaction.instructions.map)
.flatMap((instruction) => Object.values(instruction.accounts.map))
.flatMap((instruction) =>
(instruction.anchorAccounts || []).concat(
Object.values(instruction.accounts.map)
)
)
.filter((account) => account.isSigner && keypairs[account.pubkey])
.map((account) => account.pubkey);

Expand All @@ -66,7 +70,10 @@ export const useSendWeb3Transaction = ({

onSent && onSent(signature);
} catch (err) {
onError && onError(new Error((err as { message: string }).message));
const message = Object.getOwnPropertyNames(err).includes("message")
? (err as { message: string }).message
: JSON.stringify(err);
onError && onError(new Error(message));
}
};

Expand Down

0 comments on commit 5253081

Please sign in to comment.