-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #347 from arconnectio/development
ArConnect BETA 1.12.0 (Subscriptions, misc bug fixes)
- Loading branch information
Showing
47 changed files
with
5,163 additions
and
2,826 deletions.
There are no files selected for viewing
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
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,11 @@ | ||
import type { PermissionType } from "~applications/permissions"; | ||
import type { ModuleProperties } from "~api/module"; | ||
|
||
const permissions: PermissionType[] = ["ACCESS_ADDRESS"]; | ||
|
||
const subscriptionModule: ModuleProperties = { | ||
functionName: "subscription", | ||
permissions | ||
}; | ||
|
||
export default subscriptionModule; |
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,68 @@ | ||
import { | ||
isAddress, | ||
isLocalWallet, | ||
isSubscriptionType | ||
} from "~utils/assertions"; | ||
import { getActiveAddress, getActiveKeyfile, getWallets } from "~wallets"; | ||
import type { ModuleFunction } from "~api/background"; | ||
import authenticate from "../connect/auth"; | ||
import { getSubscriptionData } from "~subscriptions"; | ||
import { | ||
RecurringPaymentFrequency, | ||
type SubscriptionData | ||
} from "~subscriptions/subscription"; | ||
|
||
const background: ModuleFunction<void> = async ( | ||
appData, | ||
subscriptionData: SubscriptionData | ||
) => { | ||
// validate input | ||
isAddress(subscriptionData.arweaveAccountAddress); | ||
|
||
isSubscriptionType(subscriptionData); | ||
const address = await getActiveAddress(); | ||
|
||
// if is hardware wallet | ||
const decryptedWallet = await getActiveKeyfile(); | ||
isLocalWallet(decryptedWallet); | ||
|
||
// check if subsciption exists | ||
let subscriptions = await getSubscriptionData(address); | ||
|
||
if ( | ||
subscriptions && | ||
subscriptions.find( | ||
(subscription) => | ||
subscription.arweaveAccountAddress === | ||
subscriptionData.arweaveAccountAddress | ||
) | ||
) { | ||
throw new Error("Account is already subscribed"); | ||
} | ||
|
||
await authenticate({ | ||
type: "subscription", | ||
url: appData.appURL, | ||
arweaveAccountAddress: subscriptionData.arweaveAccountAddress, | ||
applicationName: subscriptionData.applicationName, | ||
subscriptionName: subscriptionData.subscriptionName, | ||
subscriptionManagementUrl: subscriptionData.subscriptionManagementUrl, | ||
subscriptionFeeAmount: subscriptionData.subscriptionFeeAmount, | ||
recurringPaymentFrequency: subscriptionData.recurringPaymentFrequency, | ||
nextPaymentDue: subscriptionData.nextPaymentDue, | ||
subscriptionStartDate: subscriptionData.subscriptionStartDate, | ||
subscriptionEndDate: subscriptionData.subscriptionEndDate, | ||
applicationIcon: subscriptionData?.applicationIcon | ||
}); | ||
|
||
subscriptions = await getSubscriptionData(address); | ||
const subscription = subscriptions.find( | ||
(subscription) => | ||
subscription.arweaveAccountAddress === | ||
subscriptionData.arweaveAccountAddress | ||
); | ||
|
||
return subscription; | ||
}; | ||
|
||
export default background; |
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,39 @@ | ||
import type { SubscriptionData } from "~subscriptions/subscription"; | ||
import type { ModuleFunction } from "~api/module"; | ||
|
||
const foreground: ModuleFunction<SubscriptionData[]> = (data) => { | ||
// Validate required fields | ||
const requiredFields: (keyof SubscriptionData)[] = [ | ||
"arweaveAccountAddress", | ||
"applicationName", | ||
"subscriptionName", | ||
"subscriptionFeeAmount", | ||
"recurringPaymentFrequency", | ||
"subscriptionManagementUrl", | ||
"subscriptionEndDate" | ||
]; | ||
|
||
for (const field of requiredFields) { | ||
if (data[field] === undefined) { | ||
throw new Error(`Missing required field: ${field}`); | ||
} | ||
} | ||
|
||
// optional fields | ||
const allFields = [...requiredFields, "applicationIcon"]; | ||
|
||
Object.keys(data).forEach((key) => { | ||
if (!allFields.includes(key as keyof SubscriptionData)) { | ||
throw new Error(`Unexpected extra field: ${key}`); | ||
} | ||
}); | ||
|
||
return [ | ||
{ | ||
...data, | ||
applicationIcon: data.applicationIcon | ||
} | ||
]; | ||
}; | ||
|
||
export default foreground; |
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
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.