Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
at main 37 lines 1.1 kB view raw
1import type { 2 AccountFollowRuleFragment, 3 AccountFollowRules, 4 GroupRuleFragment, 5 GroupRules 6} from "@hey/indexer"; 7import type { Address } from "viem"; 8import getAnyKeyValue from "./getAnyKeyValue"; 9 10interface AssetDetails { 11 assetAddress: Address | null; 12 assetSymbol: string | null; 13 amount: number | null; 14} 15 16const extractPaymentDetails = ( 17 rules: GroupRuleFragment[] | AccountFollowRuleFragment[] 18): AssetDetails => { 19 for (const rule of rules) { 20 if (rule.type === "SIMPLE_PAYMENT") { 21 return { 22 amount: 23 Number(getAnyKeyValue(rule.config, "amount")?.bigDecimal) || null, 24 assetAddress: 25 getAnyKeyValue(rule.config, "assetContract")?.address || null, 26 assetSymbol: getAnyKeyValue(rule.config, "assetSymbol")?.string || null 27 }; 28 } 29 } 30 31 return { amount: null, assetAddress: null, assetSymbol: null }; 32}; 33 34export const getSimplePaymentDetails = ( 35 rules: GroupRules | AccountFollowRules 36): AssetDetails => 37 extractPaymentDetails(rules.required) || extractPaymentDetails(rules.anyOf);