-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP * make RPC call to landline for deposits * update landline api interface * deposit button WIP * landline deposit button * fix stored landlineAccount type * mobile & api: landline feature flag, logo, copy fixes * mobile: create hook for landline deposit * generate landline url server-side * more i18n * landline offchain action * small spanish fix * parse dollarStr to zDollarStr * make landlineSessionURL optional
- Loading branch information
1 parent
a1b2be5
commit 0fbcc4c
Showing
28 changed files
with
566 additions
and
134 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { OffchainAction, now, zDollarStr } from "@daimo/common"; | ||
import { daimoChainFromId } from "@daimo/contract"; | ||
import * as Haptics from "expo-haptics"; | ||
import { useCallback } from "react"; | ||
import { stringToBytes } from "viem"; | ||
|
||
import { signAsync } from "./sign"; | ||
import { ActHandle, useActStatus } from "../action/actStatus"; | ||
import { i18n } from "../i18n"; | ||
import { getRpcFunc } from "../logic/trpc"; | ||
import { Account } from "../storage/account"; | ||
|
||
const i18 = i18n.landlineDepositButton; | ||
|
||
interface UseLandlineDepositArgs { | ||
account: Account; | ||
recipient: { landlineAccountUuid: string }; | ||
dollarsStr: string; | ||
memo?: string; | ||
} | ||
|
||
export function useLandlineDeposit({ | ||
account, | ||
recipient, | ||
dollarsStr, | ||
memo, | ||
}: UseLandlineDepositArgs): ActHandle & { exec: () => Promise<void> } { | ||
const [as, setAS] = useActStatus("useLandlineDeposit"); | ||
|
||
const exec = useCallback(async () => { | ||
console.log( | ||
`[LANDLINE] Creating deposit for ${account.name} to ${recipient.landlineAccountUuid} for $${dollarsStr}` | ||
); | ||
setAS("loading", i18.depositStatus.creating()); | ||
|
||
// Make the user sign an offchain action to authenticate the deposit | ||
const action: OffchainAction = { | ||
type: "landlineDeposit", | ||
time: now(), | ||
landlineAccountUuid: recipient.landlineAccountUuid, | ||
amount: zDollarStr.parse(dollarsStr), | ||
memo: memo ?? "", | ||
}; | ||
const actionJSON = JSON.stringify(action); | ||
const messageBytes = stringToBytes(actionJSON); | ||
const signature = await signAsync({ account, messageBytes }); | ||
|
||
try { | ||
const rpcFunc = getRpcFunc(daimoChainFromId(account.homeChainId)); | ||
console.log("[LANDLINE] Making RPC call to depositFromLandline"); | ||
const response = await rpcFunc.depositFromLandline.mutate({ | ||
daimoAddress: account.address, | ||
actionJSON, | ||
signature, | ||
}); | ||
|
||
if (response.status === "success") { | ||
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success); | ||
setAS("success", i18.depositStatus.success()); | ||
} else { | ||
console.error("[LANDLINE] Landline deposit error:", response.error); | ||
setAS("error", i18.depositStatus.failed()); | ||
} | ||
} catch (error) { | ||
console.error("[LANDLINE] Landline deposit error:", error); | ||
setAS("error", i18.depositStatus.failed()); | ||
} | ||
}, [account, recipient, dollarsStr, memo, setAS]); | ||
|
||
return { ...as, exec }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum BankTransferOptions { | ||
Deposit = "Deposit", | ||
Withdraw = "Withdraw", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.