Skip to content

Commit

Permalink
fix: prettier for react-dapp-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
dianasavvatina committed Sep 19, 2024
1 parent a219cd0 commit 77c9121
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 60 deletions.
2 changes: 1 addition & 1 deletion advanced/dapps/react-dapp-v2/src/components/Asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function getAssetIcon(asset: AssetData): JSX.Element {
}
}

function getDecimals(asset: AssetData) : number {
function getDecimals(asset: AssetData): number {
switch (asset?.symbol?.toLowerCase()) {
case "xtz":
return 6;
Expand Down
8 changes: 5 additions & 3 deletions advanced/dapps/react-dapp-v2/src/components/Blockchain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const SPre = styled.div`
background-color: #f4f4f4;
width: 100%;
min-width: 700px;
textAlign: 'left';
textalign: "left";
padding: 10px;
border-radius: 5px;
overflow-x: auto;
Expand Down Expand Up @@ -136,7 +136,9 @@ const Blockchain: FC<PropsWithChildren<BlockchainProps>> = (
balances,
actions,
} = props;
const [hoveredDescription, setHoveredDescription] = React.useState<string | null>(null);
const [hoveredDescription, setHoveredDescription] = React.useState<
string | null
>(null);

if (!Object.keys(chainData).length) return null;

Expand Down Expand Up @@ -215,7 +217,7 @@ const Blockchain: FC<PropsWithChildren<BlockchainProps>> = (
</SAccount>
{hoveredDescription && (
<SPre>
<pre style={{ textAlign: 'left' }}>{hoveredDescription}</pre>
<pre style={{ textAlign: "left" }}>{hoveredDescription}</pre>
</SPre>
)}
</React.Fragment>
Expand Down
57 changes: 31 additions & 26 deletions advanced/dapps/react-dapp-v2/src/constants/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
PartialTezosIncreasePaidStorageOperation,
PartialTezosOriginationOperation as PartialTezosOriginationOperationOriginal,
PartialTezosTransactionOperation,
TezosOperationType }
from "@airgap/beacon-types";
TezosOperationType,
} from "@airgap/beacon-types";
import { ScriptedContracts } from "@taquito/rpc";

if (!process.env.NEXT_PUBLIC_PROJECT_ID)
Expand Down Expand Up @@ -283,50 +283,54 @@ export enum TEZOS_SAMPLE_KINDS {
const tezosTransactionOperation: PartialTezosTransactionOperation = {
kind: TezosOperationType.TRANSACTION,
destination: "tz3ZmB8oWUmi8YZXgeRpgAcPnEMD8VgUa4Ve", // Tezos Foundation Ghost Baker
amount: "100000"
amount: "100000",
};

const tezosOriginationOperation: PartialTezosOriginationOperation = {
kind: TezosOperationType.ORIGINATION,
balance: '1',
script: { // This contract adds the parameter to the storage value
balance: "1",
script: {
// This contract adds the parameter to the storage value
code: [
{ prim: "parameter", args: [{ prim: "int" }] },
{ prim: "storage", args: [{ prim: "int" }] },
{ prim: "code",
args: [[
{ prim: "DUP" }, // Duplicate the parameter (parameter is pushed onto the stack)
{ prim: "CAR" }, // Access the parameter from the stack (parameter is on top)
{ prim: "DIP", args: [[{ prim: "CDR" }]] }, // Access the storage value (storage is on the stack)
{ prim: "ADD" }, // Add the parameter to the storage value
{
prim: "code",
args: [
[
{ prim: "DUP" }, // Duplicate the parameter (parameter is pushed onto the stack)
{ prim: "CAR" }, // Access the parameter from the stack (parameter is on top)
{ prim: "DIP", args: [[{ prim: "CDR" }]] }, // Access the storage value (storage is on the stack)
{ prim: "ADD" }, // Add the parameter to the storage value
{ prim: "NIL", args: [{ prim: "operation" }] }, // Create an empty list of operations
{ prim: "PAIR" } // Pair the updated storage with the empty list of operations
]]
}
{ prim: "PAIR" }, // Pair the updated storage with the empty list of operations
],
],
},
],
storage: { int: "10" }
storage: { int: "10" },
},
};

const tezosContractCallOperation: PartialTezosTransactionOperation = {
kind: TezosOperationType.TRANSACTION,
destination: "[contract address]",
amount: "0",
parameters: { entrypoint: "default", value: { int: "20" } } // Add 20 to the current storage value
parameters: { entrypoint: "default", value: { int: "20" } }, // Add 20 to the current storage value
};

const tezosDelegationOperation: PartialTezosDelegationOperation = {
kind: TezosOperationType.DELEGATION,
delegate: "tz3ZmB8oWUmi8YZXgeRpgAcPnEMD8VgUa4Ve" // Tezos Foundation Ghost Baker. Cannot delegate to ourself as that would block undelegation
delegate: "tz3ZmB8oWUmi8YZXgeRpgAcPnEMD8VgUa4Ve", // Tezos Foundation Ghost Baker. Cannot delegate to ourself as that would block undelegation
};

const tezosUndelegationOperation: PartialTezosDelegationOperation = {
kind: TezosOperationType.DELEGATION
kind: TezosOperationType.DELEGATION,
};

const tezosStakeOperation: PartialTezosTransactionOperation = {
kind: TezosOperationType.TRANSACTION,
destination:"[own adress]",
destination: "[own adress]",
amount: "1000000",
parameters: {
entrypoint: "stake",
Expand All @@ -336,7 +340,7 @@ const tezosStakeOperation: PartialTezosTransactionOperation = {

const tezosUnstakeOperation: PartialTezosTransactionOperation = {
kind: TezosOperationType.TRANSACTION,
destination:"[own adress]",
destination: "[own adress]",
amount: "1000000",
parameters: {
entrypoint: "unstake",
Expand All @@ -346,19 +350,20 @@ const tezosUnstakeOperation: PartialTezosTransactionOperation = {

const tezosFinalizeOperation: PartialTezosTransactionOperation = {
kind: TezosOperationType.TRANSACTION,
destination:"[own adress]",
destination: "[own adress]",
amount: "0",
parameters: {
entrypoint: "finalize_unstake",
value: { prim: "Unit" },
},
};

const TezosIncreasePaidStorageOperation: PartialTezosIncreasePaidStorageOperation = {
kind: TezosOperationType.INCREASE_PAID_STORAGE,
amount: "10",
destination: "[contract address]"
};
const TezosIncreasePaidStorageOperation: PartialTezosIncreasePaidStorageOperation =
{
kind: TezosOperationType.INCREASE_PAID_STORAGE,
amount: "10",
destination: "[contract address]",
};

export const TEZOS_SAMPLES = {
"tezos_send:transaction": tezosTransactionOperation,
Expand Down
50 changes: 32 additions & 18 deletions advanced/dapps/react-dapp-v2/src/contexts/JsonRpcContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ export function JsonRpcContextProvider({
const [kadenaAccount, setKadenaAccount] = useState<KadenaAccount | null>(
null
);
const [contractAddress, setContractAddress] = useState("[Run Origination to get contract address]");
const [contractAddress, setContractAddress] = useState(
"[Run Origination to get contract address]"
);

const { client, session, accounts, balances, solanaPublicKeys } =
useWalletConnectClient();
Expand Down Expand Up @@ -883,7 +885,7 @@ export function JsonRpcContextProvider({
})),
transaction: transaction
.serialize({ verifySignatures: false })
.toString('base64'),
.toString("base64"),
},
},
});
Expand Down Expand Up @@ -1416,9 +1418,7 @@ export function JsonRpcContextProvider({

// -------- TEZOS RPC METHODS --------

const signTransaction = (
method: TEZOS_SAMPLE_KINDS
) => {
const signTransaction = (method: TEZOS_SAMPLE_KINDS) => {
return _createJsonRpcRequestHandler(
async (
chainId: string,
Expand All @@ -1431,36 +1431,41 @@ export function JsonRpcContextProvider({
break;

case TEZOS_SAMPLE_KINDS.SEND_DELEGATION:
operation = TEZOS_SAMPLES[method]
operation = TEZOS_SAMPLES[method];
break;

case TEZOS_SAMPLE_KINDS.SEND_UNDELEGATION:
operation = TEZOS_SAMPLES[method]
operation = TEZOS_SAMPLES[method];
break;

case TEZOS_SAMPLE_KINDS.SEND_ORGINATION:
operation = TEZOS_SAMPLES[method]
operation = TEZOS_SAMPLES[method];
break;

case TEZOS_SAMPLE_KINDS.SEND_CONTRACT_CALL:
operation = {...TEZOS_SAMPLES[method], destination: contractAddress};
operation = {
...TEZOS_SAMPLES[method],
destination: contractAddress,
};
break;

case TEZOS_SAMPLE_KINDS.SEND_STAKE:
operation = {...TEZOS_SAMPLES[method], destination: address};
operation = { ...TEZOS_SAMPLES[method], destination: address };
break;

case TEZOS_SAMPLE_KINDS.SEND_UNSTAKE:
operation = {...TEZOS_SAMPLES[method], destination: address};
operation = { ...TEZOS_SAMPLES[method], destination: address };
break;

case TEZOS_SAMPLE_KINDS.SEND_FINALIZE:
operation = {...TEZOS_SAMPLES[method], destination: address};
operation = { ...TEZOS_SAMPLES[method], destination: address };
break;

case TEZOS_SAMPLE_KINDS.SEND_INCREASE_PAID_STORAGE:
operation = {
...TEZOS_SAMPLES[method], destination: contractAddress};
...TEZOS_SAMPLES[method],
destination: contractAddress,
};
break;

default:
Expand All @@ -1481,12 +1486,17 @@ export function JsonRpcContextProvider({

// Get the contract ID if it's an origination
if (method === TEZOS_SAMPLE_KINDS.SEND_ORGINATION) {
const contractAddressList = await apiGetContractAddress(chainId, result.hash);
const contractAddressList = await apiGetContractAddress(
chainId,
result.hash
);
if (contractAddressList.length > 0) {
setContractAddress(contractAddressList[0]);
console.log("TezosRpc stored contract: ", contractAddressList[0]);
} else {
console.error("TezosRpc could not find contract address in origination operation.");
console.error(
"TezosRpc could not find contract address in origination operation."
);
}
}

Expand All @@ -1506,7 +1516,7 @@ export function JsonRpcContextProvider({
chainId: string,
address: string
): Promise<IFormattedRpcResponse> => {
const result = await client!.request<Array<{ address: string}>>({
const result = await client!.request<Array<{ address: string }>>({
chainId,
topic: session!.topic,
request: {
Expand All @@ -1525,13 +1535,17 @@ export function JsonRpcContextProvider({
),
testSignTransaction: signTransaction(TEZOS_SAMPLE_KINDS.SEND_TRANSACTION),
testSignOrigination: signTransaction(TEZOS_SAMPLE_KINDS.SEND_ORGINATION),
testSignContractCall: signTransaction(TEZOS_SAMPLE_KINDS.SEND_CONTRACT_CALL),
testSignContractCall: signTransaction(
TEZOS_SAMPLE_KINDS.SEND_CONTRACT_CALL
),
testSignDelegation: signTransaction(TEZOS_SAMPLE_KINDS.SEND_DELEGATION),
testSignUndelegation: signTransaction(TEZOS_SAMPLE_KINDS.SEND_UNDELEGATION),
testSignStake: signTransaction(TEZOS_SAMPLE_KINDS.SEND_STAKE),
testSignUnstake: signTransaction(TEZOS_SAMPLE_KINDS.SEND_UNSTAKE),
testSignFinalize: signTransaction(TEZOS_SAMPLE_KINDS.SEND_FINALIZE),
testSignIncreasePaidStorage: signTransaction(TEZOS_SAMPLE_KINDS.SEND_INCREASE_PAID_STORAGE),
testSignIncreasePaidStorage: signTransaction(
TEZOS_SAMPLE_KINDS.SEND_INCREASE_PAID_STORAGE
),
testSignMessage: _createJsonRpcRequestHandler(
async (
chainId: string,
Expand Down
4 changes: 1 addition & 3 deletions advanced/dapps/react-dapp-v2/src/helpers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ export async function apiGetAccountBalance(
}

if (namespace === "tezos") {
return apiGetTezosAccountBalance(
address, networkId
);
return apiGetTezosAccountBalance(address, networkId);
}

if (namespace !== "eip155") {
Expand Down
15 changes: 9 additions & 6 deletions advanced/dapps/react-dapp-v2/src/helpers/tezos.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { TezosToolkit } from '@taquito/taquito';
import { TezosToolkit } from "@taquito/taquito";
import { TezosChainData } from "../chains/tezos";

// Singleton class to manage TezosToolkit instances
class TezosInstanceManager {
private static instances: Map<string, TezosToolkit> = new Map();

private constructor() { }
private constructor() {}

public static getTezosInstance(networkId: string): TezosToolkit {
if (!TezosChainData[networkId]) {
Expand All @@ -22,7 +22,6 @@ class TezosInstanceManager {
}
export default TezosInstanceManager;


export async function apiGetTezosAccountBalance(
address: string,
networkId: string
Expand All @@ -33,7 +32,7 @@ export async function apiGetTezosAccountBalance(
console.log(`Got balance: ${balanceInTez} ꜩ`);

return {
balance: (balanceInTez).toString(),
balance: balanceInTez.toString(),
symbol: "XTZ",
name: "XTZ",
};
Expand All @@ -56,9 +55,13 @@ export async function apiGetContractAddress(
.then((data) => {
return data
.map((op: any) => {
const address = op?.status === 'applied' && op?.originatedContract?.kind === "smart_contract" ? op.originatedContract.address : '';
const address =
op?.status === "applied" &&
op?.originatedContract?.kind === "smart_contract"
? op.originatedContract.address
: "";
if (address) {
console.log('Got contract address:', address);
console.log("Got contract address:", address);
}
return address;
})
Expand Down
10 changes: 7 additions & 3 deletions advanced/dapps/react-dapp-v2/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,13 @@ const Home: NextPage = () => {
openRequestModal();
await tezosRpc.testSignFinalize(chainId, address);
};
const onSignIncreasePaidStorage = async (chainId: string, address: string) => {
const onSignIncreasePaidStorage = async (
chainId: string,
address: string
) => {
openRequestModal();
await tezosRpc.testSignIncreasePaidStorage(chainId, address);
}
};
const onSignMessage = async (chainId: string, address: string) => {
openRequestModal();
await tezosRpc.testSignMessage(chainId, address);
Expand Down Expand Up @@ -511,7 +514,8 @@ const Home: NextPage = () => {
{
method: TEZOS_SAMPLE_KINDS.SEND_INCREASE_PAID_STORAGE,
callback: onSignIncreasePaidStorage,
description: TEZOS_SAMPLES[TEZOS_SAMPLE_KINDS.SEND_INCREASE_PAID_STORAGE],
description:
TEZOS_SAMPLES[TEZOS_SAMPLE_KINDS.SEND_INCREASE_PAID_STORAGE],
},
{
method: TEZOS_SAMPLE_KINDS.SIGN,
Expand Down

0 comments on commit 77c9121

Please sign in to comment.