Skip to content

Commit

Permalink
chore: update sdk to 14, improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Oct 19, 2024
1 parent 31f72e3 commit 9c5b0b8
Show file tree
Hide file tree
Showing 8 changed files with 701 additions and 659 deletions.
1,004 changes: 530 additions & 474 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"test": "echo \"All tests passed\""
},
"dependencies": {
"@aeternity/aepp-sdk": "^13.3.3",
"@aeternity/aepp-sdk": "github:aeternity/aepp-sdk-js#33ce3b067575ff4c35b8c3270d13a218e14a6dfa",
"@codemirror/lang-javascript": "^6.2.2",
"@codemirror/theme-one-dark": "^6.1.2",
"ansi_up": "^6.0.2",
"buffer": "^6.0.3",
"codemirror": "^6.0.1",
"phoenix": "^1.7.14",
"phoenix-channels": "^1.0.0",
Expand Down
5 changes: 0 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@
<script setup lang="ts">
import Editor from "./components/Editor.vue";
import { useSdkStore } from "./stores/sdkStore";
import { onMounted } from "vue";
import { useContractStore } from "./stores/contractStore";
import Version from "./components/Version.vue";
const sdkStore = useSdkStore();
const { initSdk } = sdkStore;
const contractStore = useContractStore();
const { initContractState } = contractStore;
onMounted(async () => {
await initSdk();
await initContractState();
});
</script>
21 changes: 11 additions & 10 deletions src/components/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<button
v-if="isLocalAccount"
class="mt-2 mr-2 rounded-full bg-black hover:bg-purple-500 text-white p-2 px-4"
@click="initSdk(false)"
@click="connectWallet"
>
Connect Wallet Extension
</button>
Expand All @@ -18,7 +18,7 @@
</h6>
</div>

<div v-if="!secretKey || !address || !nodeUrl || modifySettings">
<div v-if="modifySettings">
<div class="flex mt-8 mb-8">
<div class="w-full p-4 bg-gray-200 rounded-sm shadow">
<h2 class="py-2">Settings</h2>
Expand Down Expand Up @@ -74,27 +74,28 @@
import { storeToRefs } from "pinia";
import { Status, useSdkStore } from "../stores/sdkStore";
import { ref, watch } from "vue";
import { Encoding, isAddressValid } from "@aeternity/aepp-sdk";
const sdkStore = useSdkStore();
const { isLocalAccount, address, nodeUrl, secretKey, status } =
storeToRefs(sdkStore);
const { initSdk } = sdkStore;
const { connectWallet, setAccountAndNode } = sdkStore;
const modifySettings = ref(false);
const nodeUrlInput = ref("");
const secretKeyInput = ref("");
watch(nodeUrl, () => {
watch(modifySettings, () => {
nodeUrlInput.value = nodeUrl.value;
});
watch(secretKey, () => {
secretKeyInput.value = secretKey.value || "";
secretKeyInput.value = secretKey.value;
});
async function useLocalAccount() {
secretKey.value = undefined;
await initSdk(true, nodeUrlInput.value, secretKeyInput.value);
if (!isAddressValid(secretKeyInput.value, Encoding.AccountSecretKey)) {
alert("Invalid secret key, it should be encoded as sk_");
return;
}
await setAccountAndNode(secretKeyInput.value, nodeUrlInput.value);
modifySettings.value = false;
}
</script>
11 changes: 10 additions & 1 deletion src/components/CodeAci.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
/>
<button
class="mt-2 mr-2 rounded-r-full bg-black hover:bg-purple-500 text-white p-2 px-4"
@click="initializeContractFromAci(contractAddress)"
@click="initializeContractFromAciWithCheck"
>
at Address
</button>
Expand All @@ -78,6 +78,7 @@ import { javascript } from "@codemirror/lang-javascript";
import { storeToRefs } from "pinia";
import { useContractStore } from "../stores/contractStore";
import { ref, watch } from "vue";
import { Encoding, isAddressValid } from "@aeternity/aepp-sdk";
const extensions = [javascript(), oneDark];
Expand All @@ -90,6 +91,14 @@ const {
resetContractState,
} = contractStore;
async function initializeContractFromAciWithCheck() {
if (!isAddressValid(contractAddress.value, Encoding.ContractAddress)) {
alert("Invalid contract address, it should be encoded as ct_");
return;
}
await initializeContractFromAci(contractAddress.value);
}
const contractAddress = ref("");
// want those watch here to only react to changes from store but still have local models
Expand Down
54 changes: 28 additions & 26 deletions src/stores/contractStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const useContractStore = defineStore("contract", () => {
compileResult.value.setInfo("Compiling contract source");
resetDeployAndCallData();

await sdkStore.aeSdk?.compilerApi
await sdkStore.aeSdk.compilerApi
.compileBySourceCode(compileData.value.contractCode)
.then((result) => {
compileResult.value.setFinal("Compiled from source", {
Expand All @@ -102,43 +102,45 @@ export const useContractStore = defineStore("contract", () => {
});
}

async function initializeContractFromAci(contractAddress: string) {
async function initializeContractFromAci(
contractAddress: Encoded.ContractAddress,
) {
resetDeployAndCallData(false);
deployResult.value.setInfo("Instantiating Contract at address ...");

await sdkStore.aeSdk
?.initializeContract({
try {
contractInstance = await Contract.initialize({
...sdkStore.aeSdk.getContext(),
aci: JSON.parse(deployData.value.aci),
address: contractAddress as Encoded.ContractAddress,
})
.then((instance) => {
contractInstance = instance;
compileResult.value.setFinal(`Initialized from ACI`, {
aci: deployData.value.aci,
byteCode:
deployData.value.bytecode ||
"calling at address doesn't need bytecode",
});

deployResult.value.setFinal(
`Instantiated Contract at address: ${contractAddress}`,
contractAddress,
);
address: contractAddress,
});

persist();
})
.catch((error) => {
if (error instanceof Error) deployResult.value.setError(error.message);
return undefined;
compileResult.value.setFinal(`Initialized from ACI`, {
aci: deployData.value.aci,
byteCode:
deployData.value.bytecode ||
"calling at address doesn't need bytecode",
});

deployResult.value.setFinal(
`Instantiated Contract at address: ${contractAddress}`,
contractAddress,
);

persist();
} catch (error) {
if (error instanceof Error) deployResult.value.setError(error.message);
return undefined;
}
}

async function deployContract() {
resetDeployAndCallData(false);
deployResult.value.setInfo("Deploying Contract ...");
const args = argsStringToArgs(deployData.value.args);

contractInstance = await sdkStore.aeSdk?.initializeContract({
contractInstance = await Contract.initialize({
...sdkStore.aeSdk.getContext(),
bytecode: deployData.value.bytecode as Encoded.ContractBytearray,
aci: JSON.parse(compileResult.value.data?.aci || deployData.value.aci),
});
Expand All @@ -148,7 +150,7 @@ export const useContractStore = defineStore("contract", () => {
);

contractInstance
?.$deploy(args, options)
.$deploy(args, options)
.then((deployed) => {
deployResult.value.setFinal(
`Deployed, and mined at this address: ${deployed.result?.contractId}`,
Expand Down
Loading

0 comments on commit 9c5b0b8

Please sign in to comment.