Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
huumn committed Nov 3, 2024
2 parents dccfd21 + 193ceef commit 25facad
Show file tree
Hide file tree
Showing 27 changed files with 326 additions and 81 deletions.
4 changes: 3 additions & 1 deletion api/paidAction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ export async function createLightningInvoice (actionType, args, context) {
expiry: INVOICE_EXPIRE_SECS
}, { models })

// the sender (me) decides if the wrapped invoice has a description
// whereas the recipient decides if their invoice has a description
const { invoice: wrappedInvoice, maxFee } = await wrapInvoice(
bolt11, { msats: cost, description }, { lnd })
bolt11, { msats: cost, description }, { me, lnd })

return {
bolt11,
Expand Down
3 changes: 2 additions & 1 deletion components/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ export default function Comment ({
</ActionTooltip>}
</>
}
onEdit={e => { setEdit(!edit) }}
edit={edit}
toggleEdit={e => { setEdit(!edit) }}
editText={edit ? 'cancel' : 'edit'}
/>}

Expand Down
4 changes: 3 additions & 1 deletion components/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { useShowModal } from './modal'
import { QRCodeSVG } from 'qrcode.react'
import { Scanner } from '@yudiel/react-qr-scanner'
import { qrImageSettings } from './qr'
import { useIsClient } from './use-client'

