From 5cb0deadcce212ef3bbdf963e23ef757e2ef7105 Mon Sep 17 00:00:00 2001 From: Lim Jet <57783762+daoauth@users.noreply.github.com> Date: Mon, 22 Jul 2024 23:57:43 +0900 Subject: [PATCH] update --- src/component/chains/Sui.tsx | 17 ++++++++-------- src/component/utils/parseMoveToml.ts | 30 ++++++++++++++++++---------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/component/chains/Sui.tsx b/src/component/chains/Sui.tsx index ead680b..7a51fa1 100644 --- a/src/component/chains/Sui.tsx +++ b/src/component/chains/Sui.tsx @@ -16,6 +16,8 @@ import { STATE } from '../../recoil'; import { Provenance } from '../Provenance'; import { parseMoveToml } from '../utils/parseMoveToml'; +import type { ITomlUpgrade } from '../utils/parseMoveToml'; + export const Sui = () => { const { networks, selectNetwork } = useSuiClientContext(); const { mutateAsync: signTransaction } = useSignTransaction(); @@ -36,18 +38,15 @@ export const Sui = () => { dependencies: string[]; digest: number[]; }; - const { - package: { authors }, // TEMP - } = parseMoveToml(state.files['Move.toml']); const transaction = new Transaction(); transaction.setSender(account.address); - if (authors && authors[0] && authors[1]) { - // TEMP: transaction.upgrade - const packageId = authors[0]; - const upgradeCap = authors[1]; - const cap = transaction.object(upgradeCap); + if (state.files['Upgrade.toml']) { + const { + upgrade: { package_id, upgrade_cap }, + } = parseMoveToml(state.files['Upgrade.toml']); + const cap = transaction.object(upgrade_cap); const ticket = transaction.moveCall({ target: '0x2::package::authorize_upgrade', arguments: [ @@ -59,7 +58,7 @@ export const Sui = () => { const receipt = transaction.upgrade({ modules, dependencies, - package: packageId, + package: package_id, ticket, }); transaction.moveCall({ diff --git a/src/component/utils/parseMoveToml.ts b/src/component/utils/parseMoveToml.ts index 4049076..c1715a9 100644 --- a/src/component/utils/parseMoveToml.ts +++ b/src/component/utils/parseMoveToml.ts @@ -6,22 +6,30 @@ export interface IMoveDependency { rev: string; } -export const parseMoveToml = (toml: string | Uint8Array) => { +export interface ITomlMove { + package: { + edition: string; + name: string; + version: string; + }; + addresses: { [key: string]: string }; + dependencies: { [key: string]: IMoveDependency }; +} + +export interface ITomlUpgrade { + upgrade: { + package_id: string; + upgrade_cap: string; + }; +} + +export const parseMoveToml = (toml: string | Uint8Array): T => { try { return parse( new TextDecoder().decode( typeof toml === 'string' ? new TextEncoder().encode(toml) : toml, ), - ) as unknown as { - package: { - edition: string; - name: string; - version: string; - authors: string[]; // TEMP - }; - addresses: { [key: string]: string }; - dependencies: { [key: string]: IMoveDependency }; - }; + ) as T; } catch (error) { throw new Error(`${error}`); }