import ArgentCompiledContract from "!!raw-loader!../contracts/ArgentAccount.txt" ; import { BigNumber , BigNumberish } from "@ethersproject/bignumber" ; import { AddTransactionResponse , Args , Calldata , CompiledContract , Contract , compileCalldata , encode , hash , json , number , stark , } from "starknet" ; import { sendMessage , waitForMessage } from "../shared/messages" ; import { getProvider } from "../shared/networks" ; const ArgentCompiledContractJson = json . parse ( ArgentCompiledContract ) ; export class Wallet { address : string ; networkId : string ; deployTransaction ? : string ; contract : Contract ; constructor ( address , networkId , deployTransaction ? ) { this . address = address ; this . deployTransaction = deployTransaction ; this . networkId = networkId ; this . contract = new Contract ( ArgentCompiledContractJson . abi , address , getProvider ( networkId ) ) ; if ( deployTransaction ) { localStorage . setItem ( `walletTx:${ address }` , deployTransaction ) ; } else if ( localStorage . getItem ( `walletTx:${ address }` ) ) { this . deployTransaction = localStorage . getItem ( `walletTx:${ address }` ) ! ; } } public completeDeployTx ( ) { localStorage . removeItem ( `walletTx:${ this . address }` ) ; this . deployTransaction = undefined ; } public async getCurrentNonce ( ) { const { nonce } = await this . contract . call ( "get_nonce" ) ; return nonce . toString ( ) ; } public static async fromDeploy ( networkId ) { sendMessage ( { type : "NEW_ACCOUNT" , data : networkId } ) ; const result = await Promise . race ( [ waitForMessage ( "NEW_ACCOUNT_RES" ) , waitForMessage ( "NEW_ACCOUNT_REJ" ) , ] ) ; if ( ! result ) { throw new Error ( "Failed to deploy account" ) ; } return new Wallet ( result . address , networkId , result . txHash ) ; } }