Skip to content

Commit

Permalink
Merge pull request #52 from blocto/develop
Browse files Browse the repository at this point in the history
Release 0.2.0
  • Loading branch information
mordochi authored Jul 10, 2023
2 parents 0bcd4f5 + abc0bb2 commit 618c132
Show file tree
Hide file tree
Showing 29 changed files with 666 additions and 362 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@blocto/fcl": "^1.0.0-alpha.1",
"@blocto/sdk": "0.4.3",
"@blocto/sdk": "^0.5.0",
"@chakra-ui/icons": "^1.1.1",
"@chakra-ui/react": "^1.7.4",
"@emotion/react": "^11",
Expand Down
7 changes: 4 additions & 3 deletions src/components/AptosEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ScriptTypes, {
PerInfo,
PerScriptAbi,
} from "../types/ScriptTypes";
import type { AptosTypes } from "@blocto/sdk";
import Editor from "./Editor";

const typeKeys = Object.values(AptosArgTypes);
Expand All @@ -36,7 +37,7 @@ const formatTransactionArgs = (args: Arg[] | undefined) => {
: currentValue.value;
}
return initial;
}, {});
}, {}) as AptosTypes.SignMessagePayload;
};

const AptosEditor = (): ReactJSXElement => {
Expand All @@ -55,7 +56,7 @@ const AptosEditor = (): ReactJSXElement => {
}, []);