export class SessionRequiredError extends Error {
constructor () {
Expand Down Expand Up @@ -472,6 +473,7 @@ function InputInner ({
const [field, meta, helpers] = noForm ? [{}, {}, {}] : useField(props)
const formik = noForm ? null : useFormikContext()
const storageKeyPrefix = useContext(StorageKeyPrefixContext)
const isClient = useIsClient()

const storageKey = storageKeyPrefix ? storageKeyPrefix + '-' + props.name : undefined

Expand Down Expand Up @@ -555,7 +557,7 @@ function InputInner ({
isInvalid={invalid}
isValid={showValid && meta.initialValue !== meta.value && meta.touched && !meta.error}
/>
{(clear && field.value) &&
{(isClient && clear && field.value && !props.readOnly) &&
<Button
variant={null}
onClick={(e) => {
Expand Down
26 changes: 21 additions & 5 deletions components/item-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import classNames from 'classnames'

export default function ItemInfo ({
item, full, commentsText = 'comments',
commentTextSingular = 'comment', className, embellishUser, extraInfo, onEdit, editText,
commentTextSingular = 'comment', className, embellishUser, extraInfo, edit, toggleEdit, editText,
onQuoteReply, extraBadges, nested, pinnable, showActionDropdown = true, showUser = true,
setDisableRetry, disableRetry
}) {
Expand Down Expand Up @@ -151,8 +151,8 @@ export default function ItemInfo ({
showActionDropdown &&
<>
<EditInfo
item={item} canEdit={canEdit}
setCanEdit={setCanEdit} onEdit={onEdit} editText={editText} editThreshold={editThreshold}
item={item} edit={edit} canEdit={canEdit}
setCanEdit={setCanEdit} toggleEdit={toggleEdit} editText={editText} editThreshold={editThreshold}
/>
<PaymentInfo item={item} disableRetry={disableRetry} setDisableRetry={setDisableRetry} />
<ActionDropdown>
Expand Down Expand Up @@ -311,7 +311,7 @@ function PaymentInfo ({ item, disableRetry, setDisableRetry }) {
)
}

function EditInfo ({ item, canEdit, setCanEdit, onEdit, editText, editThreshold }) {
function EditInfo ({ item, edit, canEdit, setCanEdit, toggleEdit, editText, editThreshold }) {
const router = useRouter()

if (canEdit) {
Expand All @@ -320,7 +320,7 @@ function EditInfo ({ item, canEdit, setCanEdit, onEdit, editText, editThreshold
<span> \ </span>
<span
className='text-reset pointer fw-bold'
onClick={() => onEdit ? onEdit() : router.push(`/items/${item.id}/edit`)}
onClick={() => toggleEdit ? toggleEdit() : router.push(`/items/${item.id}/edit`)}
>
<span>{editText || 'edit'} </span>
{(!item.invoice?.actionState || item.invoice?.actionState === 'PAID')
Expand All @@ -334,5 +334,21 @@ function EditInfo ({ item, canEdit, setCanEdit, onEdit, editText, editThreshold
)
}

if (edit && !canEdit) {
// if we're still editing after timer ran out
return (
<>
<span> \ </span>
<span
className='text-reset pointer fw-bold'
onClick={() => toggleEdit ? toggleEdit() : router.push(`/items/${item.id}`)}
>
<span>cancel </span>
<span>00:00</span>
</span>
</>
)
}

return null
}
16 changes: 12 additions & 4 deletions components/wallet-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ export default function WalletCard ({ wallet, draggable, onDragStart, onDragEnte
<Card.Title>{title}</Card.Title>
<Card.Subtitle className='mt-2'>
{badges?.map(
badge =>
<Badge className={styles.badge} key={badge} bg={null}>
{badge}
</Badge>)}
badge => {
let style = ''
switch (badge) {
case 'receive': style = styles.receive; break
case 'send': style = styles.send; break
}
return (
<Badge className={`${styles.badge} ${style}`} key={badge} bg={null}>
{badge}
</Badge>
)
})}
</Card.Subtitle>
</Card.Body>
<Link href={`/settings/wallets/${wallet.def.name}`}>
Expand Down
16 changes: 14 additions & 2 deletions fragments/paidAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ const ITEM_PAID_ACTION_FIELDS = gql`
}
}`

const ITEM_PAID_ACTION_FIELDS_NO_CHILD_COMMENTS = gql`
${COMMENTS}
fragment ItemPaidActionFieldsNoChildComments on ItemPaidAction {
result {
id
deleteScheduledAt
reminderScheduledAt
...CommentFields
}
}
`

const ITEM_ACT_PAID_ACTION_FIELDS = gql`
fragment ItemActPaidActionFields on ItemActPaidAction {
result {
Expand Down Expand Up @@ -226,11 +238,11 @@ export const CREATE_COMMENT = gql`
}`

export const UPDATE_COMMENT = gql`
${ITEM_PAID_ACTION_FIELDS}
${ITEM_PAID_ACTION_FIELDS_NO_CHILD_COMMENTS}
${PAID_ACTION}
mutation upsertComment($id: ID!, $text: String!, $boost: Int, ${HASH_HMAC_INPUT_1}) {
upsertComment(id: $id, text: $text, boost: $boost, ${HASH_HMAC_INPUT_2}) {
...ItemPaidActionFields
...ItemPaidActionFieldsNoChildComments
...PaidActionFields
}
}`
Expand Down
4 changes: 4 additions & 0 deletions fragments/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ export const WALLET_FIELDS = gql`
url
secondaryPassword
}
... on WalletBlink {
apiKeyRecv
currencyRecv
}
}
}
`
Expand Down
26 changes: 26 additions & 0 deletions prisma/migrations/20241016171557_blinkreceive/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- AlterEnum
ALTER TYPE "WalletType" ADD VALUE 'BLINK';

-- CreateTable
CREATE TABLE "WalletBlink" (
"id" SERIAL NOT NULL,
"walletId" INTEGER NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"apiKeyRecv" TEXT NOT NULL,
"currencyRecv" TEXT,

CONSTRAINT "WalletBlink_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "WalletBlink_walletId_key" ON "WalletBlink"("walletId");

-- AddForeignKey
ALTER TABLE "WalletBlink" ADD CONSTRAINT "WalletBlink_walletId_fkey" FOREIGN KEY ("walletId") REFERENCES "Wallet"("id") ON DELETE CASCADE ON UPDATE CASCADE;


-- Update wallet json
CREATE TRIGGER wallet_blink_as_jsonb
AFTER INSERT OR UPDATE ON "WalletBlink"
FOR EACH ROW EXECUTE PROCEDURE wallet_wallet_type_as_jsonb();
1 change: 0 additions & 1 deletion prisma/migrations/20241024175439_vault/migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
-- the enum.


ALTER TYPE "WalletType" ADD VALUE 'BLINK';
ALTER TYPE "WalletType" ADD VALUE 'LNC';
ALTER TYPE "WalletType" ADD VALUE 'WEBLN';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- fix revenue for users who have multiple revenue entries for the same day
WITH revenue_days AS (
SELECT coalesce(sum(msats), 0) as revenue_msats, "userId", created_at
FROM "SubAct"
WHERE type = 'REVENUE'
GROUP BY "userId", created_at
HAVING COUNT(*) > 1
),
revenue_total AS (
SELECT coalesce(sum(revenue_msats), 0) as revenue_msats, "userId"
FROM revenue_days
GROUP BY "userId"
)
UPDATE users SET msats = users.msats + revenue_total.revenue_msats
FROM revenue_total
WHERE users.id = revenue_total."userId";

-- fix stacked msats for users who have territory revenue
-- prior to this, we were not updating stacked msats for territory revenue
WITH territory_revenue AS (
SELECT coalesce(sum(msats), 0) as revenue_msats, "userId"
FROM "SubAct"
WHERE type = 'REVENUE'
GROUP BY "userId"
)
UPDATE users SET "stackedMsats" = users."stackedMsats" + territory_revenue.revenue_msats
FROM territory_revenue
WHERE users.id = territory_revenue."userId";
11 changes: 11 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ model Wallet {
walletLNbits WalletLNbits?
walletNWC WalletNWC?
walletPhoenixd WalletPhoenixd?
walletBlink WalletBlink?
vaultEntries VaultEntry[] @relation("VaultEntries")
withdrawals Withdrawl[]
Expand Down Expand Up @@ -298,6 +299,16 @@ model WalletNWC {
nwcUrlRecv String
}

model WalletBlink {
id Int @id @default(autoincrement())
walletId Int @unique
wallet Wallet @relation(fields: [walletId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
apiKeyRecv String
currencyRecv String?
}

model WalletPhoenixd {
id Int @id @default(autoincrement())
walletId Int @unique
Expand Down
8 changes: 8 additions & 0 deletions styles/wallet.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
margin-right: 0.2rem;
}

.receive {
color: #20c997 !important;
}

.send {
color: var(--bs-primary) !important;
}

.attach {
color: var(--bs-body-color) !important;
text-align: center;
Expand Down
55 changes: 11 additions & 44 deletions wallets/blink/client.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { galoyBlinkUrl } from 'wallets/blink'
import { getScopes, SCOPE_READ, SCOPE_WRITE, getWallet, request } from 'wallets/blink/common'
export * from 'wallets/blink'

export async function testSendPayment ({ apiKey, currency }, { logger }) {
currency = currency ? currency.toUpperCase() : 'BTC'
logger.info('trying to fetch ' + currency + ' wallet')
const scopes = await getScopes(apiKey)
if (!scopes.includes(SCOPE_READ)) {
throw new Error('missing READ scope')
}
if (!scopes.includes(SCOPE_WRITE)) {
throw new Error('missing WRITE scope')
}

currency = currency ? currency.toUpperCase() : 'BTC'
await getWallet(apiKey, currency)

logger.ok(currency + ' wallet found')
}

Expand Down Expand Up @@ -143,45 +152,3 @@ async function getTxInfo (authToken, wallet, invoice) {
error: ''
}
}

async function getWallet (authToken, currency) {
const out = await request(authToken, `
query me {
me {
defaultAccount {
wallets {
id
walletCurrency
}
}
}
}
`, {})
const wallets = out.data.me.defaultAccount.wallets
for (const wallet of wallets) {
if (wallet.walletCurrency === currency) {
return wallet
}
}
throw new Error(`wallet ${currency} not found`)
}

async function request (authToken, query, variables = {}) {
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-KEY': authToken
},
body: JSON.stringify({ query, variables })
}
const res = await fetch(galoyBlinkUrl, options)
if (res.status >= 400 && res.status <= 599) {
if (res.status === 401) {
throw new Error('unauthorized')
} else {
throw new Error('API responded with HTTP ' + res.status)
}
}
return res.json()
}
Loading

0 comments on commit 25facad

Please sign in to comment.