diff --git a/src/pages/Wallet/Send.tsx b/src/pages/Wallet/Send.tsx index a0086d6..b063d18 100644 --- a/src/pages/Wallet/Send.tsx +++ b/src/pages/Wallet/Send.tsx @@ -17,6 +17,7 @@ import { Input } from "@/components/ui/input" import { Dialog } from "@/components/ui/dialog" import useURLParams from "@/hooks/useURLParams" import useKaspa from "@/hooks/useKaspa" +import { CustomInput } from "@/provider/protocol" export enum Tabs { Creation, @@ -28,12 +29,14 @@ export default function SendDrawer () { const { kaspa, request } = useKaspa() const [ hash, params ] = useURLParams() const [ outputs, setOutputs ] = useState<[ string, string ][]>(JSON.parse(params.get('outputs') ?? `[[ "", "" ]]`)) + const [ fee ] = useState(params.get('fee') ?? "0") + const [ inputs ] = useState(JSON.parse(params.get('outputs') ?? `[]`)) const [ transactions, setTransactions ] = useState() const [ error, setError ] = useState("") const [ tab, setTab ] = useState(Tabs.Creation) const initiateSend = useCallback(() => { - request('account:create', [ outputs, '0' ]).then((transactions) => { + request('account:create', [ outputs, fee, inputs ]).then((transactions) => { setTransactions(transactions) setTab(Tabs.Sign) }).catch((err) => { @@ -89,8 +92,8 @@ export default function SendDrawer () { }) }} onKeyUp={e => { - if (e.key !== 'Enter' || output[0] === "") return; - initiateSend(); + if (e.key !== 'Enter' || output[0] === "") return + initiateSend() }} /> - {tab === Tabs.Sign && { + {tab === Tabs.Sign && { setTransactions(transactions) setTab(Tabs.Submit) }} />} diff --git a/src/pages/Wallet/Send/Sign.tsx b/src/pages/Wallet/Send/Sign.tsx index 9981230..0bfa869 100644 --- a/src/pages/Wallet/Send/Sign.tsx +++ b/src/pages/Wallet/Send/Sign.tsx @@ -11,9 +11,11 @@ import { DialogTitle, } from "@/components/ui/dialog" import useKaspa from "@/hooks/useKaspa" +import { CustomInput } from "@/provider/protocol" -export default function Sign ({ transactions, onSigned }: { +export default function Sign ({ transactions, inputs, onSigned }: { transactions: string[], + inputs: CustomInput[], onSigned: (transactions: string[]) => void }) { const kaspa = useKaspa() @@ -48,7 +50,7 @@ export default function Sign ({ transactions, onSigned }: { const sign = useCallback(() => { setPassword("") - kaspa.request('account:sign', [ transactions, password ]).then((transactions) => { + kaspa.request('account:sign', [ transactions, password, inputs ]).then((transactions) => { onSigned(transactions) }).catch((err) => { setError(err) diff --git a/src/provider/protocol.ts b/src/provider/protocol.ts index 2b8543e..2b39cd9 100644 --- a/src/provider/protocol.ts +++ b/src/provider/protocol.ts @@ -8,8 +8,16 @@ export interface AccountInfo { addresses: [ string[], string[] ] } +export interface CustomInput { + address: string + outpoint: string + index: number, + signer: string + script?: string +} + export interface RequestMappings { - 'transact': [[ string, string ][]] + 'transact': [[ string, string ][], string, CustomInput[]?] // outputs, fee, custom } export interface Request { @@ -27,8 +35,6 @@ export function isRequest (object: any): object is Request { switch (object.method) { case 'transact': { - if (!Array.isArray(object.params)) return false - for (const output of object.params[0]) { if (typeof output[0] !== 'string' || typeof output[1] !== 'string') return false // TODO: Better checks } diff --git a/src/wallet/kaspa/account/transactions.ts b/src/wallet/kaspa/account/transactions.ts index 596f9b4..e448603 100644 --- a/src/wallet/kaspa/account/transactions.ts +++ b/src/wallet/kaspa/account/transactions.ts @@ -9,8 +9,8 @@ export interface CustomInput { } export interface CustomSignature { - outpoint: number - index: string, + outpoint: string, + index: number, signer: string, script?: string } diff --git a/src/wallet/messaging/protocol.ts b/src/wallet/messaging/protocol.ts index cd73657..cfdfd47 100644 --- a/src/wallet/messaging/protocol.ts +++ b/src/wallet/messaging/protocol.ts @@ -17,7 +17,7 @@ export interface RequestMappings { 'account:balance': [] 'account:utxos': [] 'account:create': [[ string, string ][], string, CustomInput[]? ] - 'account:sign': [ string[], string, CustomSignature[] ] + 'account:sign': [ string[], string, CustomSignature[]? ] 'account:submitContextful': [ string[] ] 'account:scan': [] 'provider:connect': [ string ] diff --git a/src/wallet/messaging/wallet/provider/index.ts b/src/wallet/messaging/wallet/provider/index.ts index 5e7d6a6..f374720 100644 --- a/src/wallet/messaging/wallet/provider/index.ts +++ b/src/wallet/messaging/wallet/provider/index.ts @@ -15,6 +15,8 @@ export default class Provider extends EventEmitter { this.windows = new Windows() this.account = account + + this.registerEvents() } get connectedURL () { @@ -82,7 +84,9 @@ export default class Provider extends EventEmitter { let transactions: string[] await this.windows.open('transact', { - 'outputs': JSON.stringify(request.params[0], null, 0) + 'outputs': JSON.stringify(request.params[0], null, 0), + 'fee': request.params[1], + 'inputs': JSON.stringify(request.params[2] ?? [], null, 0) // TODO: consider where to do this }, () => { if (transactions) { this.submitEvent(request.id, 'transactions', transactions) @@ -94,4 +98,14 @@ export default class Provider extends EventEmitter { this.account.transactions.once('transactions', (parsedTransactions) => transactions = parsedTransactions) } } + + private registerEvents () { + // TODO: implement better event processing by a seperate class :p + this.account.on('balance', () => { + this.submitEvent(0, 'account', { + balance: this.account.balance, + addresses: [ this.account.addresses.receiveAddresses, this.account.addresses.changeAddresses ] + }) + }) + } } \ No newline at end of file