const handleSignMessage = useCallback((args) => {
return new Promise<void>((resolve) => {
return new Promise<AptosTypes.SignMessageResponse>((resolve) => {
const aptos = ChainServices[Chains.Aptos]?.bloctoSDK?.aptos;
resolve(aptos.signMessage(formatTransactionArgs(args)));
});
Expand Down Expand Up @@ -122,7 +123,7 @@ const AptosEditor = (): ReactJSXElement => {
isTransactionsExtraSignersAvailable
isSandboxDisabled
defaultTab={ScriptTypes.CONTRACT}
disabledTabs={[ScriptTypes.TX]}
disabledTabs={[ScriptTypes.TX, ScriptTypes.USER_OPERATION]}
tabsShouldLoadDefaultTemplate={[
ScriptTypes.SCRIPT,
ScriptTypes.CONTRACT,
Expand Down
44 changes: 39 additions & 5 deletions src/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const TabNames = [
"Contract",
"Sign Message",
"Resource",
"User Operations",
];

const isMainnet = process.env.REACT_APP_NETWORK === "mainnet";
Expand All @@ -65,10 +66,12 @@ interface EditorProps {
shouldSign: boolean | undefined,
signers: Array<{ privateKey: string; address: string }> | undefined,
script: string,
method?: (...param: any[]) => Promise<any>
method?: (...param: any[]) => Promise<any>,
isUserOperation?: boolean
) => Promise<{
transactionId: string;
transactionId?: string;
transaction?: any;
userOpHash?: string;
subscribeFunc?: (callback: (transaction: any) => void) => () => void;
isSealed?: (transaction: any) => boolean;
}>;
Expand Down Expand Up @@ -214,7 +217,7 @@ const Editor: React.FC<EditorProps> = ({
.catch((error) => {
setError(error?.message || "Error: Signing message failed.");
});
} else if (scriptType === ScriptTypes.TX) {
} else if (scriptType === ScriptTypes.TX && onSendTransactions) {
onSendTransactions(
args,
shouldSign,
Expand All @@ -223,8 +226,39 @@ const Editor: React.FC<EditorProps> = ({
methodRef.current
)
.then(({ transactionId, transaction, subscribeFunc, isSealed }) => {
setTxHash(transactionId);
setResponse(transaction);
if (transactionId) {
setTxHash(transactionId);
setResponse(transaction);
}

if (subscribeFunc && isSealed) {
const unsub = subscribeFunc((transaction: any) => {
setResponse(transaction);
if (isSealed(transaction)) {
unsub();
}
});
}
})
.catch((error) => {
setError(error?.message || "Error: Sending transaction failed.");
});
} else if (
scriptType === ScriptTypes.USER_OPERATION &&
onSendTransactions
) {
onSendTransactions(
args,
shouldSign,
signers,
script,
methodRef.current,
true
)
.then(({ userOpHash, subscribeFunc, isSealed }) => {
if (userOpHash) {
setResult(userOpHash);
}

if (subscribeFunc && isSealed) {
const unsub = subscribeFunc((transaction: any) => {
Expand Down
83 changes: 57 additions & 26 deletions src/components/EvmEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Context } from "../context/Context";
import * as ContractTemplates from "../scripts/evm/Contract";
import * as SignMessageTemplates from "../scripts/evm/SignMessage";
import * as TransactionsTemplates from "../scripts/evm/Transactions";
import * as UserOperationsTemplates from "../scripts/evm/UserOperations";
import { EvmChain } from "../types/ChainTypes";
import ScriptTypes, { Arg, ArgTypes, PerInfo } from "../types/ScriptTypes";
import Editor from "./Editor";
Expand All @@ -13,7 +14,7 @@ import EvmChainSelect from "./EvmChainSelect";
const typeKeys = Object.values(ArgTypes);

const FaucetUrls = {
[EvmChain.Ethereum]: "https://rinkeby-faucet.com/",
[EvmChain.Ethereum]: "https://goerlifaucet.com/",
[EvmChain.Bsc]: "https://testnet.binance.org/faucet-smart",
[EvmChain.Polygon]: "https://faucet.polygon.technology/",
[EvmChain.Avalanche]: "https://faucet.avax-test.network/",
Expand All @@ -25,6 +26,7 @@ const MenuGroups = [
{ title: "Transactions", templates: TransactionsTemplates },
{ title: "Sign Message", templates: SignMessageTemplates },
{ title: "Contract", templates: ContractTemplates },
{ title: "User Operations", templates: UserOperationsTemplates },
];

const formatTransactionArgs = (args: Arg[] | undefined) => {
Expand Down Expand Up @@ -99,8 +101,13 @@ const EvmEditor = (): ReactJSXElement => {
shouldSign: boolean | undefined,
signers: Array<{ privateKey: string; address: string }> | undefined,
script: string,
method?: (...param: any[]) => Promise<any>
): Promise<{ transactionId: string; transaction: any }> => {
method?: (...param: any[]) => Promise<any>,
isUserOperation?: boolean
): Promise<{
transactionId?: string;
transaction?: any;
userOpHash?: string;
}> => {
return new Promise(async (resolve, reject) => {
if (!method) {
return reject(new Error("Error: Transaction method is missing."));
Expand All @@ -109,28 +116,48 @@ const EvmEditor = (): ReactJSXElement => {
const address = await checkArgumentsAndAddress(args);
const formattedArgs = formatTransactionArgs(args);

method(address, formattedArgs, chain)
.then((transaction) => {
resolve({
transactionId: transaction.transactionHash,
transaction,
});
toast({
title: "Transaction is Sealed",
status: "success",
isClosable: true,
duration: 1000,
});
})
.catch((error) => {
reject(error);
toast({
title: "Transaction failed",
status: "error",
isClosable: true,
duration: 1000,
});
});
!isUserOperation
? method(address, formattedArgs, chain)
.then((transaction) => {
resolve({
transactionId: transaction.transactionHash,
transaction,
});
toast({
title: "Transaction is Sealed",
status: "success",
isClosable: true,
duration: 1000,
});
})
.catch((error) => {
reject(error);
toast({
title: "Transaction failed",
status: "error",
isClosable: true,
duration: 1000,
});
})
: method(address, formattedArgs, chain)
.then((userOpHash) => {
resolve({ userOpHash });
toast({
title: "Transaction is Sealed",
status: "success",
isClosable: true,
duration: 1000,
});
})
.catch((error) => {
reject(error);
toast({
title: "Transaction failed",
status: "error",
isClosable: true,
duration: 1000,
});
});
});
},
[toast, checkArgumentsAndAddress, chain]
Expand Down Expand Up @@ -198,7 +225,11 @@ const EvmEditor = (): ReactJSXElement => {
isSandboxDisabled
shouldClearScript
disabledTabs={[ScriptTypes.SCRIPT, ScriptTypes.RESOURCE]}
tabsShouldLoadDefaultTemplate={[ScriptTypes.SIGN, ScriptTypes.CONTRACT]}
tabsShouldLoadDefaultTemplate={[
ScriptTypes.SIGN,
ScriptTypes.CONTRACT,
ScriptTypes.USER_OPERATION,
]}
faucetUrl={(chain as EvmChain) ? FaucetUrls[chain as EvmChain] : ""}
>
<EvmChainSelect />
Expand Down
6 changes: 5 additions & 1 deletion src/components/FlowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ const FlowEditor = (): ReactJSXElement => {
onSendTransactions={handleSendTransactions}
argTypes={typeKeys}
isTransactionsExtraSignersAvailable
disabledTabs={[ScriptTypes.CONTRACT, ScriptTypes.RESOURCE]}
disabledTabs={[
ScriptTypes.CONTRACT,
ScriptTypes.RESOURCE,
ScriptTypes.USER_OPERATION,
]}
tabsShouldLoadDefaultTemplate={[ScriptTypes.SIGN]}
onSendScript={handleSendScript}
faucetUrl="https://testnet-faucet.onflow.org/fund-account"
Expand Down
1 change: 1 addition & 0 deletions src/components/SolanaEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const SolanaEditor = (): ReactJSXElement => {
ScriptTypes.SCRIPT,
ScriptTypes.SIGN,
ScriptTypes.RESOURCE,
ScriptTypes.USER_OPERATION,
]}
tabsShouldLoadDefaultTemplate={[ScriptTypes.CONTRACT]}
faucetUrl="https://solfaucet.com/"
Expand Down
Loading

0 comments on commit 618c132

Please sign in to comment.