lodash-es#get TypeScript Examples

The following examples show how to use lodash-es#get. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DnD.ts    From LogicFlow with Apache License 2.0 6 votes vote down vote up
clientToLocalPoint({ x, y }) {
    const gridSize = get(this.lf.options, ['grid', 'size']);
    // 处理 container 的 offset 等
    const position = this.lf.graphModel.getPointByClient({ x, y });
    // 处理缩放和偏移
    const { x: x1, y: y1 } = position.canvasOverlayPosition;
    // x, y 对齐到网格的 size
    return { x: snapToGrid(x1, gridSize), y: snapToGrid(y1, gridSize) };
  }
Example #2
Source File: actions.ts    From github-deploy-center with MIT License 6 votes vote down vote up
setState = <T>(
  { state }: Context,
  { selector, value }: { selector: (state: AppState) => T; value: T }
) => {
  const path = selector.toString().replace(/^.*?\./, '')
  if (get(state, path) === undefined) {
    throw Error('Unkown path ' + path)
  }
  set(state, path, value)
}
Example #3
Source File: migrate.ts    From raydium-ui with GNU General Public License v3.0 5 votes vote down vote up
// interface Farms {
//   farmInfo: FarmInfo | undefined | null
//   lpAccount: string | undefined | null
//   rewardAccount: string | undefined | null
//   infoAccount: string | undefined | null
//   amount: TokenAmount
// }

export async function mergeTokens(
  connection: Connection | undefined | null,
  wallet: any | undefined | null,
  auxiliaryTokenAccounts: Array<{ pubkey: PublicKey; account: AccountInfo<ParsedAccountData> }>,
  tokenAccounts: any
) {
  if (!connection || !wallet) throw new Error('Miss connection')
  if (!auxiliaryTokenAccounts || auxiliaryTokenAccounts.length === 0)
    throw new Error('Miss auxiliary accounts infomations')

  const owner = wallet.publicKey

  const { blockhash } = await connection.getRecentBlockhash()
  const transaction = new Transaction({ recentBlockhash: blockhash, feePayer: owner })
  const signers: any = []

  const atas: string[] = []

  for (let index = 0; index < auxiliaryTokenAccounts.length; index++) {
    if (index > 0) {
      try {
        const data = transaction.compileMessage().serialize()
        // 1280 - 40 - 8 - 64 - 1 - 256
        if (data.length > 911) {
          break
        }
      } catch {
        break
      }
    }

    const auxiliaryTokenAccount = auxiliaryTokenAccounts[index]

    const { pubkey: from, account: accountInfo } = auxiliaryTokenAccount
    const { info } = accountInfo.data.parsed
    const { mint, tokenAmount } = info

    const mintPubkey = new PublicKey(mint)

    const ata = await findAssociatedTokenAddress(owner, mintPubkey)
    const ataAccountInfo = get(tokenAccounts, mint)

    if (!ataAccountInfo && !atas.includes(ata.toBase58())) {
      transaction.add(
        Token.createAssociatedTokenAccountInstruction(
          ASSOCIATED_TOKEN_PROGRAM_ID,
          TOKEN_PROGRAM_ID,
          mintPubkey,
          ata,
          owner,
          owner
        )
      )
      atas.push(ata.toBase58())
    }

    const { amount } = tokenAmount
    transaction.add(Token.createTransferInstruction(TOKEN_PROGRAM_ID, from, ata, owner, [], new U64(amount)))
  }

  return await sendTransaction(connection, wallet, transaction, signers)
}