Skip to content

Commit

Permalink
update ts formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Feb 15, 2024
1 parent a037f9e commit 399f0d5
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 97 deletions.
109 changes: 54 additions & 55 deletions lib/flow/account.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fcl from "@onflow/fcl"
import * as t from "@onflow/types"
import { encodeKey } from "@onflow/util-encode-key"
import publicConfig from "../publicConfig"
import { sendTransaction } from "./send"

Check failure on line 4 in lib/flow/account.ts

View workflow job for this annotation

GitHub Actions / Static checks (15.x)

Replace `·sendTransaction·` with `sendTransaction`

Expand All @@ -11,32 +10,32 @@ import FlowToken from ${publicConfig.contractFlowToken}
import FungibleToken from ${publicConfig.contractFungibleToken}
transaction(publicKey: String, flowTokenAmount: UFix64, sigAlgorithm: UInt8, hashAlgorithm: UInt8) {
let tokenAdmin: &FlowToken.Administrator
let tokenReceiver: &{FungibleToken.Receiver}
prepare(signer: auth(BorrowValue) &Account) {
let account = Account(payer: signer)
let signatureAlgorithm = SignatureAlgorithm(sigAlgorithm)
?? panic("Invalid SignatureAlgorithm")
let hashAlgorithm = HashAlgorithm(hashAlgorithm)
?? panic("Invalid HashAlgorithm")
let key = PublicKey(
publicKey: publicKey.decodeHex(),
signatureAlgorithm: signatureAlgorithm
)
account.keys.add(
publicKey: key,
hashAlgorithm: hashAlgorithm,
weight: 1000.0
)
let tokenAdmin: &FlowToken.Administrator
let tokenReceiver: &{FungibleToken.Receiver}
prepare(signer: auth(BorrowValue) &Account) {
let account = Account(payer: signer)
let signatureAlgorithm = SignatureAlgorithm(sigAlgorithm)
?? panic("Invalid SignatureAlgorithm")
let hashAlgorithm = HashAlgorithm(hashAlgorithm)
?? panic("Invalid HashAlgorithm")
let key = PublicKey(
publicKey: publicKey.decodeHex(),
signatureAlgorithm: signatureAlgorithm
)
account.keys.add(
publicKey: key,
hashAlgorithm: hashAlgorithm,
weight: 1000.0
)
self.tokenAdmin = signer.storage.borrow<&FlowToken.Administrator>(from: /storage/flowTokenAdmin)
?? panic("Signer is not the token admin")
?? panic("Signer is not the token admin")
self.tokenReceiver = account.capabilities.borrow<&{FungibleToken.Receiver}>(/public/flowTokenReceiver)
?? panic("Unable to borrow receiver reference")
?? panic("Unable to borrow receiver reference")
}
execute {
Expand All @@ -51,37 +50,37 @@ transaction(publicKey: String, flowTokenAmount: UFix64, sigAlgorithm: UInt8, has
`

export async function createAccount(
publicKey: string,
sigAlgo: number,
hashAlgo: number,
authorization: fcl.Authorization
publicKey: string,

Check failure on line 53 in lib/flow/account.ts

View workflow job for this annotation

GitHub Actions / Static checks (15.x)

Replace `↹` with `··`
sigAlgo: number,

Check failure on line 54 in lib/flow/account.ts

View workflow job for this annotation

GitHub Actions / Static checks (15.x)

Replace `↹` with `··`
hashAlgo: number,

Check failure on line 55 in lib/flow/account.ts

View workflow job for this annotation

GitHub Actions / Static checks (15.x)

Replace `↹` with `··`
authorization: fcl.Authorization

Check failure on line 56 in lib/flow/account.ts

View workflow job for this annotation

GitHub Actions / Static checks (15.x)

Replace `↹` with `··`
) {
const result = await sendTransaction({
transaction: txCreateAccount,
args: [
fcl.arg(publicKey, t.String),
fcl.arg(publicConfig.tokenAmountFlow, t.UFix64),
fcl.arg(sigAlgo.toString(), t.UInt8),
fcl.arg(hashAlgo.toString(), t.UInt8),
],
authorizations: [authorization],
payer: authorization,
proposer: authorization,
})

const accountCreatedEvent = result.events.find(
(event: fcl.Event) => event.type === accountCreatedEventType
)

if (!accountCreatedEvent) {
throw "Transaction did not emit account creation event"
}

const address = accountCreatedEvent.data.address
const transactionId = accountCreatedEvent.transactionId

return {
address,
transactionId,
}
const result = await sendTransaction({

Check failure on line 58 in lib/flow/account.ts

View workflow job for this annotation

GitHub Actions / Static checks (15.x)

Replace `↹` with `··`
transaction: txCreateAccount,

Check failure on line 59 in lib/flow/account.ts

View workflow job for this annotation

GitHub Actions / Static checks (15.x)

Replace `↹↹` with `····`
args: [

Check failure on line 60 in lib/flow/account.ts

View workflow job for this annotation

GitHub Actions / Static checks (15.x)

Replace `↹↹` with `····`
fcl.arg(publicKey, t.String),

Check failure on line 61 in lib/flow/account.ts

View workflow job for this annotation

GitHub Actions / Static checks (15.x)

Replace `↹↹↹` with `······`
fcl.arg(publicConfig.tokenAmountFlow, t.UFix64),

Check failure on line 62 in lib/flow/account.ts

View workflow job for this annotation

GitHub Actions / Static checks (15.x)

Replace `↹↹↹` with `······`
fcl.arg(sigAlgo.toString(), t.UInt8),
fcl.arg(hashAlgo.toString(), t.UInt8),
],
authorizations: [authorization],
payer: authorization,
proposer: authorization,
})

const accountCreatedEvent = result.events.find(
(event: fcl.Event) => event.type === accountCreatedEventType
)

if (!accountCreatedEvent) {
throw "Transaction did not emit account creation event"
}

const address = accountCreatedEvent.data.address
const transactionId = accountCreatedEvent.transactionId

return {
address,
transactionId,
}
}
82 changes: 41 additions & 41 deletions lib/flow/fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import FlowToken from ${publicConfig.contractFlowToken}
import FungibleToken from ${publicConfig.contractFungibleToken}
transaction(address: Address, amount: UFix64) {
let tokenAdmin: &FlowToken.Administrator
let tokenReceiver: &{FungibleToken.Receiver}
let tokenAdmin: &FlowToken.Administrator
let tokenReceiver: &{FungibleToken.Receiver}
prepare(signer: AuthAccount) {
self.tokenAdmin = signer.storage.borrow<&FlowToken.Administrator>(from: /storage/flowTokenAdmin)
?? panic("Signer is not the token admin")
prepare(signer: AuthAccount) {
self.tokenAdmin = signer.storage.borrow<&FlowToken.Administrator>(from: /storage/flowTokenAdmin)
?? panic("Signer is not the token admin")
self.tokenReceiver = getAccount(address).capabilities.borrow<&{FungibleToken.Receiver}>(
/public/flowTokenReceiver
) ?? panic("Could not borrow receiver reference to the recipient's Vault")
self.tokenReceiver = getAccount(address).capabilities.borrow<&{FungibleToken.Receiver}>(
/public/flowTokenReceiver
) ?? panic("Could not borrow receiver reference to the recipient's Vault")
}
execute {
Expand All @@ -37,52 +37,52 @@ import FUSD from ${publicConfig.contractFUSD}
import FungibleToken from ${publicConfig.contractFungibleToken}
transaction(address: Address, amount: UFix64) {
let tokenMinter: auth(FUSD.ProxyOwner) &FUSD.MinterProxy
let tokenReceiver: &{FungibleToken.Receiver}
prepare(minterAccount: AuthAccount) {
self.tokenMinter = minterAccount.storage.borrow<auth(FUSD.ProxyOwner) &FUSD.MinterProxy>(
from: FUSD.MinterProxyStoragePath
) ?? panic("No minter available")
self.tokenReceiver = getAccount(address).capabilities.borrow<&{FungibleToken.Receiver}>(
/public/fusdReceiver
) ?? panic("Unable to borrow receiver reference")
}
execute {
let mintedVault <- self.tokenMinter.mintTokens(amount: amount)
self.tokenReceiver.deposit(from: <-mintedVault)
}
let tokenMinter: auth(FUSD.ProxyOwner) &FUSD.MinterProxy
let tokenReceiver: &{FungibleToken.Receiver}
prepare(minterAccount: AuthAccount) {
self.tokenMinter = minterAccount.storage.borrow<auth(FUSD.ProxyOwner) &FUSD.MinterProxy>(
from: FUSD.MinterProxyStoragePath
) ?? panic("No minter available")
self.tokenReceiver = getAccount(address).capabilities.borrow<&{FungibleToken.Receiver}>(
/public/fusdReceiver
) ?? panic("Unable to borrow receiver reference")
}
execute {
let mintedVault <- self.tokenMinter.mintTokens(amount: amount)
self.tokenReceiver.deposit(from: <-mintedVault)
}
}
`

type TokenType = "FLOW" | "FUSD"
type Token = {
tx: string
amount: string
tx: string
amount: string
}
type Tokens = Record<TokenType, Token>

export const tokens: Tokens = {
FLOW: {tx: txFundAccountFLOW, amount: TOKEN_FUNDING_AMOUNTS[FLOW_TYPE]},
FUSD: {tx: txFundAccountFUSD, amount: TOKEN_FUNDING_AMOUNTS[FUSD_TYPE]},
FLOW: {tx: txFundAccountFLOW, amount: TOKEN_FUNDING_AMOUNTS[FLOW_TYPE]},
FUSD: {tx: txFundAccountFUSD, amount: TOKEN_FUNDING_AMOUNTS[FUSD_TYPE]},
}

export async function fundAccount(
address: string,
token: TokenType,
authorization: fcl.Authorization
address: string,
token: TokenType,
authorization: fcl.Authorization
) {
const {tx, amount} = tokens[token]
const {tx, amount} = tokens[token]

await sendTransaction({
transaction: tx,
args: [fcl.arg(address, t.Address), fcl.arg(amount, t.UFix64)],
authorizations: [authorization],
payer: authorization,
proposer: authorization,
})
await sendTransaction({
transaction: tx,
args: [fcl.arg(address, t.Address), fcl.arg(amount, t.UFix64)],
authorizations: [authorization],
payer: authorization,
proposer: authorization,
})

return amount
return amount
}
2 changes: 1 addition & 1 deletion lib/publicConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Networks, TokenTypes } from "./constants"
import {Networks, TokenTypes} from "./constants"

const network = process.env.NEXT_PUBLIC_NETWORK as Networks | undefined
if (!network) throw "Missing NEXT_PUBLIC_NETWORK"
Expand Down

0 comments on commit 399f0d5

Please sign in to comment.